Php Magento Api Rest创建客户密码问题:

I'm using the Magento ver. 2.1.2 Rest Api to create users, following this : 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);

If i send a password (as in the example above), i've got the following error :

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

I noticed that if i remove the "password" => 'password' from the $data array, a user is created without password (seems odd to me).

I can't find any help on this error. Any idea anyone ?

drkjzk3359
drkjzk3359 点击此处分步指南:magento.stackexchange.com/questions/150581/...
3 年多之前 回复

1个回答



请参阅以下链接了解Magento 2.x版本。
http://devdocs.magento.com/swagger/index_20.html#/ </ p>

我在下面使用过 通过Rest Api创建客户的正文,它工作正常。</ p>

{
“客户”:{</ p>

“email”:“xyz @ abc .com“,
”firstname“:”x“,
”lastname“:”y“,
”website_id“:1,
”group_id“:1,
”custom_attributes“:[
{

“attribute_code”:“mobile_no”,
“value”:“1234567890”
}

] </ p>

},</ p>

“ 密码“:”123456“</ p>

} </ p>
</ div>

展开原文

原文

Refer below link for Magento 2.x version. http://devdocs.magento.com/swagger/index_20.html#/

I have used below body for creating customers through Rest Api and it worked properly.

{ "customer": {

"email": "xyz@abc.com", "firstname": "x", "lastname": "y", "website_id":1, "group_id":1, "custom_attributes": [ { "attribute_code": "mobile_no", "value": "1234567890" } ]

},

"password": "123456"

}

duanmeng3126
duanmeng3126 谢谢@ qwerty .....你救了我的一天..... !!
3 年多之前 回复
dqvy87517
dqvy87517 对不起上述评论。 链接:devdocs.magento.com/guides/m1x/api/rest/Resources / ...用于Magento 1.x版本。 在文档中,他们只给出了示例,我分享了我使用它的方式。 在swagger中,您可以单击customerCustomerRepositoryV1链接,在其中您将获得与其示例相关的所有客户相关API。
接近 4 年之前 回复
douqiangchuai7674
douqiangchuai7674 链接:devdocs.magento.com/guides/m1x/api/rest/Resources / ...
接近 4 年之前 回复
dqnf28092
dqnf28092 谢谢,工作就像一个魅力。 但是,为什么在该文档中,密码是客户的一部分? devdocs.magento.com/guides/m1x/api/rest/Resources/...。 最后一个问题,在招摇,你究竟在哪里找到这个信息? 我唯一能找到的是“customerAccountManagementV1”,这里没有提到密码。
接近 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