This article will discuss about how to use Shopify API with step-by-step integration guide and full documentation list. Let’s get started!
Overview of Shopify API
Shopify API provides developers a utility to build and launch Shopify Apps. In doing so, the Shopify API integration eases the life of the merchants and their online business operations. The Shopify Dev API provisions access to the data from the Shopify online data store and then leverage the data as needed.
Also read: How to use Stripe API; a step-by-step integration guide and full documentation list
List of Shopify developer API and functionalities
At the onset of the article, let’s first be acquainted with the list of Shopify developer API and functionalities.
- Web API: It has a group of HTTP methods to use that support the major functions of the Shopify API library. There are almost 100 methods available from which you need to select the perfect one for your app. All the Web API methods are listed here.
- Events API: Through Events API, you can build your apps for responding to the activities undertaken in the Slack platform. You need to subscribe to the event types as illustrated here. You then need to create a Slack app that will provide a response to the events.
- Admin API: This comes under niche Shopify API scopes for simplification and automation of the Slack organization administration
- SCIM API: Another niche Slack API for provisioning and managing users
- Audit Logs API: Specially created for constructing event management tools and other security information
- Status API: Helps in the health check of the Slack App programmatically
- RTM API: not to be used frequently, provides WebSocket access to certain functionalities similar to Event and Web APIs.
Also read: How To Use YouTube API; A Step-By-Step Guide To Integrate And Full Documentation List
How to use Shopify API – step-by-step integration guide
Let us now focus on how to use Shopify API, the Shopify API endpoints, and with some examples of the codes to be used.
- To call a web Shopify Rest API, you need to present certain arguments to the methods.
GET query string parameters
POST parameters as application/x-www-form-urlencoded
Or it can be a mix of both GET and POST parameters. For the write methods, the arguments belong to the attributes in application/json.
- If you want to call methods like dialog.open and chat.postMessage, then you need to use JSON-encoded bodies.
- Set your HTTP content_type header to application/x-www-form-urlencoded while sending data that is URL-encoded. The key/value pairs for Shopify integration API need to be as per RFC-3986. Here is the sample code
POST /API/conversations.create
Content-type: application/x-www-form-urlencoded
token=xoxp-xxxxxxxxx-xxxx&name=something-urgent
- For JSON-encoded bodies, the HTTP content_type header is set to application/json. In the Authorization header, the Shopify API token needs to be transmitted as a bearer token
Here is the sample code. In this example, we have shown how the Shopify API access token is appended to the Bearer string
POST /API/conversations.create
Content-type: application/json
Authorization: Bearer xoxp-xxxxxxxxx-xxxx
{“name”:”something-urgent”}
- Here is another example code on how to post a message using chat.PostMessage
POST /api/chat.postMessage
Content-type: application/json
Authorization: Bearer xoxp-xxxxxxxxx-xxxx
{“channel”:”C123ABC456″,”text”:”I hope the tour went well, Mr. Wonka.”,”attachments”:[{“text”:”Who wins the lifetime supply of chocolate?”,”fallback”:”You could be telling the computer exactly what it can do with a lifetime supply of chocolate.”,”color”:”#3AA3E3″,”attachment_type”:”default”,”callback_id”:”select_simple_1234″,”actions”:[{“name”:”winners_list”,”text”:”Who should win?”,”type”:”select”,”data_source”:”users”}]}]}
- You can also use “curl” to send chat messages and attachments
Sample code:
curl -X POST -H ‘Authorization: Bearer xoxb-1234-56789abcdefghijklmnop’ \
-H ‘Content-type: application/json’ \
–data ‘{“channel”:”C123ABC456″,”text”:”I hope the tour went well, Mr. Wonka.”,”attachments”: [{“text”:”Who wins the lifetime supply of chocolate?”,”fallback”:”You could be telling the computer exactly what it can do with a lifetime supply of chocolate.”,”color”:”#3AA3E3″,”attachment_type”:”default”,”callback_id”:”select_simple_1234″,”actions”:[{“name”:”winners_list”,”text”:”Who should win?”,”type”:”select”,”data_source”:”users”}]}]}’ \
https://slack.com/api/chat.postMessage
- The responses need to be evaluated and these can be done through the following sample codes.
{
“ok”: true,
“stuff”: “This is good”
}
{
“ok”: false,
“error”: “something_bad”
}
{
“ok”: true,
“warning”: “something_problematic”,
“stuff”: “Your requested information”
}
- You need to authenticate your web requests using a token or Shopify API key. Now how to get Shopify API key? You need to register your application with Shopify. For that, you need to log in and go to the admin panel. You need to create an app, configure the required Shopify API access and save the app. Once done get the Shopify API key from the credentials.
- If you are installing your apps in Shopify, then you will receive 20 requests per second on the Admin Rest API Shopify and the Shopify API limit on GraphQL Admin API is 500 points per second. Also, merchants on Shopify Commerce API enjoy unlimited API calls.
- SNI extension must be used for all TLS connections. The cipher suites that need to be supported are:
- ECDHE-RSA-AES128-GCM-SHA256
- ECDHE-RSA-AES256-GCM-SHA384
- ECDHE-RSA-AES128-SHA256
- ECDHE-RSA-AES256-SHA384
Shopify API Authentication
Authentication is a vital part of Shopify API so that transactions can be kept safe and secure. There are two ways by which the apps can be authenticated – OAuth and the HTTP authentication methods.
The other important concept is the two modes by which the users can access the tokens.
- Online access: In this method, the link is to a single user of the app, and the Shopify API token has a lifespan that is the same as that of the web session of the user. Online access mode is used when the single user interacts with the app via the internet or web
- Offline access: This method is used when there are no user interventions and a long-term access is required to the store.
Shopify API Access Scopes
During the authorization process, you need to specify the parts of the app to which you need access, either authenticated or unauthenticated. The access scopes are available through Shopify REST APIs and Admin API in GraphQL.
Shopify API versioning
You need to maintain the Shopify webhook API versioning so that you can change platforms and be open to any upgrades and uplifts to the product.
Shopify API Rate Limits
A Shopify API rate limit needs to be set to maintain the stability of the platform and enable fair usage for all users. The rate limits can be to limit calls, no of times requests can be retried, and caching results.
GraphQL API Rate Limits
This particular limit is set based on the query costs or cost of requests within a particular time. Also, an interesting part is the rate limits can be set on a combination of apps and the store, to prevent any overlap.
Shopify REST API Rate Limits
This particular rate limit is also set on the basis of resources, requests, and throttles. Here also the rate limits can be set on a combination of apps and the store, to prevent any overlap
Storefront API Rate Limits
These limits must be set when you need to ensure the calls are time-based i.e. the time taken for the requests to complete.
Resource-Based Rate Limits
This is the limit that can be set if the store exceeds the threshold of an additional throttle containing 50,000 product variants. Beyond the threshold, you can only create 1000 new variants in a day.
Pagination
If you want to retrieve certain results from a particular connection, then use cursor-based pagination as supported by GraphQL and REST endpoints. In the arguments, you must mention the number of results to retrieve.
Last and not least use the Mobile Buy SDK to enable Shopify API for mobile apps. In general Shopify API communicates with the REST web service through pyactiveresource, which needs to be configured for usage to an authorized website of a store.
Also read: How to use ChatGPT API; a step-by-step integration guide and full documentation list
Shopify API documentation references
You can find most of the Shopify API documentation references here.
If you want to refer to Shopify API docs related to app build, then you must refer to that particular sub-section and check out the various types of API like Admin API, Partner API, Payment Apps API, Messaging API etc.
For Shopify API tutorial related to app extensions, component libraries, and references then also refer to the website and refer the details on each of the extensions and libraries.
For Shopify API reference on how to build a custom theme, there are tutorials and step-by-step guides on the website mentioned above. For any Shopify API versions and Shopify API changes, details are mentioned in the release notes. Even the Shopify API changelog can be checked from this particular sub-section.
For building a custom storefront or building a marketplace, refer to the Shopify Rest API documentation and other reference docs, and tutorials for the necessary details. The guides are helpful with all the steps mentioned to ensure smooth usage of Shopify API and also its installation, configuration, and setup.
Shopify API examples
Let is now focus on some key Shopify API examples which will assist you in creating and designing your application and using it for your needs. We will discuss the different Shopify API collections based on various technology and their subsequent usage, which varies in terms of their coding.
1. How to use Shopify Ajax API
Before using Shopify Ajax API, you must be aware that this API can only be used with seeded Shopify API and not via any custom storefront. It is mainly used when you want to recommend any product to the users, suggest products and brands, provision to add products to the shopping cart and increase the cart counter based on the purchase.
The Ajax API Shopify can only accept GET and POST HTTP requests and the sample code for it is as below: reference website.
var cartContents = fetch(window.Shopify.routes.root + ‘cart.js’)
.then(response => response.json())
.then(data => { return data });
2. How to use Shopify Python API
To start using Shopify Python API, you must first install Shopify, then create the application and the base URL. You also need to create a token to gain access to the shop’s data. After the sessions are activated, you need to make the authorized requests.
The sample code example using Python Shopify API is mentioned below and also can be referred to the website for more details.
python
shop = shopify.Shop.current
# Get a specific product
product = shopify.Product.find(179761209)
# Create a new product
new_product = shopify.Product()
new_product.title = “Burton Custom Freestyle 151”
new_product.product_type = “Snowboard”
new_product.vendor = “Burton”
success = new_product.save() #returns false if the record is invalid
# or
if new_product.errors:
#something went wrong, see new_product.errors.full_messages() for example
# Update a product
product.handle = “burton-snowboard”
product.save()
3. How to use Shopify Node API
For using Shopify Node API, you need to follow the similar steps as above. Install Shopify, create the application, and the basic URL, and then create the Shopify API NPM token/ key for authentication.
A sample code for using Shopify API node as below:
const ShopifyAPI = require(‘shopify-node-api’);
const mapStyles = require(‘./map-styles’);
module.exports = {
stores: {},
mapConfiguration: {},
install (storeOptions) {
let store = this.stores[storeOptions.shop];
if (!store) {
store = new ShopifyAPI(storeOptions);
this.stores[storeOptions.shop] = store;
}
return store;
},
shopNameFormater (shop){
return shop.replace(/https?:///, ”);
},
getStore (shop) {
shop = this.shopNameFormater(shop);
return this.stores[shop];
},
saveMapConfiguration (shop, configurations) {
shop = this.shopNameFormater(shop);
let mapConfigurations = this.mapConfiguration[shop];
if (!mapConfigurations) {
mapConfigurations = {};
this.mapConfiguration[shop] = mapConfigurations
}
mapConfigurations.mapApi = configurations.mapApi;
mapConfigurations.location = configurations.location;
let mapStyle;
if (configurations.mapStyle){
mapStyles[configurations.mapStyle]
} else if(configurations.mapStyleCustom){
mapStyle = JSON.parse(configurations.mapStyleCustom);
}else{
mapStyle =mapStyles[Object.keys(mapStyles)[0]];
}
mapConfigurations.styles = mapStyle;
return mapConfigurations;
}
}
4. How to use Shopify API Laravel PHP
The steps for using Shopify API Laravel PHP along with examples are mentioned below:
- Create a server for hosting the application
- Get the Shopify API Key
- Add it to the env file
SHOPIFY_API_KEY=6e8a2bcdb6e43d8a29c4d6dd60fc8713
SHOPIFY_API_SECRET=********************************************
- Update scopes in the config file
/*
Shopify API Scopes | This option is for the scopes your application needs in the API.
*/
- Update scopes in the config file
‘api_scopes’ => env(‘SHOPIFY_API_SCOPES’, ‘read_products,write_products,read_themes,write_themes,read_orders,read_customers’),
- After executing a few more steps of updating the env file, you have to run PHP Artisan migrate to complete the process.
5. How to use Shopify Ruby API
To use Shopify Ruby API, you need to first complete the basic steps of installation, account creation, and Shopify API token creation.
Next is to set up the Ruby Shopify API context, sample code as below elaborated.
ShopifyAPI::Context.setup(
api_key: “<api-key>”,
api_secret_key: “<api-secret-key>”,
host: “<https://application-host-name.com>”,
scope: “read_orders,read_products,etc”,
session_storage: ShopifyAPI::Auth::FileSessionStorage.new, # See more details below
is_embedded: true, # Set to true if you are building an embedded app
api_version: “2022-01”, # The version of the API you would like to use
is_private: false, # Set to true if you have an existing private app
)
Then you can set up the store, grant authorizations, and register the webhooks.
6. How to use Shopify Js API
Shopify Js API is based on the Storefront Shopify API and is essentially used to create e-commerce for your website. The steps for this Shopify API usage are:
- Initializing the client
- Fetching products and collections
- Creating checkouts, fetching checkouts and the checkout attributes
- Adding, updating, and removing the line items
- Adding and removing a discount
- Updating the shipping address
- Completing the checkout.
Sample code for creating checkout:
// Create an empty checkout
client.checkout.create().then((checkout) => {
// Do something with the checkout
console.log(checkout);
});
Sample code for adding line items:
const checkoutId = ‘gid://shopify/Checkout/e3bd71f7248c806f33725a53e33931ef?key=47092e448529068d1be52e5051603af8’; // ID of an existing checkout
const lineItemsToAdd = [
{
variantId: ‘gid://shopify/ProductVariant/29106064584’,
quantity: 5,
customAttributes: [{key: “MyKey”, value: “MyValue”}]
}
];
// Add an item to the checkout
client.checkout.addLineItems(checkoutId, lineItemsToAdd).then((checkout) => {
// Do something with the updated checkout
console.log(checkout.lineItems); // Array with one additional line item
});
Also read: What to Look for in a Geolocation API
Shopify API pricing
In the Shopify API pricing list, the Storefront API comes for free. There are other APIs too which can be used for free. But to use advanced features like checkout, you need to check out the Shopify API premium plans. The details on the pricing and plans can be received by contacting the sales department as indicated in the website.
Most used Shopify APIs
As we approach the last section of the article, let us discuss the most used Shopify APIs. We will provide a short description of each of the APIs for reference, assisting you to decide on their use.
Shopify storefront API
Shopify Storefront API empowers to strengthen the customer front-ending experiences by creating custom storefronts. It is device-agnostic and is a GraphQL Shopify API.
Shopify Graphql API
Shopify Storefront and Admin APIs are GraphQL API and is majorly focused on retrieving orders. It accelerates the development work supporting authentication, proxies, and webhooks.
Shopify admin API
Shopify Admin API is one of the most powerful of all APIs. It is used to enhance the Shopify experience by adding new features. It enforces rate limits on requests and works both with REST and GraphQL.
Shopify product API
If you want to use a GET request for retrieving information about a product, then use the Shopify Product API. It is an Ajax API using locale-aware URLs providing a consistent user experience.
Shopify order API
The Shopify Order API is used to retrieve orders from a store and display them. The orders can be modified and also the details of the customers, product categories, items, and other entities.
Shopify cart API
Shopify cart API is used for various purposes. It is used to add items to the shopping cart, retrieve the items from the cart and update or modify the items in the cart as per the needs.
Shopify subscription API
The Shopify subscription API helps in introducing innovations, thus delivering a faster and more reliable checkout experience. The subscription experiences can be built directly within the checkout feature.
Shopify checkout API
The Shopify Checkout API is used when Sales Channel SDK is being used for creating an app. It enables customers to purchase the products from the stores where the sales channel has been installed.
Shopify fulfillment API
The Shopify Fulfillment API is used to create and manage the fulfillment of the products ordered by a customer. It provides tracking information about the products and notifies the customers when the products are ready for delivery.
Shopify customer API
The Shopify customer API is used to create an active account of a customer and store the addresses, contact details, and order history. Also, it stores whether the customer has agreed to receive email marketing.
Shopify inventory API
The Shopify inventory API helps to maintain and manage the quantities of inventory for a particular product. Each inventory belongs to a particular product in a particular location.
Shopify billing API
The Shopify billing API should be used to process the charges to the products sold via the merchant invoicing system of Shopify. It helps to reflect the charges directly on the invoice, preventing entry of credit card information.
Shopify gift card API
Shopify Gift Card API helps in using the alternative method of payment in the Shopify store using gift cards.
Shopify Metafields API
The Shopify Metafields API helps to store additional information about a product, or a collection or any other Shopify resources.
Shopify shipping API
The Shopify Shipping API performs the calculation of shipping for a particular product and location before the checkout and adds to the item cost.
Shopify Search API
The Shopify Search API assists in retrieving search results while querying for products, pages, collections or articles.
Shopify discount API
The Shopify Discount API is used to apply discounts to any particular product or product category added to the shopping cart.
Shopify payments API
The Shopify Payments API helps to create a payment by capturing the transaction, amount and the credit card information.
Shopify partner API
The Shopify Partner API grants access to transactions that scale up earnings, events, and marketplace opportunities.
Shopify refund API
Refunds are returns or money send back to the customer. The Shopify Refund API creates refunds and retrieves them too for an order.
Shopify marketplace API
Shopify Marketplace API is used to develop, grow, and maintain e-commerce features on your app or platform for a state-of-the-art marketplace.
Shopify analytics API
The Shopify Analytics API is used to track gross sales, net sales, discounts, total sales as well as page views and insights.
Shopify theme API
The Shopify Theme API is used to maintain the theme of the online store that provides the proper look and feel.
Shopify POS API
The Shopify POS API maintains the Point of Sale of a store where products are sold in person and users can create their shopping cart and modify/add too.
Kuntala is a versatile writer with a focus on diverse areas around work, productivity, collaboration at work, hiring, management, HR, and training. Her background of past experience in technology and consulting helps in molding razor-sharp insights into the research and user-focused content she creates. Professionally she is an IT consultant in a sales role and also a writer of short stories and poems, travel blogger, and fashion influencer.
Leave a Reply