Before you start you need to obtain the following information
Code Block |
---|
|
CLIENT_ID="my client id"
CLIENT_SECRET="my client secret"
API_USERNAME="my KODE API username"
API_PASSWORD="my KODE API password" |
...
In order to obtain a token, run the following
Code Block |
---|
|
curl -s -H "Content-Type: application/json" https://beta-api.ambita.com:443/authentication/v2/token -d "
{
\"grant_type\": \"password\",
\"client_id\": \"CLIENT_ID\",
\"client_secret\": \"CLIENT_SECRET\",
\"username\": \"API_USERNAME\",
\"password\": \"API_PASSWORD\"
}" |
Example response
Code Block |
---|
|
{
"access_token": "ej577asf-a5k6-42yq-a3a2-fh03hb8cb58c",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "aj274ajd-t1s8-48sk-v5m1-shf64j9bq25a",
"scope": [
"kode.order.write",
"shoppingkode.order.read",
"shoppingkode.product.writeread",
"productcatalogkode.price.read",
...
]
} |
The access_token
is valid for 1 hour and should be reused until it expires. When the token expires, the API will return 401 UNAUTHORIZED
.
To get a new access_token
you can use the refresh token grant_type
Code Block |
---|
|
curl -s -H "Content-Type: application/json" https://beta-api.ambita.com:443/authentication/v2/token -d "
{
\"grant_type\": \"refresh_token\",
\"refresh_token\": \"aj274ajd-t1s8-48sk-v5m1-shf64j9bq25a\"
}" |
...
The token should be a request header and should be added in the Authorization header as shown below
Code Block |
---|
|
curl -s \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ej577asf-a5k6-42yq-a3a2-fh03hb8cb58c" \
..... |
...