metafresh logo and link to homepage

Setup Authorization Token for accessing REST API

Setup Access

  1. open user window
  2. go to tab “authorization”
  3. add new record
  4. Role: specify which permissions the token should be able to use
  5. confirm
  6. token is generated and saved

Now you can use that token to access the API.

Example

This example shows how to create a sales order using the token.

Test

sales/order

create a file test.json with your json string:

{ "shipBPartnerCode":"1000106","datePromised": "2018-08-16T00:00:00.000Z","docTypeName": "Angebot","lines": [{"productCode":"A001","qty":111}]}

run the test:

cat test.json | curl -X POST -d @- "http://app:8282/api/sales/order" -H "accept: */*" -H "Authorization: fa51643c4e2849ed8db64c70baf578dc" -H "Content-Type: application/json"   > response.log

sales/order/candidates

Post a new sales order candidate

curl -X POST "http://localhost:8181/api/sales/order/candidates" -H "accept: */*" -H "Authorization: 64390d2e7f8341c685ef1b982a652134" -H "Content-Type: application/json" -d "{ \"org\": { \"code\": \"test-org-03\", \"name\": \"test-org-03-name\" }, \"bpartner\": { \"bpartner\": { \"code\": \"test-create-03\", \"name\": \"test-create-03-name\" }, \"location\": { \"externalId\":\"addr1\", \"countryCode\":\"DE\" }, \"contact\": { \"name\":\"teo\", \"externalId\": \"contact1\" } }, \"dateRequired\": \"2018-10-01\", \"productCode\": \"9002737\", \"qty\": 1, \"price\": 321, \"discount\": 13, \"poReference\": \"external-po-ref\", \"externalId\": \"123456\"}"

the JSON is:

{
  "org": {
    "code": "test-org-03",
    "name": "test-org-03-name"
  },

  "bpartner": {
    "bpartner": {
      "code": "test-create-03",
      "name": "test-create-03-name"
    },
    "location": {
      "externalId":"addr1", "countryCode":"DE"
    },
    "contact": { "name":"teo", "externalId": "contact1" }
  },

  "dateRequired": "2018-10-01",
  "productCode": "9002737",
  "qty": 1,
  "price": 321,
  "discount": 13,
  "poReference": "external-po-ref",
  "externalId": "123456"
}

Post an array of new sales order candidates

curl -X POST "http://localhost:8181/api/sales/order/candidates/bulk" -H "accept: */*" -H "Authorization: 64390d2e7f8341c685ef1b982a652134" -H "Content-Type: application/json" -d "{ \"requests\": [{ \"org\": { \"code\": \"test-org-03\", \"name\": \"test-org-03-name\" }, \"bpartner\": { \"bpartner\": { \"code\": \"test-create-03\", \"name\": \"test-create-03-name\" }, \"location\": { \"externalId\":\"addr1\", \"countryCode\":\"DE\" }, \"contact\": { \"name\":\"teo\", \"externalId\": \"contact1\" } }, \"dateRequired\": \"2018-10-01\", \"productCode\": \"9002737\", \"qty\": 1, \"price\": 321, \"discount\": 13, \"poReference\": \"external-po-ref\", \"externalId\": \"123456\"} ]}"

Basically your JSON will look like

{
  "requests": [
       { order candidate JSON },
       { order candidate JSON },
        ..............................................
  ]
}

Attach a file to an existing order candidate

Attach test.pdf to an existing order candidate identified by ExternalId=123456:

curl -X POST "http://localhost:8181/api/sales/order/candidates/123456/attachments" -H "accept: */*" -H "Authorization: 64390d2e7f8341c685ef1b982a652134" -H "Content-Type: multipart/form-data" -F "file=@test.pdf;type=application/pdf"

source: https://github.com/metasfresh/metasfresh/issues/4549#issuecomment-420188488


Zur Quelldatei auf github.com