我正在使用Magento版本。 2.1.2 REST API來創建用戶,以下這一點: http://devdocs.magento.com/guides/m1x/api/rest/Resources/resource_customers.html#RESTAPI-Resource-Customers-HTTPMethod-POST-customersPhp Magento Api Rest創建客戶密碼問題:
$data = [
"customer" => [
"firstname" => 'Earl',
"lastname" => 'Hickey',
"email" => '[email protected]',
"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」=>'password',就會創建一個沒有密碼的用戶(對我而言似乎很奇怪)。
我找不到這個錯誤的任何幫助。 任何想法的人?
入住這裏一步一步的指導:http://magento.stackexchange.com/questions/150581/magento-2-how-to-call-rest- api-to-register-a-new-customer/156818#156818 – Manish