2016-10-10 68 views
1

如何使用REST API更新/添加客戶的EAV屬性?Magento 2.1使用REST API更新客戶自定義EAV屬性

我試圖做使用[PUT] /V1/customers/{id}這個URL

http://<website>/rest/V1/customers/1 

它,並以此爲主體數據:

$data = array(
    'customer' => array(
     'id' => 1, 
     'email' => '[email protected]', 
     'firstname' => 'John', 
     'lastname' => 'Doe', 
     'website_id' => 1, 
     'custom_attributes' => array(
      'attribute_code' => 'my_custom_attribute_code', 
      'value' => 'my_custom_attribute_value' 
     ) 
    ) 
); 

我能夠編輯客戶的默認屬性,例如firstnamelastname但我還沒有能夠編輯EAV屬性。

是否可以使用默認的customerCustomerRepositoryV1接口來完成? 如果不是,您如何擴展以便可以編輯/添加客戶的EAV屬性?

謝謝。

Magento的2.1 REST API接口: http://devdocs.magento.com/swagger

回答

0

有主體數據是錯誤的。我忘記把索引放在custom_attributes陣列上。

它應該是這樣的:

$data = array(
    'customer' => array(
     'id' => 1, 
     'email' => '[email protected]', 
     'firstname' => 'John', 
     'lastname' => 'Doe', 
     'website_id' => 1, 
     'custom_attributes' => array(
      '0' => array(
       'attribute_code' => 'my_custom_attribute_code', 
       'value' => 'my_custom_attribute_value' 
      ) 
     ) 
    ) 
); 
相關問題