【发布时间】:2022-11-10 02:07:25
【问题描述】:
遇到 GAS 和 WC RESTv2 之间的问题,我试图创建一个具有自定义属性的简单产品,而我能够在没有任何特定参数的情况下这样做,REST api 返回此错误:
错误:
{"code":"rest_invalid_param","message":"无效参数:属性","data":{"status":400,"params":{"attributes":"attributes[0] 不是对象类型。"},"details":{"attributes":{"code":"rest_invalid_type","message":"attributes[0] 不是对象类型。","data":{"param" :"属性[0]"}}}}}
// the product gets CREATED fine using this simple var data structure :
var data =
{
"name" : " TESTING HERE TOO",
//"sku" : "TESTINGINGING ",
"type" : "simple",
"regular_price" : "1.99",
"weight" : 10,
"manage_stock" : true,
"stock_quantity" : 10,
"description" : "testing \n" } ;
var surl = website + "/wp-json/wc/v2/products?consumer_key=" + keys + "&consumer_secret=" + scret;
var options =
{
"method": "POST",
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
"muteHttpExceptions": true,
"payload": data
};
``` // -- the product DOES NOT get created using this :
var data =
{
"name" : " TESTING HERE TOO",
//"sku" : "TESTINGINGING ",
"type" : "simple",
"regular_price" : "1.99",
"weight" : 10,
"manage_stock" : true,
"stock_quantity" : 10,
"description" : "testing \n" } ;
"attributes" : [ { "variation" : "false", "options" : "[ANY]", "id" : 0.0, "name" : "Supplier", "position" : 0.0, "visible" :"false"} , { "variation" : "false", "options" : "[ANY]", "id" : 0.0, "name" : "Invoice", "position" :1.0, "visible" :"false"}]
任何机构都可以阐明问题所在?
【问题讨论】:
标签: api rest woocommerce