Token Exchange
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 access_token, refresh_token is returned as customer access token and customer refresh token. |
| 400 Bad Request | Invalid or missing parameters, such as grant_type, code, redirect_uri, client_id, or client_secret. |
| 401 Unauthorized | Invalid client id or client secret |
