如何使用BigCommerce API更新自定义字段?

问题描述:

我期待更新产品上的自定义字段。如何使用BigCommerce API更新自定义字段?

the guide on how to do it manually via the admin interface

API docs发现表明,你不能直接修改的自定义字段上的产品,只能访问他们:

我的下一个念头,就是update the product

这是产品上现有的custom_field。

{ 
    "url"=> "https://storename.mybigcommerce.com/api/v2/products/32/customfields.json", 
    "resource"=>"/products/32/customfields" 
} 

当我尝试修改URL /资源并发送哈希回更新,我用400 Bad Request :(

new_custom_fields = { 
"url" => "https://storename.mybigcommerce.com/api/v2/products/75/customfields.json", 
"resource" => "/products/75/customfields" 
} 

api.update_products(75, {"custom_fields" => new_custom_fields}) 
RuntimeError: Failed to parse Bigcommerce response: 400 Bad Request 

思考招呼?

+0

感谢您的URL清理:) – manderson 2013-05-06 19:11:24

这似乎是一个Bigcommerce API中的bug现在只支持自定义字段的GET请求

http://developer.bigcommerce.com/api/products/customfields

这可能是你碰到400的原因。

不知道这是否有助于Ruby,但它可以帮助那些使用PHP ...我可以在产品上创建自定义字段使用PHP。只需要产品ID和自定义字段“name”和“text”的值。

$data_array = array('name' => 'gender', 'text' => 'male'); 
BigCommerce::createProductCustomField('17', $data_array); 

我没有尝试过更新的自定义字段,但是,如果创建一个作品,那么下面也应努力更新当前自定义字段:

BigCommerce::updateProductCustomField($product_id, $id, $object); 

您将需要$ PRODUCT_ID要更新的产品的名称,要更新的自定义字段的$ id以及$ object应该是上面的$ data_array这样的数组。 PHP客户端上

更多信息的BC:https://github.com/bigcommerce/bigcommerce-api-php

祝你好运!

试试这个代码:

$头=阵列(
"内容类型:应用/ JSON ",
// "授权:基本" BASE64_ENCODE($凭证)
);
$ name ='Bullet Point';
$ data_array = array('name'= >'Bullet Point','text'= >'Bullet Point value');
$ body = json_encode($ data_array);
//获取当前网址并将其拆分为'?'
$ ch = curl_init('https://www.abc.mybigcommerce.com/api/v2/products/1122/customfields。JSON'); //打开连接
curl_setopt($ CH,CURLOPT_TIMEOUT,60); //设置为60秒,从BC API指南V1 PDF例如
curl_setopt($ CH,CURLOPT_HTTPHEADER,$头); //加载所有标题数据
curl_setopt($ CH,CURLOPT_CUSTOMREQUEST," POST "); //注释掉该行PUT更改为POST声明
curl_setopt($ CH,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ ch,CURLOPT_USERPWD," admin:api-key ");
curl_setopt($ ch,CURLOPT_POSTFIELDS,$ body);
curl_setopt($ CH,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);
$结果= curl_exec($ CH); //执行后
curl_close($ ch);