Sergiu Z Sergiu Z - 3 days ago 4
PHP Question

How do I create a PHP array for a SOAP call?

Here's the SOAP function:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="http://domain.com/" xmlns:sen="http:/domain.com">
<soapenv:Header/>
<soapenv:Body>
<v2:actionContactsGroup>
<sen:pInfo>
<sen:ActionType>?</sen:ActionType>
<sen:GroupName>?</sen:GroupName>
<!--Optional:-->
<sen:ContactIdsList>
<!--1 or more repetitions:-->
<sen:Id>?</sen:Id>
</sen:ContactIdsList>
</sen:pInfo>
</v2:actionContactsGroup>
</soapenv:Body>
</soapenv:Envelope>


If I send over this XML code it works just fine:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="http://domain.com" xmlns:sen="http://domain.com">
<soapenv:Header/>
<soapenv:Body>
<v2:actionContactsGroup>
<sen:pInfo>
<sen:ActionType>Add</sen:ActionType>
<sen:GroupName>MyGroup</sen:GroupName>
<sen:ContactIdsList>
<sen:Id>SomeID1</sen:Id>
<sen:Id>SomeID2</sen:Id>
<sen:Id>SomeID3</sen:Id>
</sen:ContactIdsList>
</sen:pInfo>
</v2:actionContactsGroup>
</soapenv:Body>
</soapenv:Envelope>


But I'm unable to do the same in php. I can do it with one id at a time:

$addToGroup = array(
'pInfo'=>array(
'ActionType'=>'Add',
'GroupName'=>'MyGroup',
'ContactIdsList'=>array('Id'=>'SomeID1')
)
);


But if I try multiple ids it doesn't work no matter how I format the array. Ideas?

I tried this but didn't work:

// didnt work, came back saying "Warning: Contact not found
// [Array]WarningDuplicated contact. Only first instance was used."
$addToGroup = array(
'pInfo'=>array(
'ActionType'=>'Add',
'GroupName'=>'NCAL_SUW',
'ContactIdsList'=>array(
array('Id'=>'SomeID1'),
array('Id'=>'SomeID2')
)
)
)

Answer

I finally figured it out: the array to send out apparently doesn't need to mention the "Id" element. Directly posting a list of ids is enough. So, I ended up using the array below. Why I don't need to mention the "Id" element in my array is beyond me but apparently the soap client takes care of it by itself.

$addToGroup = array(
    'pInfo'=>array(
        'ActionType'=>'Add',
        'GroupName'=>'NCAL_SUW',
        'ContactIdsList'=>array(
            'SomeID1',
            'SomeID2'
        )
    )
)
Comments