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' => '[email protected]',
                            '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();
    }
?>
1
  • Anyone please help on this concept.
    – Ramesh
    May 10, 2017 at 7:31

1 Answer 1

1

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

$customerdata = ['customer'=>
                                 [
                                  'email'=> '[email protected]',
                                  '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 and acknowledge you have read our privacy policy.

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