1

I am trying to create customer through SOAP API with below script. I am able to get customer details with customer id but can't create the customer.

I am getting this error "SOAP-ERROR: Encoding: object has no 'customer' property"

    <?php
    require('vendor/zendframework/zend-server/src/Client.php');
    require('vendor/zendframework/zend-soap/src/Client.php');
    require('vendor/zendframework/zend-soap/src/Client/Common.php');

    ini_set('display_errors', 1);
    $request = new SoapClient("http://127.0.0.1/magento2011/soap/?wsdl&services=integrationAdminTokenServiceV1");
    //$token = $request->integrationAdminTokenServiceV1CreateAdminAccessToken(array("username"=>"admin","password"=>"admin@123"));
    $token = $request->integrationAdminTokenServiceV1CreateAdminAccessToken(array("username"=>"soapadmin","password"=>"admin@1234"));
    //echo "<pre>"; print_r($token->result); exit;
    $opts = array(
        'http'=>array(
            'header' => 'Authorization: Bearer '.$token->result
        )
    );
    //echo "<pre>"; print_r($opts); exit;
    $serviceArgs = array("customerId" => 1);

    $customerparams = array('email' => 'customer-mail@example.org',
                            'firstname' => 'Dough',
                            'lastname' => 'Deeks',
                            'password' => 'test@123',
                            'website_id' => 1,
                            'store_id' => 1,
                            'group_id' => 1
                           );

    //echo "<pre>"; print_r($customerparams); exit;

    $wsdlUrl = 'http://127.0.0.1/magento2011/soap/default?wsdl&services=customerCustomerRepositoryV1';
    $context = stream_context_create($opts);
    try{
        $soapClient = new \Zend\Soap\Client($wsdlUrl);
        $soapClient->setSoapVersion(SOAP_1_2);
        $soapClient->setStreamContext($context);
        //$soapResponse = $soapClient->customerCustomerRepositoryV1GetById($serviceArgs);
        //$soapResponse = $soapClient->customerCustomerRepositoryV1GetList();
        $soapResponse = $soapClient->customerCustomerRepositoryV1Save($customerparams);
        echo "<pre>"; var_dump((array) $soapResponse);
    }catch(Exception $e){
        echo "Exception Error:------".$e->getMessage();
    }
?>
  • Anyone please help on this concept. – Ramesh May 10 '17 at 7:31
1

I got the solution, Actually we need to pass parameters as like below format.

$customerdata = ['customer'=>
                                 [
                                  'email'=> 'customer-mail@example.org',
                                  'firstname' => 'Dough',
                                  'lastname' => 'Deeks',
                                  'password' => 'test@123',
                                  'promotion_code' => 'test123',
                                  'regulation' => '1',
                                  'website_id' => 1,
                                  'store_id' => 1,
                                  'group_id' => 1
                                 ]
                    ];
   $wsdlUrl = 'http://127.0.0.1/magento2011/soap/default?wsdl&services=customerCustomerRepositoryV1';
    $context = stream_context_create($opts);
    try{
        $soapClient = new \Zend\Soap\Client($wsdlUrl);
        $soapClient->setSoapVersion(SOAP_1_2);
        $soapClient->setStreamContext($context);
        //$soapResponse = $soapClient->customerCustomerRepositoryV1GetById($customerId);
        //$soapResponse = $soapClient->customerCustomerRepositoryV1GetList();
        $soapResponse = $soapClient->customerCustomerRepositoryV1Save($customerdata);
        //$soapResponse = $soapClient->customerCustomerRepositoryV1DeleteById($serviceArgs);
        //$soapResponse = $soapClient->customerCustomerRepositoryV1GetList($searchCriteria);
        echo "<pre>"; var_dump((array) $soapResponse);
    }catch(Exception $e){
        echo "Exception Error:------".$e->getMessage();
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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