- Daily Developer Hurdles
- Posts
- How to generate access token 🔑
How to generate access token 🔑
Create custom app from the Shopify Admin and create an access token to make admin API call to Shopify REST and GraphQL api. Bonus, Its also possible to generate storefront token from here.
Context:
You have a task that requires to make some API calls to Shopify, and you are not a Public app or you do not have Custom app from the partner dashboard. In another word, you do not want to go through the OAuth process but still want to create an access token.
Problem:
This is a general use case, and it applies to many different use cases like, to get order details, to see the list of registered webhooks…. list goes on…. To summarise we can say that to get any info from the shopify or to make any update to the data which is in Shopify, we need use their APIs, and to make API call we need access token.
Solution:
Create Custom App from the Shopify Admin
Select all the required scopes.
Install the app
save the token
And you are done
Implementation:
Login to the shopify admin and go to following path
Settings > Apps and sales channels
and click on Develop AppsIf you are doing this for the first time, it will ask for “Allow custom app development“, click on it and proceed, you may have next screen asking the same, with links to some pages having guidelines of using this feature. You can again click “Allow custom app development” and proceed.
Now click on “Create an app“.
Give some meaningful name and click “Create app“
Now in this step we have options to select all the scopes that we need. And you will also have some links below to explore how to make an authenticated request and all. We will focus on creating the admin access token, so lets click on “Configure Admin API scopes“
This step will allow you to select all the scopes that you need, If you already know which scope you want, feel free to select it. It depends on your use case, if you need product data, then scopes will be different, if you need customers info, then the scopes will be different, It all depends on you use case. Here we will go with “read_orders“. And you can change this after you have generated the access token, so no worries and click “Save”
Once you have saved it, the “Install app“ button is now enabled, you can click it to install the app. This installation process do not take to to the normal/general app install flow, It just create an access token and take you to the next screen where you can view the token.
Once the app is installed, you will be able to see the screen with your token, the token is not shown by default, you can click on “Reveal token once“ to see the token. This is the only time they show you the token, in case you need it again, you need to find it from a place where you are using it, like Postman, ENV variable of the app, Password manager etc… You will not get it again from this screen. But you can always regenerate it by uninstall and then reinstalling the app.
Now you have your access token and you can use it wherever you need to.
It is important to note that there are many other things to look for and I have not covered them in this article. Such things are like, using Google Pub/Sub to get the webhooks, and authenticate received webhooks, how to make Admin and Storefront API calls, yes, there is a little difference in making both the calls, and many more things….
But these are special use cases, and it is better to have another article for them.