Add person through PHP web services

I would like to add a person entity through PHP web services and I have some difficulty adding phone and address to this person, can you please let me know what is wrong with my code:

//get WSDL client
$options = array('trace' => true);
$wsdl = 'crm.xxxxx.com/.../CRMwebservice.wsdl';
$client = new SoapClient($wsdl, $options);

//logon
$logonParams = array('username' => 'xxxxxx', 'password' => 'xxxxxx');
$logonResponse = $client->logon($logonParams);

//set swap header
$sessionId = $logonResponse->result->sessionid;
$header = '<sessionheader><sessionid>' . $sessionId . '</sessionid></sessionheader>';
$sessionVar = new SoapVar($header, XSD_ANYXML, null, null, null);
$sessionHeader = new SoapHeader('http://tempuri.org/type', 'SessionHeader', $sessionVar);
$client->__setSoapHeaders(array($sessionHeader));

//add contact/person record
$phoneData[] = array(
'countrycode' => '999',
'areacode' => '99',
'number' => '9999999',
'type' => 'Business',
);
$phone = new SoapVar($phoneData, XSD_ANYTYPE, "phone", "">http://tempuri.org/type");

$emailData[] = array(
'type' => 'Business',
'emailaddress' => '[email protected]'
);
$email = new SoapVar($emailData, XSD_ANYTYPE, "email", "">http://tempuri.org/type");

$personData = array(
'firstname' => 'firstname',
'lastname' => 'lastname',
'phone' => $phone,
'email' => $email,
'companyname' => 'company',
'country' => 'jordan',
'title' => 'Mr',
'source' => 'web'
);

$person = new SoapVar($personData, SOAP_ENC_OBJECT, "person", "">http://tempuri.org/type");
$personResponse = $client->add(array('entityname' => 'person', 'records' => $person));

$logoffParams = array('sessionId' => $sessionId);
$logoffResponse = $client->logoff($logoffParams);

As you see from the above code I was able to insert a person but the phone & email are empty.

  • 0

    I don't use PHP. But below is an example of the generated XML that can be sent to create a new company with a child person and phone and email records. This should give you an idea of how to solve this in PHP.

    " href="http://schemas.xmlsoap.org/soap/envelope/"">schemas.xmlsoap.org/.../" xmlns:xsi="">www.w3.org/.../XMLSchema-instance" xmlns:xsd="">www.w3.org/.../XMLSchema">

    " href="http://tempuri.org/type">">tempuri.org/type">

    13580603722635

    " href="http://tempuri.org/type">">tempuri.org/type">

    company

    person

    Ann

    Female

    Example

    1

    Ms.

    address

    3096 Lake Drive

    Citywest Business Park

    Dublin

    IE

    24

    phone

    Business

    20

    44

    7701076

    Fax

    20

    44

    7701077

    Test Company(13580603722635)

    1

    Import

    Active

    Prospect

  • 0

    After a long journey with SagCRM and PHP SOAP, I finally get it :)

    I think this code can be a good documentation for PHP/SageCRM integration (add record), since the scarcity of resources on the internet.

    //get WSDL client

    $options = array('trace' => true);

    $wsdl = 'crm.xxxxx.com/.../CRMwebservice.wsdl&

    $client = new SoapClient($wsdl, $options);

    //logon

    $logonParams = array('username' => 'xxxxxx', 'password' => 'xxxxxx');

    $logonResponse = $client->logon($logonParams);

    //set swap header

    $sessionId = $logonResponse->result->sessionid;

    $header = '' . $sessionId . '';

    $sessionVar = new SoapVar($header, XSD_ANYXML, null, null, null);

    $sessionHeader = new SoapHeader('http://tempuri.org/type', 'SessionHeader', $sessionVar);

    $client->__setSoapHeaders(array($sessionHeader));

    //phone data

    $phoneData = array(

    'countrycode' => '999',

    'areacode' => '99',

    'number' => '9999999',

    'type' => 'Business',

    );

    $phone = new SoapVar($phoneData, XSD_ANYTYPE, "phone", "">http://tempuri.org/type");

    //email data

    $emailData = array(

    'type' => 'Business',

    'emailaddress' => '[email protected]'

    );

    $email = new SoapVar($emailData, XSD_ANYTYPE, "email", "">http://tempuri.org/type");

    $personData = array(

    'firstname' => 'firstname',

    'lastname' => 'lastname',

    'phone' => array('entityname' => 'phone', 'records' => $phone),

    'email' => array('entityname' => 'email', 'records' => $emai),

    'companyname' => 'company',

    'country' => 'jordan',

    'title' => 'mr',

    'source' => 'web'

    );

    $person = new SoapVar($personData, SOAP_ENC_OBJECT, "person", "">http://tempuri.org/type");

    $personResponse = $client->add(array('entityname' => 'person', 'records' => $person));

    $logoffParams = array('sessionId' => $sessionId);

    $logoffResponse = $client->logoff($logoffParams);

  • 0

    Mohammed

    I am sorry you had to struggle with this but I am very glad you got it sorted in the end.

    It looks like the key is understanding that the Person, Phone and Email data needs to be added to the Company as arrays.

  • 0

    Did you get anywhere with being able to add multiselectfield data as part of adding the person record?

  • 0

    yeah, follow the example above it is a working example of adding a person record with multiselectfields like phone and address.

  • 0

    Hmm. Tried that. Multiselects are abstract fields rather than standard field (like email/phone/address) - they don't have an entityname?

    have you got a working example?

  • 0

    Actually, I am not sure regarding the multiselectfields thing, but email, address,... are not standard fields since they stored like separated entities or sub entities.

  • 0

    * standard objects, sorry.

    Web Services Guide Chapter 5

    Thanks for the input anyway... :)