我正在使用Magento ver。 2.1.2 Rest Api创建用户,如下: http://devdocs.magento.com/guides/m1x/api/rest/Resources/resource_customers.html#RESTAPI-Resource-Customers-HTTPMethod-POST-customers
$data = [
"customer" => [
"firstname" => 'Earl',
"lastname" => 'Hickey',
"email" => 'earl-2@example.com',
"password" => 'password',
"website_id" => 1,
'store_id' => 1,
"group_id" => 1
]
];
$token = $this->get('lp_api')->getToken();
$ch = curl_init( $this->endpoint . 'customers');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json", "Authorization: Bearer " . json_decode( $token ),
)
);
// var_dump(curl_getinfo($c));
$result = curl_exec($ch);
如果我发送密码(如上例所示),我会收到以下错误:
Next Exception: Report ID: webapi-583357a3bf02f; Message: Property "Password" does not have corresponding setter in class "Magento\Customer\Api\Data\CustomerInterface". in /var/www/html/www.magento.dev/vendor/magento/framework/Webapi/ErrorProcessor.php:195
我注意到如果我删除“密码”=>来自$ data数组的'password',用户创建时没有密码(对我来说似乎很奇怪)。
我找不到任何有关此错误的帮助。 任何想法的人?
答案 0 :(得分:2)
请参阅以下链接了解Magento 2.x版本。 http://devdocs.magento.com/swagger/index_20.html#/
我使用下面的身体通过Rest Api创建客户并且它正常工作。
{ "客户":{
" email":" xyz@abc.com", "名字":" x", "姓氏":" y", " website_id":1, " GROUP_ID":1, " custom_attributes":[ { " attribute_code":" mobile_no", "价值":" 1234567890" } ]
},
"密码":" 123456"
}