How to get Shopify Access Token from Post-Purchase Extension?

How to get Shopify Access Token from Post-Purchase Extension?

washingmachine
Shopify Partner
4 0 2

Hi, sorry if this may seem like a stupid question but I can't find any tutorials specifically for the post-purchase extensions. I have created a post-purchase UI extension following this tutorial: https://shopify.dev/docs/apps/checkout/product-offers/post-purchase/getting-started .

Now I want to query the Admin API via HTTP request for which I need the access token, e.g. 

 

let response = await fetch(`https://${shopName}.myshopify.com/admin/api/${apiVersion}/graphql.json`, {
    method: "POST",
    headers: {
      "Content-Type": "application/graphql",
      "X-Shopify-Access-Token": <ACCESS-TOKEN>,
    },
    body: <query>
}

 

 

1) How do I get the token? I have tried hardcoding the token which I got after running npm run prisma studio but this is not a permanent solution because the token is different for every merchant.

2) What are the best practices for querying the Admin API? Does it matter whether I query the API from my-extension/src/index.js or from app/routes/api.sign-changeset.jsx? I would be grateful for any pointers or tutorials for that.

Replies 0 (0)