dqwd71332 2016-11-21 20:33
浏览 72
已采纳

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 ?

  • 写回答

1条回答 默认 最新

  • douan5151 2016-11-22 09:31
    关注

    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"

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题