Tôi đang sử dụng ver Magento. 2.1.2 REST API để tạo người dùng, sau này: http://devdocs.magento.com/guides/m1x/api/rest/Resources/resource_customers.html#RESTAPI-Resource-Customers-HTTPMethod-POST-customersPhp Magento Api Rest Tạo Mật khẩu Khách hàng Số phát hành:
$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);
Nếu tôi gửi một mật khẩu (như trong ví dụ trên), tôi đã có những lỗi sau:
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
tôi nhận thấy rằng nếu tôi loại bỏ "mật khẩu" => 'mật khẩu' từ mảng dữ liệu $, một người dùng được tạo ra mà không có mật khẩu (có vẻ lạ với tôi).
Tôi không thể tìm thấy bất kỳ trợ giúp nào về lỗi này. Bất kỳ ý tưởng nào?
Kiểm tra ở đây hướng dẫn từng bước: http://magento.stackexchange.com/questions/150581/magento-2-how-to-call-rest- api-to-register-a-new-khách hàng/156818 # 156818 – Manish