Re: How to access shopify api on a request that came from a theme app extension proxy

How to access shopify api on a request that came from a theme app extension proxy

Harelk1015
Shopify Partner
40 1 6

I have created a theme app extension.

and i created a proxy that handles the requests from the theme app to my server and it works.

im verfying the requests with the package : "shopify-verify-app-proxy-middleware". and it works well.

my problem now is that when I want to send a request to the shopify REST or Graphql, i need to add a session, and i just dont understand where can i get it from the proxy request.

usually i just get it like : "
res.locals.shopify.session"

but i just cant find it on requests that were made from a theme app extension.

Please help 🙂

Replies 5 (5)

Liam
Community Manager
3108 341 881
Hi Harelk1015,
If your server needs to make requests to Shopify's REST or GraphQL APIs, you'll need an access token. For theme app extensions, one common method is to use a stored access token (usually obtained during the app installation OAuth process). You store these tokens securely on your server, indexed by shop domain or some other identifier.
 
In the app proxy request, you should be able to identify the shop domain (usually passed as a query parameter or in the request headers). Use this to look up the corresponding access token from your storage.
 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Harelk1015
Shopify Partner
40 1 6

Sounds great!

I will try to store the access token in my DB,

should i store the whole "res.locals.shopify.session"

or just the accessToken from inside it ?

SajalTimilsina
Shopify Partner
8 1 2

Are you able to figure it out? I am also looking a way to get session from fetch requests in theam extension.

Harelk1015
Shopify Partner
40 1 6

For now i store the res.locals.shopify.session in my db and i just fetch it and use it.

but im not sure if it stays availble unlimited

SajalTimilsina
Shopify Partner
8 1 2

Can we connect brother? I am also working on a similar project. My email: sazzal77@gmail.com


I use the same res. local. Shopify. session token, it works. 

But, have to tried a way to create a token? I use the res. local.Shopify. session from the embedded app.