2

I am trying to create new customer using magento soap api , here is my code :

    $client = new SoapClient('http://map.itgprojects.pw/api/v2_soap?wsdl=1');


    `$session = $client->login('mylogiin',` 'myapikey');
    $result = $client->customerCustomerCreate($session, ['email' => '[email protected]', 'firstname' => 'Dough', 'lastname' => 'Deeks', 'password' => 'password', 'website_id' => 1, 'store_id' => 1, 'group_id' => 1]);

    var_dump ($result);

I keep getting this error and I don't know why, even if the user has been added to the database :

Uncaught SoapFault exception: [SOAP-ENV:Server] Call to a member function getUserId() on null in /home/mapitgprojects/public_html/api/customer.php:51

version of magento : 1.9

I am working on an ionic app and I'am creating a web service to do some stuff.

Thank you for your help

enter image description here

9
  • Please try the code which is in answer. Commented Sep 28, 2018 at 16:07
  • I'm using SOAP V2, but I tried your answer it didn't work , I'm having the same error : Call to a member function getUserId() on null
    – Hanane
    Commented Sep 28, 2018 at 16:18
  • Hi, please check updated answer Commented Sep 28, 2018 at 16:29
  • Is it your first soap api ? Commented Sep 28, 2018 at 16:30
  • yes it is my first, I 'm having the same error with ur updated answer. I can retrieve list of customers with customerCustomerList but i can't add a new one
    – Hanane
    Commented Sep 28, 2018 at 16:48

1 Answer 1

1
$client = new SoapClient('http://magentohost/api/v2_soap/?wsdl');

// If some stuff requires api authentication,
// then get a session token
$session = $client->login('apiUser', 'apiKey');
$result = $client->customerCustomerCreate($session, array('email' => '[email protected]', 'firstname' => 'Dough', 'lastname' => 'Deeks', 'password' => 'password', 'website_id' => 1, 'store_id' => 1, 'group_id' => 1));

var_dump ($result);

Request Example SOAP V1

$client = new SoapClient('http://magentohost/api/soap/?wsdl');

// If somestuff requires api authentication,
// then get a session token
$session = $client->login('apiUser', 'apiKey');
$result = $client->call($session,'customer.create',array(array('email' => '[email protected]', 'firstname' => 'Dough', 'lastname' => 'Deeks', 'password' => 'password', 'website_id' => 1, 'store_id' => 1, 'group_id' => 1)));

var_dump ($result);

// If you don't need the session anymore
//$client->endSession($session);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.