0

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" => '[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);

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 ?

asked Nov 21, 2016 at 21:19

1 Answer 1

0

Use below code to create customer account by api

 $data = [
 "customer" => [
 "firstname" => 'Earl',
 "lastname" => 'Hickey',
 "email" => '[email protected]',
 "website_id" => 1,
 'store_id' => 1,
 "group_id" => 1
 ],
 "password" => 'password'
 ];
 $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);
answered Jan 25, 2017 at 12:55

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.