The API supports two different authentications Basic Auth and Bearer Token
Note: Bearer Token is currently not supported for SSOP
-
Basic Authentication
You need to request the username and password through customer service
curl -X POST "{{URL}}/ShipServer/{{ID}}/{{PATH}}"
-H "Authorization: basic {{TOKEN}}"
-H "Content-Type: application/json"
--data-raw "{
\"data\": {},
\"options\": {}
}"
- {{TOKEN}} - your username + ":" + password encoded with base64
-
Bearer Token
The client_id and client_screct are generated by following these steps
1. Generate the client_id & client_secret
- Login to www.nshiftportal.com with your Owner user
- Click on the Settings icon in the top right corner
- In the menu to the right select Clients under API Configuration and click on the Add button
- Give the new entry a Display Name and a Description
- Make sure that the Enable checkbox is checked
- Set the Allowed Scope to Shipment Server (public_api_shipmentserver)
- Save the client_id and client_secret locally, once you close the dialog the client_secret can't be recovered
For more detailed instructions with images, see Creating a Client ID and Client Secret for Ship API v2
2. Request an access_token using the client_id and client_secret
The Token is valid for 60 minutes before it expires and you have to re-authenticate
curl -X POST "https://account.nshiftportal.com/idp/connect/token"
--header "Content-Type: application/x-www-form-urlencoded"
--data-urlencode "grant_type=client_credentials"
--data-urlencode "client_id={{CLIENT_ID}}"
--data-urlencode "client_secret={{CLIENT_SECRET}}"
- You do not re-authenticate for each request, you should save it and reuse it from a cache
Response
{
"access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjI3QjA1ODk4Nzc1OEUwMkMI1NiIsInR2...",
"expires_in": 3600,
"token_type": "Bearer",
"scope": "public_api_shipmentserver"
}
3. Using the access token in a request
The access_token has to be added to the header on all requests.
curl -X POST "{{URL}}/ShipServer/{{ID}}/{{PATH}}"
-H "Authorization: bearer {{TOKEN}}"
-H "Content-Type: application/json"
--data-raw "{
\"data\": {},
\"options\": {}
}"
- {{TOKEN}} - the access_token received in step 2