Get all products’ info in Shopify

0
83
Get all products' info in Shopify

This is a tip for Shopify development. I will show you how easy it is to get all products’ info in Shopify store. The best thing of this tip is that, you don’t need to authenticate to use the API.

Get all products’ info in Shopify

First of all, let’s assume your store URL is STORE=your-store.myshopify.com so that it will make easier for you to read the API.

Straight to the API. In order to get all products in Shopify, you call this API directly:

STORE/admin/api/2020-01/products.json

You can paste into browser, or use curl or write a script to query the API, whatever is convenient for you. It will return a JSON file that contains all products in STORE.

The output is something similar to this:

{
"products": [
{
"id": 4602433962043,
"title": "5 Panel Camp Cap",
"body_html": "<p><em>This is a demonstration store. You can purchase products like this from <a href=\"http://unitedbyblue.com/\" target=\"_blank\">United By Blue</a>.</em></p>\n<p><span style=\"line-height: 1.4;\">A classic 5 panel hat with our United By Blue logo on the front and an adjustable strap to keep fit and secure. Made with recycled polyester and organic cotton mix.</span></p>\n<ul>\n<li><span style=\"line-height: 1.5;\">Made in New Jersey</span></li>\n<li><span style=\"line-height: 1.5;\">7oz Eco-Twill fabric: 35% organic cotton, 65% recycled PET (plastic water and soda bottles) </span></li>\n<li><span style=\"line-height: 1.5;\">Embossed leather patch</span></li>\n</ul>\n<ul class=\"tabs\"></ul>\n<p> </p>\n<ul class=\"tabs-content\"></ul>",
"vendor": "United By Blue",
"product_type": "Accessories",
"created_at": "2020-03-02T12:23:53-05:00",
"handle": "5-panel-hat",
"updated_at": "2020-03-02T12:23:54-05:00",
"published_at": "2020-03-02T12:23:52-05:00",
"template_suffix": null,
"published_scope": "web",
"tags": "Accessories",
"admin_graphql_api_id": "gid://shopify/Product/4602433962043",
"variants": [
  {
    "id": 32473924108347,
    "product_id": 4602433962043,
    "title": "Heather Green",
    "price": "48.00",
    "sku": "4255",
    ...

Wait, does it really return all products in store?

Limit number of products and get next/previous URLs

Just kidding, it doesn’t. In facts, it returns, by default, 50 products, and the rest of products can be queried via paging.

So, if there are more results for the API, the response header will contain this header key Link which indicates the URL for next page and URL for previous page.

The header will be like following:

Link: <https://STORE/admin/api/2020-01/products.json?limit=50&page_info=eyJsYXN0X2lkIjo0NjAyNDM0MjI0MTg3LCJsYXN0X3ZhbHVlIjoiQ2FudmFzIEx1bmNoIEJhZyIsImRpcmVjdGlvbiI6Im5leHQifQ>; rel="next"

In case, there are both previous and next pages, it could be:

Link: <https://STORE/admin/api/2020-01/products.json?limit=50&page_info=eyJkaXJlY3Rpb24iOiJwcmV2IiwibGFzdF9pZCI6NDYwMjQzMzYwMTU5NSwibGFzdF92YWx1ZSI6IkNoZXZyb24ifQ>; rel="previous", <https://STORE/admin/api/2020-01/products.json?limit=50&page_info=eyJkaXJlY3Rpb24iOiJuZXh0IiwibGFzdF9pZCI6NDYwMjQzNTIwNzIyNywibGFzdF92YWx1ZSI6IkRvdWJsZSBXYWxsIE11ZyJ9>; rel="next"

Okay, so what are limit and page_info in the page URLs?

limit is to indicate how many results per page, and page_info is an unique generated hash of your specific product search query. In reality, you don’t really care much about these two query parameters.

limit by default is 50, but you can set it to maximum at 250 products per query.

Filter output fields

With this API, you can also filter the output fields you expect to reduce unnecessary data in JSON result. For example:

STORE/admin/api/2020-01/products.json?fields=id,title,product_type,handle&limit=5

Filter by published status

If you want to filter all published products, use published_status=published, like following:

STORE/admin/api/2020-01/products.json?published_status=published

Use published_status=unpublished to return all unpublished products. By default, it is any which returns all products.

Other filter options

Some provided filter options you can try include:

  • ids=X1,X2,X3 : filter by comma-separated list of product IDs.
  • since_id=X: Restrict results to after the specified ID.
  • title=X: filter products by title.
  • vendor=X: filter products by vendor.
  • handle=X: filter products by handle.
  • product_type=X: filter products by product type.
  • collection_id=X: filter products in collection ID.
  • presentment_currencies=X: return product prices in certain currencies only. This is not a filter, in facts, it is a format. This option requires your store to be configured to handle multiple payment currencies.

References

That’s it. I have shown you how to get all products’ info in Shopify store. Hope this help your Shopify development progress.

Also, don’t forget to spend some time to refer official Shopify API documentation: