We are trying to create products by API, if we use json as payload, no problem Endpoint:
POST /rest/default/V1/products
Payload:
{
"product": {
"sku": "MS-Champ-S",
"name": "Champ Tee Small",
"attribute_set_id": 9,
"price": 25,
"status": 1,
"visibility": 1,
"type_id": "simple",
"weight": "0.5",
"extension_attributes": {
"category_links": [
{
"position": 0,
"category_id": "11"
},
{
"position": 1,
"category_id": "12"
},
{
"position": 2,
"category_id": "16"
}
],
"stock_item": {
"qty": "10",
"is_in_stock": true
}
},
"custom_attributes": [
{
"attribute_code": "description",
"value": "The Champ Tee keeps you cool and dry while you do your thing. Let everyone know who you are by adding your name on the back for only $10."
},
{
"attribute_code": "tax_class_id",
"value": "2"
},
{
"attribute_code": "material",
"value": "148"
},
{
"attribute_code": "pattern",
"value": "196"
},
{
"attribute_code": "color",
"value": "52"
},
{
"attribute_code": "size",
"value": "168"
}
]
}
}
But we use an XML as payload, we face an error.
<?xml version="1.0" encoding="UTF-8"?>
<magento_api>
<product>
<attribute_set_id>9</attribute_set_id>
<custom_attributes>
<element>
<attribute_code>description</attribute_code>
<value>The Champ Tee keeps you cool and dry while you do your thing. Let everyone know who you are by adding your name on the back for only $10.</value>
</element>
<element>
<attribute_code>tax_class_id</attribute_code>
<value>2</value>
</element>
<element>
<attribute_code>material</attribute_code>
<value>148</value>
</element>
<element>
<attribute_code>pattern</attribute_code>
<value>196</value>
</element>
<element>
<attribute_code>color</attribute_code>
<value>52</value>
</element>
<element>
<attribute_code>size</attribute_code>
<value>168</value>
</element>
</custom_attributes>
<extension_attributes>
<category_links>
<element>
<category_id>11</category_id>
<position>0</position>
</element>
<element>
<category_id>12</category_id>
<position>1</position>
</element>
<element>
<category_id>16</category_id>
<position>2</position>
</element>
</category_links>
<stock_item>
<is_in_stock>true</is_in_stock>
<qty>10</qty>
</stock_item>
</extension_attributes>
<name>Champ Tee Small</name>
<price>25</price>
<sku>MS-Champ-S</sku>
<status>1</status>
<type_id>simple</type_id>
<visibility>1</visibility>
<weight>0.5</weight>
</product>
</magento_api>
error message:
An empty custom attribute is specified. Enter the attribute and try again.
we are able to create customers the both, without any problem