快工助手跨境电商知识与商机助手

v2.public.get_access_token

Shopee 官方资料 · Shopee Open Platform 接口参考 · 适合开发者

stable本次发布有变化全部展示

来自 Shopee 官方资料快照 ·

打开官方原文 ↗
  1. 当前资料结构化阅读页
  2. 固定快照已留存,可追溯
  3. 官方原文可核对
查看技术与溯源信息
平台 / profile
Shopee / profile.shopee.api_reference
语言
en-US
发布版本
cn-20260909-2
标签
zhuge/sourceplatform/shopeeaudience/developercategory/api_doctopic/apitopic/developer

资料正文

§1 v2.public.get_access_token

Use the code from the authorization step to call this API to obtain the authorized shop_id, merchant_id, supplier_id, or user_id, and its corresponding access_token and refresh_token.

#

§2 Overview

Overview

FieldValue
ModulePublic
API typePublic
HTTP methodPOST
Path/api/v2/auth/token/get
Production URLhttps://partner.shopeemobile.com/api/v2/auth/token/get
Sandbox URLhttps://partner.test-stable.shopeemobile.com/api/v2/auth/token/get
Rate limit[0, 0, 0]
PermissionERP System; Seller In House System; Product Management; Order Management; Accounting And Finance; Marketing; Customer Service; Brand Membership; Customized APP; Ads Service; Consignment Service System; Custom APP; Swam ERP; Livestream Management; Ads Facil; Affiliate Marketing Solution Management; Shopee Video Management; Brand Portal Service
#

§3 Request parameters

Request parameters

NameTypeRequiredSampleDescription
codestringYes5a5477794a55537954697169514f4653The code in redirect url after the authorization. Valid for one-time use, expires in 10 minutes
partner_idint64Yes1001141Partner ID is assigned upon registration is successful. Required for all requests.
shop_idint64NoShopee's unique identifier for a shop.
main_account_idint64NoThe main_account_id of the seller that authorized the developer.
#

§4 Response parameters

Response parameters

NameTypeRequiredSampleDescription
errorstringError codes for API requests; always returned.When the API call is successful, the error code returned is empty.
messagestringAlways returned. Provides detailed error information.
request_idstringID of API requests; always returned. Used to diagnose problems.
shop_id_listint64[]Returned all shop_ids authorized this time.
merchant_id_listint64[]Returned all merchant_ids authorized this time.
supplier_id_listint64[]Returned all supplier_ids authorized this time.
user_id_listint64[]Returned all user_ids authorized this time.
principal_id_listint64[]If the authorized role is principal administrator, return all principal_id under this authorization.
access_tokenstringReturned when the API call is successful. A dynamic token that can be used multiple times and expires after 4 hours.
refresh_tokenstringReturned when the API call is successful. Use refresh_token to get a new access_token. Valid for each shop_id, merchant_id, supplier_id, or user_id respectively, for 30 days.
expire_intimestampReturned when the API call is successful. The validity period of the access_token, in seconds.
#

§5 Common parameters

Common parameters

NameTypeRequiredSampleDescription
partner_idint1Partner ID is assigned upon registration is successful. Required for all requests.
timestamptimestamp1610000000This is to indicate the timestamp of the request. Required for all requests. Expires in 5 minutes.
signstringe318d3e932719916a9f9ebb57e2011961bd47abfa54a36e040d050d8931596e2Signature generated by partner_id, api path, timestamp and partner_key via HMAC-SHA256 hashing algorithm. More details: https://open.shopee.com/documents?module=87&type=2&id=58&version=2
#

§6 Request samples

Request samples

#

§7 Payload

Payload

{
	"code": "5a5477794a55537954697169514f4653",
	"partner_id": 1001141
}
#

§8 Java

Java

Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://partner.shopeemobile.com/api/v2/auth/token/get?partner_id=partner_id&sign=sign&timestamp=timestamp")
.header("Content-Type","application/json")
.body("{
   \"code\": \"5a5477794a55537954697169514f4653\",
   \"partner_id\": 1001141
}")
.asString();
#

§9 PHP

