Create a Storefront Access Token

Emilio_Moreira
New Member
2 0 1

I am trying to create a Storefront Access Token based on the documentation posted at https://help.shopify.com/en/api/reference/access/storefrontaccesstoken#create.

I have successfully acquired an Access Token via the Admin API, and am then trying to make a POST call to /admin/storefront_access_tokens.json. It seems that this should be straightforward, but I am getting an error that I cannot find any postings or blog posts about.

Error: TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be one of type string or Buffer. Received type object

I realize that I need to change the parameter that is being passed into the function, but I don't know which parameter "chunk" is. All of the research that I did referred back to streaming APIs, but this is not sending voice or video data. According to the documentation, the response should just be a JSON payload.

Note: I do have the store set up as a "Sales Channel"

Does anyone have a simple code example of creating a Storefront Access Token?

    console.log("QT/sat...")
    const shop = req.query.shop;

    if (shop) {
        /*#################### START CALL TO DESIRED FUNCTION #################### */
        const accessToken = "f24c1215650febf0992a49f582930d7a";
        const storefrontTokenRequestUrl = "https://" + shop + "/admin/storefront_access_tokens.json";
        const shopRequestHeaders = {
            'X-Shopify-Access-Token': accessToken,
        };
        console.log("QT/shopify/callback :: shopRequestHeaders <" + JSON.stringify(shopRequestHeaders) + ">");

        const storefrontTokenPayload = {
            "storefront_access_token": {
                title: "Test",
                access_scope: "unauthenticated_read_product_listings"
            }
        };
        console.log("QT/shopify/callback :: storefrontTokenPayload <" + JSON.stringify(storefrontTokenPayload) + ">");

        request.post(storefrontTokenRequestUrl, {
                json: storefrontTokenPayload,
                headers: shopRequestHeaders
            })
            .then((storefrontResponse) => {
                console.log("QT :: storefrontResponse.access_token <" + storefrontResponse.access_token + ">");
                console.log("QT :: storefrontResponse.access_scope <" + storefrontResponse.access_scope + ">");
                console.log("QT :: storefrontResponse.created_at <" + storefrontResponse.created_at + ">");
                console.log("QT :: storefrontResponse.title <" + storefrontResponse.title + ">");
                res.end(storefrontResponse);
            })
            .catch((error) => {
                console.log("QT :: ERROR in Promise!!! " + error);
                //DEL: res.status(error.statusCode).send(error.error_description);
                if (error.statusCode >= 100 && error.statusCode < 600) {
                    res.status(error.statusCode);
                } else {
                    res.status(500);
                }
                res.end("Something BAD happened!!!\n" + error);
            });
        /*#################### END CALL TO DESIRED FUNCTION ####################*/
    } else {
        res.status(400).send('Missing \'shop\' parameter');
    }

 

dylanpierce
Shopify Partner
140 2 48

Have you solved the issue with creating Storefront Access Tokens with the Admin Access Token? I've tried changing my store to a sales channel, but instead it gives me a 406 error.

 

Are there any other steps you did to create an Storefront Access Token?

Founder of Verdict - Anti-Fraud Apps for Shopify
  • Blockade - Easily block countries, IP addresses, VPNs
  • Real ID - Verify your customer's real IDs easily & securely
0 Likes
ZeeshanImran
New Member
2 0 1

did you find any solution?


@dylanpierce wrote:

Have you solved the issue with creating Storefront Access Tokens with the Admin Access Token? I've tried changing my store to a sales channel, but instead it gives me a 406 error.

 

Are there any other steps you did to create an Storefront Access Token?


 

0 Likes
ssagli
New Member
5 0 0

Have you figured it out by any chance? i would appreciate it if you could let me know Thank you.

0 Likes