Building Shopify Apps with PHP (Shopify 2019-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 2019-07. It’s their very first API versioning to ensure that future updates to the platform are predictable, clearly communicated and easy to be adopted.

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 2019-07 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/<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/2019-07/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

If you noticed, the first version released in April 2019. That means that the next update will happen on July 2019, and so on.

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/2019-07";

$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 calls. Just overwrite the value of the variable and that’s it. You’re updated now.

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
Bernard Polidario
About Bernard Polidario

A full-stack developer who has been around programming community for 10+ years and still has a lot of passion for programming and design. I am the founder of WeeklyHow and I can be reached at [email protected]

https://weeklyhow.com

2 comments on Building Shopify Apps with PHP (Shopify 2019-07 Update)

    1. Hello Navpreet!

      Thank you for sending us a comment!

      If you are encountering a refused connection error message. You may want to double-check your URL and see if it gives you .myshopify.com.myshopify.com. That’s most likely the reason behind the error. Otherwise, it’s related to your server.

      We hope we helped you!

      Cheers from WeeklyHow

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*
*