magento api 2 创建产品错误
magento api 2 create product error
我已经使用 C#
调用 magento rest api 来创建新产品
(magento version 2.2.5
)
这是正文数据:
{
"product": {
"id": 0,
"sku": "MS-Champ11",
"name": "Champ Tee11",
"attribute_set_id": 9,
"price": 110,
"status": 1,
"visibility": 4,
"type_id": "simple",
"created_at": null,
"updated_at": null,
"weight": 5,
"extension_attributes": null,
"product_links": null,
"options": null,
"media_gallery_entries": null,
"tier_prices": null,
"custom_attributes": [
{
"attribute_code": "description",
"value": "Test Description"
}
]
},
"save_options": false
}
这是我的 C# 代码:
public string CreateProduct(Product product)
{
try
{
var request = CreateRequest("/rest/V1/products", Method.POST, Token);
var prod = new ProductModel();
prod.Product = product;
string json = JsonConvert.SerializeObject(prod, Formatting.Indented);
request.AddParameter("application/json", json, ParameterType.RequestBody);
var response = Client.Execute(request);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
return "Succeed";
}
else
{
return "Failed";
}
}
catch (Exception ex)
{
return ex.ToString();
}
}
我尝试了很多次,但总是响应错误
"BadRequest"
{"message":"Invalid product data: %1","parameters":["Invalid attribute set entity type"]}
我做错了什么?请帮忙
你体内数据中的以下数据不正确
"attribute_set_id": 9,
您可以在 Magento 管理 -> 商店 -> 属性集 -> 'Your attribute set' 中找到属性集 ID。您可以在 url
中找到 id 值
magento.domain/admin/catalog/product_set/edit/id/4/key
我已经使用 C#
调用 magento rest api 来创建新产品
(magento version 2.2.5
)
这是正文数据:
{
"product": {
"id": 0,
"sku": "MS-Champ11",
"name": "Champ Tee11",
"attribute_set_id": 9,
"price": 110,
"status": 1,
"visibility": 4,
"type_id": "simple",
"created_at": null,
"updated_at": null,
"weight": 5,
"extension_attributes": null,
"product_links": null,
"options": null,
"media_gallery_entries": null,
"tier_prices": null,
"custom_attributes": [
{
"attribute_code": "description",
"value": "Test Description"
}
]
},
"save_options": false
}
这是我的 C# 代码:
public string CreateProduct(Product product)
{
try
{
var request = CreateRequest("/rest/V1/products", Method.POST, Token);
var prod = new ProductModel();
prod.Product = product;
string json = JsonConvert.SerializeObject(prod, Formatting.Indented);
request.AddParameter("application/json", json, ParameterType.RequestBody);
var response = Client.Execute(request);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
return "Succeed";
}
else
{
return "Failed";
}
}
catch (Exception ex)
{
return ex.ToString();
}
}
我尝试了很多次,但总是响应错误
"BadRequest"
{"message":"Invalid product data: %1","parameters":["Invalid attribute set entity type"]}
我做错了什么?请帮忙
你体内数据中的以下数据不正确
"attribute_set_id": 9,
您可以在 Magento 管理 -> 商店 -> 属性集 -> 'Your attribute set' 中找到属性集 ID。您可以在 url
中找到 id 值magento.domain/admin/catalog/product_set/edit/id/4/key