Shopify Get Collections
Summary of Changes: (The purpose of this table is to keep traceability and Product team to highlight the things that were changed into the scope, based on comments or discussions)
Version | Date | Created / Updated | Notes |
---|---|---|---|
v1.0 | Hristiyan | First publish |
A smart collection is a grouping of products defined by rules that are set by the merchant. Shopify automatically changes the contents of a smart collection based on the rules. Smart collections, like other types of collections, are used to break down the catalog of products into categories and make the shop easier to browse.
The purpose of the call will be for the end user to be able to download all the smart collections in their store into a .csv file and by this way to manage the collections in Shopify easier. We want this to happen through a button called “Get Collections” in the Account Shopify
table. Once the button is pressed, it should generate and download a .csv file with the information. We should have a validation and if the integration is not established (if we don’t have an access token generated) the button needs to be unpressable.
The CSV delimiter will be comma (,) and we need to place all the enclosing (“) and escaping end line characters (\r\n) . The file name structure should be : SmartCollectionsExport{YYYY}{MM}{DD}{HH}{MI}{SS}.csv
API Docs : https://shopify.dev/docs/api/admin-rest/2024-04/resources/smartcollection API Call : GET /admin/api/2024-04/smart_collections.json
Sample Request : GET https://{{store}}.myshopify.com/admin/api/2024-04/smart_collections.json
Headers:
X-Shopify-Access-Token: {access_token}.
Example response :
{
"smart_collections": [
{
"id": 482865238,
"handle": "smart-ipods",
"title": "Smart iPods",
"updated_at": "2008-02-01T19:00:00-05:00",
"body_html": "<p>The best selling ipod ever</p>",
"published_at": "2008-02-01T19:00:00-05:00",
"sort_order": "manual",
"template_suffix": null,
"disjunctive": false,
"rules": [
{
"column": "type",
"relation": "equals",
"condition": "Cult Products"
}
],
"published_scope": "web",
"admin_graphql_api_id": "gid://shopify/Collection/482865238",
"image": {
"created_at": "2024-01-02T09:28:43-05:00",
"alt": "MP3 Player 8gb",
"width": 123,
"height": 456,
"src": "https://cdn.shopify.com/s/files/1/0005/4838/0009/collections/ipod_nano_8gb.jpg?v=1704205723"
}
}
]
}
Mapping: Please note N/A means we exclude it from saving it in the CSV.
Shopify Field | CSV Header Name | CSV Header Position | Comment | ||
---|---|---|---|---|---|
smart_collections |
|||||
id |
ID | 1 | |||
handle |
Handle | 2 | |||
title |
Title | 3 | |||
updated_at |
N/A | ||||
body_html |
Description | 4 | |||
published_at |
N/A | ||||
sort_order |
Sort order | 5 | |||
template_suffix |
N/A | ||||
disjunctive |
N/A | ||||
rules |
|||||
column |
Rules | 6 | The rules will be sent in three separate nodes which are column relation and condition . We want to combine the three nodes and store them as a rule. |
The way we should combine them is in the exact order :
olumn
relation
condition
.
As an example we can have :
column
: "title",
relation
: "contains",
condition
: "Apple"
So in the csv, we should store the rule as “Title contains Apple”.
We can have more than one rule assigned to a collection so we need to store them all and delimit them with “|” . |
| | | relation
| | | |
| | | condition
| | | |
| | published_scope
| | N/A | | |
| | admin_graphql_api_id
| | N/A | | |
| | image
| | N/A | | |
| | | created_at
| N/A | | |
| | | alt
| N/A | | |
| | | width
| N/A | | |
| | | height
| N/A | | |
| | | src
| Image | 7 | We want to store only the src which is essentially the url of the image under a “Image” header. |
The file is not expected to be big as the maximum collections are 5000 and it is highly unlikely to even have a store with 5000 collections, so we want the file to be generated upon button press and to be downloaded locally.