This guide will show you how to connect your Shopee store to API2Cart in just a few steps.
Step 1: Create an App
To add a Shopee store, you need to register a developer account at
.
After registration and account approval, go to App Management > App List and create an app with the type ERP System.
In the Test Redirect URL Domain field, enter the redirect URL for the app OAuth authorization.
After successful app creation, you will receive a partner ID and API Partner Key. These are used for testing in the sandbox environment only.
To authorize the app, you need to generate an authorization link. Detailed instructions can be found
here.
Below is an example in PHP:
expand source
<?php
function authShop($partnerId, $partnerKey) {
global $host;
$path = "/api/v2/shop/auth_partner";
$redirectUrl = "your_redirect_url";//Redirect URL of your registered app
$timest = time();
$baseString = sprintf("%s%s%s", $partnerId, $path, $timest);
$sign = hash_hmac('sha256', $baseString, $partnerKey);
$url = sprintf("%s%s?partner_id=%s×tamp=%s&sign=%s&redirect=%s", $host, $path, $partnerId, $timest, $sign, $redirectUrl);
return $url;
}
$host = "<https://partner.test-stable.shopeemobile.com>";//Shopee API host (sandbox: <https://partner.test-stable.shopeemobile.com,>
//production: <https://partner.shopeemobile.com,> CB-KR / CB-JP: <https://openplatform.shopee.cn)>
$partnerId = your_partner_id;//Partner ID of your registered app
$partnerKey = "your_partner_key";//API partner key of your registered app
echo authShop($partnerId, $partnerKey);
When visiting the generated link, an authorization window will open.
After logging in, the user will be asked to authorize the app.
⚠️ Note: App authorization is valid for 365 days. After expiration, the seller must reauthorize the app.
For apps in Developing status, you can authorize a test store in the API Test Tool section.
After authorization confirmation, you will receive a code and shop_id on your redirect URL. These are used to obtain the refresh_token.
Example of obtaining a refresh_token in PHP:
expand source
<?php
function getTokenShopLevel($code, $partnerId, $partnerKey, $shopId) {
global $host;
$path = "/api/v2/auth/token/get";
$timest = time();
$body = array("code" => $code, "shop_id" => $shopId, "partner_id" => $partnerId);
$baseString = sprintf("%s%s%s", $partnerId, $path, $timest);
$sign = hash_hmac('sha256', $baseString, $partnerKey);
$url = sprintf("%s%s?partner_id=%s×tamp=%s&sign=%s", $host, $path, $partnerId, $timest, $sign);
$c = curl_init($url);
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, json_encode($body));
curl_setopt($c, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$resp = curl_exec($c);
echo "raw result: $resp";
$ret = json_decode($resp, true);
$accessToken = $ret["access_token"];
$newRefreshToken = $ret["refresh_token"];
echo "\\naccess_token: $accessToken, refresh_token: $newRefreshToken raw: $ret"."\\n";
return $ret;
}
$host = "<https://partner.test-stable.shopeemobile.com>";//Shopee API host depending on region and environment
$partnerId = your_partner_id;//Partner ID of your registered app
$partnerKey = "your_partner_key";//API partner key of your registered app
$code = "code";//Code received after app authorization
$shopId = shop_id;//Shop ID received after app authorization
getTokenShopLevel($code, $partnerId, $partnerKey, $shopId);
Step 2: Connect via API2Cart
After obtaining the refresh_token, the Shopee store can be added to API2Cart.
Required parameters:
- shopee_partner_id – Partner ID of your registered app
- shopee_partner_key – API partner key of your registered app
- shopee_shop_id – Shopee store's shop id
- shopee_refresh_token – Refresh token received after app authorization
- shopee_region (optional) – Region of the store (possible values: BR, CN)
- shopee_environment (optional) – Environment (possible values: sandbox, production)