christophergregory / shopify-node-api

OAuth2 Module for Shopify API
MIT License
216 stars 74 forks source link

Can't get access token and shop info #109

Open krutipatel-8794 opened 2 years ago

krutipatel-8794 commented 2 years ago

I am trying to get an access token using exchange_temporary_token method but I don't get any error or any successful response. I am implementing this node API in the AWS Lambda function.

var Shopify = new shopifyAPI({
                 shop: 'SHOP_NAME', 
                 shopify_api_key: 'API_KEY', // Your API key
                 shopify_shared_secret: 'API_SHARED_SECRET'// Your Shared Secret
             });

Shopify.exchange_temporary_token(event['queryStringParameters'], function (err, data){
    if (err)
    {
        console.log(err);
    }
    else {
        console.log(data);
    }

    console.log('Access token is..', data['access_token']);
});

I am using the correct shopify_api_key and shopify_shared_secret, but I can't see any error OR any data result OR access_token. I can successfully call Shopify.is_valid_signature method and it is returning 'True' value. Any suggestions for this on how I can get the details?

My 2nd question is: I have also tried to call the below code, and the same issue (No errors, no data, no headers). I am calling this by setting my temporary token in the config

var Shopify = new shopifyAPI({
                 shop: 'SHOP_NAME', 
                 shopify_api_key: 'API_KEY', // Your API key
                 shopify_shared_secret: 'API_SHARED_SECRET', // Your Shared Secret
                                 access_token: event['queryStringParameters'].code
             });

Shopify.get('admin/api/2022-07/shop.json', "", function(err, data, headers){
                console.log(err); 
                console.log(data); // Data contains product json information
                console.log(headers); // Headers returned from request
            });

image

As per the docs the 2nd parameter query_params is optional so I haven't passed any. Could you please suggest how I can get the shop details?

nodeit commented 2 years ago

It's hard to tell without any sort of stack trace or error message. Are you able to reproduce the error locally? Testing in AWS lambda can be tricky.

krutipatel-8794 commented 2 years ago

No, I haven't tested this locally and only tried with Lambda. But I can try testing locally and will let you know.

krutipatel-8794 commented 2 years ago

@nodeit I have tested this locally and I can get an access token but when I try the same code in lambda then it does not return an error or data. I feel like it doesn't execute the method itself. Do you know if anyone had the same issue before and has a resolution?

await Shopify.exchange_temporary_token(queryParams, async function(err, data){
                console.log("err is....", err);
                console.log("data is....", data);
                console.log("access token is....", data['access_token']);
                accessToken = data['access_token'];
});