laravellaravel-http-clientshopee

Shopee API access token?


I'm new to Shopee API and just want to know how can I find the access token?

$host = '*****';
$date = new DateTime();
$timestamp = $date->getTimestamp();
$partner_id = ****;
$shop_id = ****;
$secret_key = "**********";
$path = "/api/v2/product/get_item_list"; //without the host
$base_str = $partner_id . $path . $timestamp . $shop_id;            
$sign = hash_hmac('sha256', $base_str,  $secret_key, false);
$sign = bin2hex($sign);

$response = Http::withHeaders([
    //'X-First' => 'foo',
    //'X-Second' => 'bar'
])->get('https://partner.test-stable.shopeemobile.com/api/v2/product/get_item_list', [
    
    'partner_id'=>$partner_id,
    'timestamp'=>$timestamp,
    'access_token'=>$sign,
    'shop_id'=>$shop_id,
    'sign'=>$sign
]);

return $response; 

and the error is:

{"request_id":"821fbdc3e5f41d32884586c7f44be93a","error":"error_auth","message":"Invalid access_token."}

How can I get access_token code, is it in Shopee admin page or need to create a code to get that?


Solution

  • You need to get the access code first from Shopee using their auth_partner API. You can refer on how to get access token from their documentation under v2 Shop Authorization in the OpenAPI 2.0 Overview.

    https://open.shopee.com/documents/v2/OpenAPI%202.0%20Overview?module=87&type=2