Building Shopify Apps with PHP (Shopify 2020-07 Update)

4th May 2019   Shopify

 

If you are a Shopify app developer, you may have already heard that they made an update with their Shopify’s Admin API (GraphQL and REST) called Shopify API versioning. At this moment, we are already at 2020-07. It’s their third API versioning and a lot of improvements have been made.

Their goal is to ensure that any developers could build Shopify apps and Shopify themes confidently. They have also made changes to their Shopify Partner Dashboard, the Developer Changelog, and to their developer documentation page to make it easier for us developers to stay updated of upcoming new versions.

 

If you have already built a Shopify app using the old versions of Shopify API. Migrating to Shopify API 2020-01 is very easy. All you needed to do is to update the endpoint URLs that your app calls to explicitly declare the API version.

Each URL should include the following format.

/admin/api/<version date>

For example, if you are trying to call using the REST endpoint, the URL endpoint could go something like:

https://<your-shop-name>.myshopify.com/admin/api/2020-01/smart_collections.json

 

Shopify API Versioning

Keep in mind that Shopify will release another update for the API versioning quarterly. This means that you should always stay up-to-date on what’s new.

Now, if you are confused about when they’re going to make updates. You may use the following table as your guide or reminder.

Stable versionRelease dateDate stable version is supported until
2020-01January 1, 2020January 1, 2021
2020-04April 1, 2020April 1, 2021
2020-07July 1, 2020July 1, 2021
2020-10October 1, 2020October 1, 2021

How to use API versioning?

If you have already developed an app using the old API then I highly recommend you to update your PHP files and change the base URLs.

Also, to make it easier for you. You should just declare a variable holding the version name of the latest API version. By doing so, every time Shopify updates the API, you won’t need to change anything but the variable holding the version name.

For this example, we’ll be using the code that we wrote on our previous tutorial on how to display Shopify products using PHP.

$collectionList = shopify_call($token, $shop, "/admin/custom_collections.json", array(), 'GET'); $collectionList = json_decode($collectionList['response'], JSON_PRETTY_PRINT); $collection_id = $collectionList['custom_collections'][0]['id']; $array = array("collection_id"=>$collection_id); $collects = shopify_call($token, $shop, "/admin/collects.json", $array, 'GET'); $collects = json_decode($collects['response'], JSON_PRETTY_PRINT);

If you have noticed, the code above is using the old format of API. No versioning whatsoever.

Migrating to New Shopify API versioning

To migrate from old API to new Shopify API versioning. We must change the code above to something like this.

$shopifyVer = "api/2020-01"; $collectionList = shopify_call($token, $shop, "/admin/".$shopifyVer."/custom_collections.json", array(), 'GET'); $collectionList = json_decode($collectionList['response'], JSON_PRETTY_PRINT); $collection_id = $collectionList['custom_collections'][0]['id']; $array = array("collection_id"=>$collection_id); $collects = shopify_call($token, $shop, "/admin/".$shopifyVer."/collects.json", $array, 'GET'); $collects = json_decode($collects['response'], JSON_PRETTY_PRINT);

The code above will make it easier for us to update our Shopify API calls. Just overwrite the value of the variable and that’s it.

Another thing to remember to keep your app updated is to navigate to your app setup. In the Webhook API version section, change the dropdown value to the latest version like below.

 

Conclusion

Nothing really special happened in this update. All they wanted to achieve is to make it easier for Shopify developers like us to stay updated on upcoming new versions.

 

React to this topic
Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments