Parag Jadhav
Parag Jadhav

Reputation: 1899

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

Upvotes: 3

Views: 1386

Answers (1)

Nguyen Duy Phong
Nguyen Duy Phong

Reputation: 124

Upvotes: 1

Related Questions