Greetings everyone!
I am making a change to a product specification via API at the Endpoint:
/api/catalog_system/pvt/products/{productId}/specification
And the body listed in the documentation is not accepted by the API.
Below is the example provided in the documentation followed by the error returned.
[
{
"Value": [
"Iron",
"Plastic"
],
"Id": 30,
"Name": "Material"
}
]
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type āVTEX.Commerce.CatalogApi.Web.Catalog.ProductFieldValueDtoā because the type requires a JSON object (e.g. {ānameā:āvalueā}) to deserialize correctly.
Would anyone know the correct way to send the request body?
I ran a test here with values similar to those in the documentation, and it worked.
- First, I made a GET request to check the existing values:
curl --location --request GET 'https://{{accountName}}.vtexcommercestable.com.br/api/catalog_system/pvt/products/1/specification' \
--header 'VtexIdclientAutCookie: {{cookie}}' \
--header 'Content-Type: application/json' \
--data '[
{
"Value": [
"Wavy"
],
"Id": 18,
"Name": "Curl Type"
}
]'
- Then, I made a POST request adding a new value to a spec:
curl --location 'https://{{accountName}}.vtexcommercestable.com.br/api/catalog_system/pvt/products/1/specification' \
--header 'VtexIdclientAutCookie: {{cookie}}' \
--header 'Content-Type: application/json' \
--data '[
{
"Value": [
"Wavy",
"Curly"
],
"Id": 18,
"Name": "Curl Type"
}
]'
- Then, GET again:
curl --location 'https://{{accountName}}.vtexcommercestable.com.br/api/catalog_system/pvt/products/1/specification' \
--header 'VtexIdclientAutCookie: {{cookie}}' \
--data ''
The response from the last one included the new value I added, so it seems to have worked:
[
{
"Value": [
"Anti-Frizz"
],
"Id": 19,
"Name": "Benefit"
},
{
"Value": [
""
],
"Id": 21,
"Name": "Eco-Friendly"
},
{
"Value": [
"Wavy",
"Curly"
],
"Id": 18,
"Name": "Curl Type"
}
]