2013-05-06 45 views
0

我期待更新產品上的自定義字段。如何使用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

回答

0

不知道這是否有助於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

祝你好運!

0

試試這個代碼:

$頭=陣列(
"內容類型:應用/ 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);

相關問題