Get Bearer Token - example
Getting a quick bearer token is simple, follow this guide to get an embedded chain.io bearer token.
Before we begin, you need an Embedded chain.io client_id and client_secret, your point of contact can help you get this.
There are two embedded chain.io environments, a production environment and a sandbox environment, The production environment connects to an actual TMS (eg: cargowise), the sandbox returns static dummy data, it is a mock of the production environment.
Build URL to get exchange token
https://production.embedded.chain.io/setup?client_id=&scopes=SHIPMENT_READ,READ_SHIPMENT_DOCUMENTS&client_owner_id=user123&redirect_url=http://clent-app.com/tms-setup-complete?customer_id=3933
This URL has the following items in the query strings:
- client_id - the client_id provided to you by chain.io
- scopes - a comma separated list of scopes - scopes are the actions that the tokens we generate are authorised to perform.
- client_owner_id - this should be the name of a customer, business unit etc, used to identify the consumer of the token.
- redirect_url - is the URL that needs to be called after the exchange token is generated, if you don't have an APP running at the redirect URL, you can just use the dummy URL shown in the above example.
- If you are building a sandbox token, replace production with sandbox in the URL. eg: `
https://sandbox.embedded.chain.io/setup?client_id=https://production.embedded.chain.io/setup?client_id=&scopes=SHIPMENT_READ,READ_SHIPMENT_DOCUMENTS&client_owner_id=user123&redirect_url
Copy paste the built URL into the browser
Click connect using system credentials the following screen:
Click on Cargowise (if production env) or FakeServer (if sandbox):
Enter credentials Cargowise / FakeServer on the next screen
For sandbox credentials Use https://sandbox.embedded.chain.io/ for http address, 'user' as username and 'user' as password
Click on Connect.
Get exchange token
Do not worry if the site can't be reached, we're only interested in the exchange token in the URL.
The URL would look something like this:
Extract the exchange token, In this case the exchange token is 2UirUMytQ7_wNso4aUb3e
Get Bearer token:
Use the following CURL to get a bearer token, make sure you use the correct client_id and client_secret (provided to you by chain.io) and the exchange token generated in the previous step. One more item to ensure is, if you're generating a sandbox token, make sure the URL is sandbox.embedded.chain.io
.
curl --request POST \
--url https://production.embedded.chain.io/connection/token/exchange \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '
{
"client_id": "3zKglYpDFC8V/firA9dwcStrD5vqLuPuUrvGl/bCVI",
"client_secret": "5q/8MBNrkSuzBbmXvsRFJSXTxy8yeky79Fb4CzAEX8",
"exchange_token": "hbGciOiJIUzINiIsInR5cCI6IkpXVCJ9"
}
Make cURL request on a terminal
The output would look like this:
eyJhbGcOiJIUzI1NiIsIn5cCI6IkpXVCJ9.eyJjb25uZWN0aW9uX2lkIjoiNTQ5ZjY2NzgtZTFmOS00OTU0LWJjNTctNmEyMjUyYjIwM2YIiwiY2xpZW50X2lkIjoiWUZsWHlNSWhrUlCbjlUS3VWNFcxckVoU2FtYU5SloiLJjbGllnRfb3duZXJfaWQiOiJ1c2VyMTIzIiwic2VydmVyX3R5cGUiOiJjYXJnb3dpUiLCJzY29wZXMiOlsiU0hJUE1FTlRfUkVBRCJdLCJlbnZpcm9ubWVudCI6InByb2R1Y3Rpb24iLJpc3MiOiJodHRwczvZWiZWRkZWQuYhhaW4uaW8vIiwiaWF0IjoxNjc2OTg3NzQ5fQ.w3JmTAuOGDLG4MKCqqLFojvOA5WUA-G2hmZlcfRRs
This is the bearer token with which request to the embedded API can be made.
Updated over 2 years ago