How can I authenticate a request in my Remix Shopify App development?

How can I authenticate a request in my Remix Shopify App development?

TisaneFR
Shopify Partner
4 0 0

I am currently developping a Shopify App using Remix. 

Using this app, I want to able to run jobs that update product information.
Using the app, the user can create jobs, specifying informations about the products and type of task they want to perform. The jobs are saved in the DB connected to the App. 
Then, every day (for example), I want to run a Serverless function (I was thinking of hosting it on Vercel) that:

- Gets the jobs the DB (not a problem)

- For each job, calls an API route that I created on the Remix app, that will be in charge of running the job (i.e updating store product information). (problem)

 

As of now, the requests fails because of the following code;

`const { admin } = await authenticate.admin(request);

 

It seems that the request cannot be authenticated as admin.

Can you give me details about how I can authenticate the request or, if that's not possible, a different way to accomplish my goal ? 

Many thanks,

Vincent

Replies 3 (3)

BrainStation23
Shopify Partner
406 60 59

hi @TisaneFR,

 

You only need to authenticate as an admin when you want to get some data from Shopify's API (graphql /rest) that generally involves the store, customer or merchants. You can simply comment out that line if you don't need that kind of data access. However, if you do need to access the Shopify API, then you need to start the OAuth process from you're cloud function itself. Youre cloud function will have to start the OAuth process on behalf of a existing store to complete the process. You will need your client id (from you're app partner dashboard), access scopes, and redirect URL to make this request.

 

https://{shop}.myshopify.com/admin/oauth/authorize?client_id={your_client_id}&scope={requested_scopes}&redirect_uri={your_redirect_uri}&state={optional_state_parameter}

 

 

you can start the OAuth process from you're cloud function by hitting this endpoint on that store. Make sure that the redirect URL points to you're cloud function and that it's whitelisted in your partner dashboard account for that app. If the OAuth process is successful, Shopify will give you an access token with that redirect response. You can then make requests to the Shopify API on behalf of that store. Hope this answers you're question. Contact me if you want to discuss more about this topic.


Brain Station 23 PLC (Mail: js.sbu@brainstation-23.com)
- Was your question answered? Mark it as an Accepted Solution
- Did the solution not address your concern? We kindly request that share or mail your store URL with us this will enable us to collaborate more closely.
- Explore our Shopify public apps
TisaneFR
Shopify Partner
4 0 0

Hello,

Thank you so much for your answer. I was able to make a request using the URL template you provided, but I can't find the access token with the response.
How should I proceed ? 

 

Thank you,

Vincent

TisaneFR
Shopify Partner
4 0 0

@BrainStation23 
Can you help me with my previous question ?
Kind regards,
Vincent