I want to call rest api in the shopify embedded app, how can i get the access token in the react?

I am following this tutorial to build an app: https://shopify.dev/tutorials/build-a-shopify-app-with-node-and-react

I want to query the abandoned checkout, so I think I should use rest api instead of grapql.
However I don’t know how tot get the access token in the react component.
Can somebody tell me how to do this?

You can use shop and accessToken from ctx

router.get("/products", async (ctx) => {
    const { shop, accessToken } = ctx.session;
    const res = await fetch(
      `https://${SHOPIFY_API_KEY}:${accessToken}@${shop}/admin/api/2020-10/products.json?${new URLSearchParams(
        ctx.request.query
      )}`
    );
    ctx.body = await res.json();
    ctx.status = 200;
  });

And make a call in React Component

const product = async (limit, sinceId) => {
    const res = await fetch(
      "/products?" +
        new URLSearchParams({
          limit,
          since_id: sinceId,
        })
    );
    return await res.json();
  };
2 Likes

To piggy back on this thread, If I want to get my customer data (namely email address) to compare against the email used in the registration process and throw a message if already used, I would have to make a private app and call the Customer API from my app instead of the front end of my store?

Any guidance is greatly appreciated!