Getting started
Search
⌃K
Links

Tagging resources

How to tag a resource via API
Most of Commerce Layer's resources can be tagged using one or more existing tags. To do that, you need to update the resource setting the relationship with the desired tag(s).
A maximum of 10 tags is allowed for each single resource object.

Example

Request
Response
The following request tags the resource identified by the "xYZkjABcde" ID with the two tags identified by the "geJmexflJQ" and "mWJAPvfBaV" IDs:
curl -g -X PATCH \
'https://yourdomain.commercelayer.io/api/skus/xYZkjABcde' \
-H 'Accept: application/vnd.api+json' \
-H 'Authorization: Bearer your-access-token' \
-H 'Content-Type: application/vnd.api+json' \
-d '{
"data": {
"type": "skus",
"id": "xYZkjABcde",
"relationships": {
"tags": {
"data": [
{
"type": "tags",
"id": "geJmexflJQ"
},
{
"type": "tags",
"id": "mWJAPvfBaV"
}
]
}
}
}
}'
On success, the API responds with a 200 OK status code, returning the updated resource object:
{
"data": {
"id": "xYZkjABcde",
"type": "skus",
"links": {
"self": "https://yourdomain.commercelayer.io/api/skus/xYZkjABcde"
},
"attributes": {
"code": "TSHIRTMS000000FFFFFFLXXX",
"name": "Black Men T-Shirt with White Logo (L)",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
"image_url": "https://img.yourdomain.com/skus/xYZkjABcde.png",
"pieces_per_pack": null,
"weight": null,
"unit_of_weight": null,
"hs_tariff_number": null,
"do_not_ship": false,
"do_not_track": false,
"created_at": "2018-01-01T12:00:00.000Z",
"updated_at": "2018-01-01T12:00:00.000Z",
"reference": "ANYREFEFERNCE",
"reference_origin": "ANYREFEFERNCEORIGIN",
"metadata": {}
},
"relationships": {
"shipping_category": { ... },
"prices": { ... },
"stock_items": { ... },
"delivery_lead_times": { ... },
"sku_options": { ... },
"attachments": { ... },
"events": { ... },
"tags": {
"links": {
"self": "https://yourdomain.commercelayer.io/api/skus/xYZkjABcde/relationships/tags",
"related": "https://yourdomain.commercelayer.io/api/skus/xYZkjABcde/tags"
}
}
},
"meta": {
"mode": "test",
"organization_id": "YyrQYFzERk"
}
}
}

Removing tags

To remove one or more tags from a resource you need to update the resource setting the relationship with the updated list of tags. To remove all the tags from a resource, just set the tags relationship as an empty array.
Deleting a tag automatically removes any existing association.

Example

Request
Response
The following request removes all the tags associated with the resource identified by the "xYZkjABcde" ID:
curl -g -X PATCH \
'https://yourdomain.commercelayer.io/api/skus/xYZkjABcde' \
-H 'Accept: application/vnd.api+json' \
-H 'Authorization: Bearer your-access-token' \
-H 'Content-Type: application/vnd.api+json' \
-d '{
"data": {
"type": "skus",
"id": "xYZkjABcde",
"relationships": {
"tags": {
"data": []
}
}
}
}'
On success, the API responds with a 200 OK status code, returning the updated resource object:
{
"data": {
"id": "xYZkjABcde",
"type": "skus",
"links": {
"self": "https://yourdomain.commercelayer.io/api/skus/xYZkjABcde"
},
"attributes": {
"code": "TSHIRTMS000000FFFFFFLXXX",
"name": "Black Men T-Shirt with White Logo (L)",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
"image_url": "https://img.yourdomain.com/skus/xYZkjABcde.png",
"pieces_per_pack": null,
"weight": null,
"unit_of_weight": null,
"hs_tariff_number": null,
"do_not_ship": false,
"do_not_track": false,
"created_at": "2018-01-01T12:00:00.000Z",
"updated_at": "2018-01-01T12:00:00.000Z",
"reference": "ANYREFEFERNCE",
"reference_origin": "ANYREFEFERNCEORIGIN",
"metadata": {}
},
"relationships": {
"shipping_category": { ... },
"prices": { ... },
"stock_items": { ... },
"delivery_lead_times": { ... },
"sku_options": { ... },
"attachments": { ... },
"events": { ... },
"tags": { ... }
},
"meta": {
"mode": "test",
"organization_id": "YyrQYFzERk"
}
}
}