Shopify provides an API that can be used to implement:
This article explains how to use Insomnia Core to query or update the data stored in Shopify using the GraphQL. Insomnia can help you to generate code for languages such as C#, Javascript, C, Swift ...
Insomnia Core a powerful API client developed by the company Kong
The Shopify test API is available at this EndPoint:
1https://shopify.dev/tools/graphiql-admin-api
This endpoint can be used to experiment and play with Shopify GraphQL API.
Below a GraphQL query that returns the first 10 products:
1{2 products(first: 2) {3 pageInfo {4 hasNextPage5 hasPreviousPage6 }7 edges {8 cursor9 node {10 handle11 descriptionHtml12 }13 }14 }15}
Result:
1{2 "data": {3 "products": {4 "pageInfo": {5 "hasNextPage": true,6 "hasPreviousPage": false7 },8 "edges": [9 {10 "cursor": "eyJsYXN0X2lkIjoxOTc0MjA4Mjk5MDMwLCJsYXN0X3ZhbHVlIjoiMTk3NDIwODI5OTAzMCJ9",11 "node": {12 "handle": "rough-snowflake-camisole",13 "descriptionHtml": ""14 }15 },16 {17 "cursor": "eyJsYXN0X2lkIjoxOTc0MjA4MzMxNzk4LCJsYXN0X3ZhbHVlIjoiMTk3NDIwODMzMTc5OCJ9",18 "node": {19 "handle": "wandering-thunder-blouse",20 "descriptionHtml": ""21 }22 }23 ]24 }25 },26 "extensions": {27 "cost": {28 "requestedQueryCost": 4,29 "actualQueryCost": 4,30 "throttleStatus": {31 "maximumAvailable": 1000,32 "currentlyAvailable": 996,33 "restoreRate": 5034 }35 }36 }37}
The GraphQL API in Shopify for production is available at this endpoint:
1https://**{{ SHOPIFY_SHOP }}**.myshopify.com/admin/api/2020-07/graphql.json
{{ SHOPIFY_SHOP }} represents the name of the Shopify instance. This endpoint is secure by default.
In order to query Shopify from an application such as a Web Application or a mobile application we need to create a Private Application.
A link "Managed private apps" is available in the "Apps" section of Shopify.
A private application is characterized by:
The name of the developer
A list of permissions
The Read / Write access policy on each entity defined in the Shopify Back-office
The API is divided into 2 parts:
Creation of a private application
In Apps click on the button "Create new private app"
Click save and create App on the dialog.
Once we have an application we can use an API client to test and create our graphQL queries.
Insomnia Core is a very powerful Desktop API Client for REST and GraphQL tool to explore and test REST and GraphQL Apis. Insomnia can be downloaded at : https://insomnia.rest/
Click create new "Workspace"
Workspaces are a core concept used for isolating projects within Insomnia.
For example for our example we store the following definitions:
1{2 "SHOPIFY_SHOP": "test",3 "SHOPIFY_ACCESS_TOKEN": "FF",4 "SHOPIFY_API_KEY": "X",5 "SHOPIFY_PASSWORD": "X"6}
In our Workspace choose the action button create "New Request"
Edit the name of the request and chose "POST" method:
Type the URL
SHOPIFY_SHOP represents the variable we have created in the Environment.
Configure the GraphQL Query
1{2 products(first: 3) {3 edges {4 cursor5 node {6 handle7 title8 }9 }10 }11}
Configure the security with Basic authentication
Choose the variable "SHOPIFY_API_KEY" and "SHOPIFY_PASSWORD" for username and password
Create a Header in the query
Configure the query to disable the cookies 🍪
A right-click on the query definition can be used to open the settings of the query
Send cookies and store cookies 🍪 must be disabled 🔥
We can now test our query with a click on the send button ▶️
😎 A cool feature of Insomnia is the code generation of a client
We deliver high quality blog posts written by professionals monthly. And we promise no spam.