Token Exchange
To get Customer Access Token, you need to first obtain an authorization code, then use this authorization code to exchange token.
1. Get authorization code
To begin the process, we call GET /oauth/authorize to obtain an authorization code. After the user grants permission, the authorization server redirects to your redirect_uri with an authorization code.
Request Method: GET
Request Host: shop host (e.g. https://{{handle}}.shoplineapp.com)
Request Endpoint: /oauth/authorize
Request Body: N/A
Request Parameter:
| Name | Type | Example |
|---|---|---|
| response_type | String | code |
| client_id | String | <client id from Open API oauth application> |
| redirect_uri | String | <self defined redirect uri> |
| scope | String | shop |
Request URL example:
GET {{shop_host}}/oauth/authorize?response_type=code&client_id={{client_id}}&redirect_uri={{redirect_uri}}&scope=shop
Redirect URI example:
{{redirect_uri}}?code={{authorization_code}}
Save the authorization code of the query string from redirect uri for later step.
Authorization code is one-time use onlyThe authorization code is by specification one-time use only.
You need to generate another new authorization code to exchange for a new access token.
2. Exchange token with authorization code
Once you receive the authorization code, call POST /oauth/token to exchange it for a Customer Access Token.
Request Method: POST
Request Host: shop host (e.g. https://{{handle}}.shoplineapp.com)
Request Endpoint: /oauth/token
Request Body:
| Name | Type | Example |
|---|---|---|
| grant_type | String | authorization_code |
| code | String | <authorization code retrieved from /oauth/authorize> |
| redirect_uri | String | <same redirect_uri as /oauth/authorize> |
| client_id | String | <client id from Open API oauth application> |
| client_secret | String | <client secret from Open API oauth application> |
Request URL example:
POST {{shop_host}}/oauth/token
Example Response:
Status Code | Example Response Body |
|---|---|
200 OK | The request was successful, and the |
400 Bad Request | Invalid or missing parameters, such as |
401 Unauthorized | Invalid client id or client secret |
Updated 2 days ago
