Welcome to the October 2021 edition of our API features roundup, designed to help you understand how you can adopt all the latest changes to improve the quality of your apps and streamline your development experience.
This version includes significant improvements to the Storefront API, including an all-new cart API and the ability to fetch specific resources by ID. This version also includes bulk operation webhooks, manual fulfillment holds to facilitate things like pre-orders, and SMS marketing consent endpoints to represent a customer’s willingness to receive SMS marketing communications.
This release also coincides with the removal of version 2020-10, so remember to check your API health report to make sure you're compatible and review the changes coming. For a full list of API changes associated with this version, visit the 2021-10 release notes.
Table of contents
1. Cart API
In the past, managing carts with the Storefront API has had some significant drawbacks. The only way to get real-time product availability, pricing, and discounts was to create or update a checkout. Shopify thoughtfully throttles checkouts to maintain a high-quality experience for buyers, and requests to manage this “pseudocart” would count against your checkout throttle limit.
The 2021-10 version makes it possible to interact directly with carts using the Storefront API. This cart API is a giant leap forward for usability, allowing you to get all of the contextual information about an upcoming order without needing to create a checkout until the customer is ready to pay. Additionally, these carts are no longer tied to the checkout throttle; they instead respect the same throttle as every other storefront request. Flash sales also benefit significantly from this update: the checkout queue is now available for carts created through the Storefront API.
Here is an example of a mutation to create a cart through the Storefront API:
Variables:
The API will then respond with a cart:
Visit our docs to learn more about managing a cart with the Storefront API.
2. Storefront API improvements
New fields have been added to the QueryRoot object to facilitate the fetching of individual resources. For example, you can directly query blogs, collections, pages, and products with an ID or a handle. These fields allow you to quickly and efficiently fetch the resource you need, rather than finding it in a list of every returned resource from the index or using the search endpoint and traversing the edges and nodes for each resource returned in the GraphQL response.
Here’s an example of a GraphQL query to fetch an individual product based on its handle:
Response:
3. Bulk Operation Webhooks
In past versions, you would need to poll the status of a bulk operation to know when Shopify had finished processing it. With the release of 2021-10, we've included webhooks to notify clients if a bulk job has been completed, failed, or cancelled. Webhooks reduce the impact of bulk operations on the API call limit even further and allow you to sit back and wait for the webhook response that includes your bulk operation status. No more polling!
Below is an example of a mutation to create a bulk operation webhook subscription:
Here is an example of a payload that would be sent to the specified URL when a bulk operation finishes:
To learn more about bulk operations, visit our documentation on performing bulk operations with the GraphQL Admin API.
4. Manual Fulfillment Holds
The 2021-10 version adds support for more powerful fulfillment workflows for clients using Fulfillment Orders. Fulfillment Orders now support the "hold" action, allowing apps to place fulfillment holds on items for things like backorders or pre-orders before the item is available for fulfillment.
Below is an example of a mutation to place a hold on a fulfillment order:
Variables:
Response:
These new actions are only available through Fulfillment Orders, not through the legacy fulfillment platform. As always, we highly recommend that any clients who are interacting with fulfillments do so using Fulfillment Orders rather than the legacy order fulfillment endpoints.
5. SMS Consent
API clients can now retrieve, add, and update customers' consent to receive marketing materials via SMS. Updates to this preference will trigger a CUSTOMERS_MARKETING_CONSENT_UPDATE webhook, allowing you to stay updated about the customer's marketing preferences.
These preferences are updated using the customerSmsMarketingConsentUpdate mutation, below is an example:
Variables:
Response:
As a reminder, all apps that perform marketing activities must update the customer record in Shopify with any marketing preferences collected from the customer. Having up-to-date information about the customer's marketing preferences in Shopify allows all apps on a store to respect every customer's marketing preferences.
For more information on the available marketing states and opt-in-levels, visit our documentation on the customerSmsMarketingConsentUpdate mutation.
Stay on top of changes
For all Shopify platform changes, make sure to subscribe to the developer changelog, the primary source of information for all new product launches. Stay up to date using the changelog, and stay ahead of the curve by adopting new features as soon as they’re shipped into the upcoming 2022-01 release candidate.
You can also subscribe to our monthly What’s New for Partners and Developers at Shopify newsletter, which will help keep you on top of all platform updates.
Read more
- API Deprecation at Shopify: 2022-04 Edition
- API Deprecation at Shopify: 2021-04 Edition
- Developer Digest: Nov. 1, 2018
- Shopify API Release: July 2021
- API Deprecation at Shopify: 2021-10 Edition
- Increase Merchant Trust: Introducing Updates to the Shopify Order API
- API Deprecation at Shopify: 2021-07 Edition