In Etsy Api V2 we can use __SELF__
as shopID but in Api v3 that gives error (Expected int value for 'shop_id' (got string)).
Endpoint in v2 (successful):
https://openapi.etsy.com/v2/shops/__SELF__/receipts
Endpoint in v3 (error):
https://openapi.etsy.com/v3/application/shops/__SELF__/receipts
So, how can we use __SELF__
method in v3?
If not how can we get id of permission granted shop?
{
"access_token": "12345678.O1zLuwveeKjpIqCQFfmR-PaMMpBmagH6DljRAkK9qt05OtRKiANJOyZlMx3WQ_o2FdComQGuoiAWy3dxyGI4Ke_76PR",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "12345678.JNGIJtvLmwfDMhlYoOJl8aLR1BWottyHC6yhNcET-eC7RogSR5e1GTIXGrgrelWZalvh3YvvyLfKYYqvymd-u37Sjtx"
}
OAuth grant token (access_token
) includes user id (12345678
in the example above), which is the internal user_id of the Etsy.com user who grants the application access.
The V3 Open API requires the combined user id prefix and OAuth token as formatted in this parameter to authenticate requests.
This numeric OAuth user_id is only available from the authorization code grant flow.
So we can get userid from access_token
and then get shops using that userid.
PHP code to get userid and setting curl url:
$user_id=explode(".", $access_token)[0];
$curlUrl = 'https://openapi.etsy.com/v3/application/users/'.$user_id.'/shops';