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).
Updating resourcesExample
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"
}
]
}
}
}
}'
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.
Example
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": []
}
}
}
}'
Updating the list of tags
If a resource is already associated with one or more tags, tagging the resource by updating the relationship will remove all the currently associated tags and replace them with the new list of tags. If you just need to change the list of the tags currently associated with a resource, you can patch the taggable resource and send the trigger attributes _add_tags
and/or _remove_tags
specifying the comma-separated list of tag names that you want to add and/or remove.
Example
The following request changes the list of 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",
"attributes": {
"_add_tags": "out-of-stock,old-collection",
"_remove_tags": "new-collection,vip"
}
}
}'
Last updated