Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error While Generating Access Token For Shopify App

I have built an app for Shopify Shops and it was working fine until yesterday. Link to the documentation followed to create a Shopify app: https://docs.shopify.com/api/authentication/oauth

But now there seems to be an error while generating an access token. I have been getting the error in response:

{"error":"795: unexpected token at 'code=<my-code>\u0026client_secret=<my-secret>\u0026client_id=<my-client-id>'"}

Here is the gist of code written in Google App Script.

function doPost(e)
{
    try
    {
        var client_id = e.parameter['client_id'];
        var client_secret = e.parameter['client_secret'];
        var code = e.parameter['code'];
        var shopUrl = e.parameter['shopUrl'];

        var headers = {
            "Accept":"application/json", 
            "Content-Type":"application/json"
        };

        var payload = {
            "client_id" : client_id,
            "client_secret" : client_secret,
            "code": code
        };

        var options =
        {
            "method" : "POST",
            "payload" : payload,
            "headers" : headers,
            "muteHttpExceptions":true
        };

        var response = UrlFetchApp.fetch(shopUrl, options);
        var data = response.getContentText().split('"')[3];

        //response variable gives the following response
        // {"error":"795: unexpected token at 'code=<my-code>\u0026client_secret=<my-client-secret>\u0026client_id=<my-client-id>'"}

        return ContentService.createTextOutput(data).setMimeType(ContentService.MimeType.TEXT);
    }//try
    catch(e)
    {
        //log the exception
    }//catch
}//doPost

Did anybody encounter the same error? Please help

like image 268
Parag Jadhav Avatar asked Aug 25 '26 18:08

Parag Jadhav


1 Answers

  • Make sure that you requested to right URL, it just likes as "https://[YOUR_SHOP_DOMAIN]/admin/oauth/access_token".
  • Make sure that you gave right ID&secret.
  • Check my PHP-code here for getting Shopify access-token: ShopifyClient.php (scroll to the function "getAccessToken")
like image 70
Nguyen Duy Phong Avatar answered Aug 27 '26 09:08

Nguyen Duy Phong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!