Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

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

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

miketsui3a
New Member
4 0 1

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?

Replies 2 (2)

gabanich
Visitor
1 0 2

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();
  };

 

Cory13
Tourist
9 0 2

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!