PHP

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://partner.shopeemobile.com/api/v2/auth/token/get?partner_id=partner_id&sign=sign&timestamp=timestamp',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => '{
    "code": "5a5477794a55537954697169514f4653",
    "partner_id": 1001141
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
#

§10 cURL

cURL

curl --location --request POST 'https://partner.shopeemobile.com/api/v2/auth/token/get?partner_id=partner_id&sign=sign&timestamp=timestamp' \
--header 'Content-Type: application/json' \
--data-raw '{
   "code": "5a5477794a55537954697169514f4653",
   "partner_id": 1001141
}'
#

§11 Python

Python

import requests
import json

url = "https://partner.shopeemobile.com/api/v2/auth/token/get?partner_id=partner_id&sign=sign&timestamp=timestamp"

payload=json.dumps({
  "code": "5a5477794a55537954697169514f4653",
  "partner_id": 1001141
})
headers = {
  'Content-Type': 'application/json'
}
response = requests.RPCRequest("POST",url,headers=headers, data=payload, allow_redirects=False)

print(response.text)
#

§12 Response sample

Response sample

#

§13 JSON

JSON

{
    "error": "",
    "message": ""
    "request_id": "f2a678875e669fdbdb4cbc6a9a18b895",
    "shop_id_list": [368765100, 368765098, 368765097],
    "access_token": "6b5a46716e474d6f6e59777659459849",
    "refresh_token": "4c7259534969484e71734d695a6e0d55",
    "expire_in": 1767001812
}
#

§14 Error example

Error example

#

§15 JSON

JSON

{
    "error": "error_auth",
    "message": "Invalid code",
    "request_id": "264e31f1f14eb20834e485dc319ffa85"
}
#

§16 Errors

Errors

ErrorDescriptionSolution
error_networkInner http call failed
error_dataparse data failed
error_datadata not exist
error_paramparameter invalid
invalid_codeThe code is expired or used or invalid, please check the code.
invalid_main_acount_idThe code or main_accoount_id is wrong, please check the code or the main_account_id.
invalid_shop_idThe code or shop_id is wrong, please check the code or the shop_id.
error_paramThe information you queried is not found.
error_paramWrong parameters, detail: {msg}.
error_serverSomething wrong. Please try later.
error_paramrequest not from gateway
error_servererror server
#

§17 Common errors

Common errors

ErrorDescriptionSolution
error_authpartner_id is invalid
error_authThe App is deleted, and you'll be unable to make any API call.
error_authApp developer’s permissions for authorizations have been restricted. If you’re a seller, contact the developer for more information. If you’re the developer, refer to the Open Platform Console for details.
error_paramThere is no partner_id in query.
error_paramInvalid partner_id.
error_paramno timestamp
error_paramInvalid timestamp
error_paramThere is no sign in query.
error_signWrong sign.
invalid_partner_idInvalid partner_id, please have a check.
error_authNo permission to current api.
error_api_call_restrictedThe App permission for api call have been restricted. If you’re a seller, contact the developer for more information. If you’re the developer, refer to the Open Platform Console for details.
api_suspendedThe API is offline. Please call v2 API instead.
error_limitThe total API call number made by your APP has reached the daily API call limit, please try again after 00: 00 (UTC+08:00)
error_rate_limitToo many requests. You have reached the rate limit. Please try again later.
source_ip_undeclaredRequest Source IP ({ip}) is undeclared. Please declare all your IP addresses in the Shopee Open Platform Console > App list > IP Address Whitelist
error_paramPermission denied. This API is currently offline or the request path is incorrect.
error_paramPartner_id is invalid, should be an integer between 0 and 4294967295.
error_paramno timestamp.
error_paramTimestamp is invalid, should be an integer between 0 and 4294967295.
error_paramTimestamp is expired.
error_partner_key_expiredYour API partner key has expired, please reset the Live API Partner Key in Console to get a new valid partner key to call open api.
error_api_permissionThis app type has no permission to this API.
#

§18 Update log

Update log

DateChange
2026-07-13Add principal_id_list as response parameter.
2024-11-08Add supplier_id
2022-09-20add
2021-09-02update
#