Cannot use script tag apis because of autherization error in public app

moatasem
New Member
1 0 0

I'm building an app to add a new scriptTag but I'm stuck with 401 error from all the scriptTag APIs

Here is my code:

    try {
        console.log('shop',shop)
        console.log('accessToken',token)
        const scriptResponse = await axios.post(`https://${shop}/admin/api/2021-01/script_tags.json`,{
            "script_tag": {
                "event": "onload",
                "src": `https://drive.google.com/uc?export=view&id=1QRvfnHbyPwY3nRvGfF78pkFBMwPxPvea`
              }
        },{
            credentials: 'include',    
            headers : {
                'X-Shopify-Storefront-Access-Token':token,
                'Content-Type': 'application/json',
            }
        })

        console.log(scriptResponse)
    } catch (error) {
        console.log(error.message)
    }

 and here is the output of the console :

shop testforraccon.myshopify.com
accessToken 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
Request failed with status code 401

 
I run this code when an API is hit after a button is clicked in the UI of my app,
shop and token is retrieved from the request header

0 Likes