Why should I update an array of attributes?
When searching for or filtering an attribute containing multiple values, you should ensure that you update the corresponding array to ensure the filter is applied to each of the values. Failing to do this will only allow you to filter them as a group.
For example, if you had an attribute containing the values 'A' 'B' 'C', and you wanted to filter according to 'B', you would need to ensure that you have updated the array accordingly. Sending the values as a string, such as 'A,B,C' will only allow you to filter the group in its entirety - 'A,B,C'. You won't be able to filter products by 'B' as a separate value.
How Can I Update an Array of Attributes?
The ability to send an attribute as an array via API is a great way to update a product and add an attribute with multiple values. You must format them as a JSON array when constructing the API request. This article explains how to do so.
To save an attribute that has different values (for example, the attribute 'category' can have 3 different values such as 'A' 'B', and 'C'), you need to send us the values as an array and not as a string.
The correct way to send it is as follows -
Your payload should look like this:
{
"payload": [
{
"attributes": [
{
"name": "string",
"value": "string",
}
],
"client_key": "string",
"disabled": 0,
"label": "AEG PowerDrill N-45Z Black",
"meta": {
"image": "string",
"permalink": "string"
},
"prices": [
{
"cost": 0,
"inventory": 0,
"shelf": 0,
"tag": "offline"
}
],
"product_id": "string"
}
]
}
The attribute should be sent like this:
"attributes": [
{
"name": "catgory",
"value": "A"
},
{
"name": "catgory",
"value": "B"
},
{
"name": "catgory",
"value": "C"
},
{
"name": "brand",
"value": "apple"
}
]Another option to update an array is sending it like this:
"attributes": [
{
"name": "catgory",
"value": ["A","B","C"].to_s
},
{
"name": "brand",
"value": "apple",
}
]Be alert: The array must be converted to an array. In this scenario, we format the array as a string using the "to_s" command in the example ruby code.
Comments
0 comments
Please sign in to leave a comment.