Php Magento Api Rest创建客户密码问题:
我正在使用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',就会创建一个没有密码的用户(对我而言似乎很奇怪)。
我找不到这个错误的任何帮助。 任何想法的人?
请参阅下面的链接Magento 2.x版本。 http://devdocs.magento.com/swagger/index_20.html#/
我已经使用下面的身体通过Rest Api创建客户,并且它正常工作。
{ “客户”:{
“电子邮件”: “[email protected]”, “名字”: “X”, “姓氏”, “Y”, “website_id”: 1, “GROUP_ID”:1, “custom_attributes”:[{ “attribute_code”: “mobile_no”, “值”: “1234567890” } ]
},
“密码”: “123456”
}
谢谢,作品像一个魅力。 但是,为什么在那个文档中密码是客户的一部分? http://devdocs.magento.com/guides/m1x/api/rest/Resources/resource_customers.html#RESTAPI-Resource-Customers-HTTPMethod-POST-customers。 最后一个问题,在大摇大摆的地方,你究竟在哪里找到这个信息? 我唯一能找到的是“customerAccountManagementV1”,而且这里没有提到密码。 – user2227498
链接:http://devdocs.magento.com/guides/m1x/api/rest/Resources/resource_customers.html#RESTAPI-Resource-Customers-HTTPMethod-POST-customers – qwerty
对不起,以上评论。 链接:http://devdocs.magento.com/guides/m1x/api/rest/Resources/resource_customers.html#RESTAPI-Resource-Customers-HTTPMethod-POST-customers 用于Magento 1.x版本。 在文档中,他们只给出了示例,我分享了我使用它的方式。 在swagger中,您可以单击customerCustomerRepositoryV1链接,您将通过它的示例获取所有与客户相关的API。 – qwerty
入住这里一步一步的指导:http://magento.stackexchange.com/questions/150581/magento-2-how-to-call-rest- api-to-register-a-new-customer/156818#156818 – Manish