GetResponse-PHP-Wrapper
GetResponse-PHP-Wrapper copied to clipboard
Multiple customs in set_contact_customs
Hi,
in set_contact_customs method, support for multivalue customs is missing. I googled a lot but I can't figure it out how to set multivalue custom. On official getreponse api doc, there is no example how to use it. I tried separators (; and ,), array but nothing worked. Is it possible to send example how to set multivalue customs? Thanks
I'll ask GetResponse about it. We may have to wait for version 3 of the API, which is currently only in beta: http://apidocs.getresponse.com/en/v3/resources/customfields#customfields.update
I asked GetResponse allready and here is the answer (easy, but it is little bit confusing I think ):
'customs' => array( array( 'name' => 'name_of_your_multivalue_custom', 'content' => 'value1' ), array( 'name' => 'name_of_your_multivalue_custom', 'content' => 'value2' ), array( 'name' => 'name_of_your_multivalue_custom', 'content' => 'value3' ), ),
Great! So using the PHP Wrapper might look something like this, then:
$multivalues = array( 'name_of_your_multivalue_custom' => 'value1', 'name_of_your_multivalue_custom' => 'value2', 'name_of_your_multivalue_custom' => 'value3' ); $setCustoms = $api->setContactCustoms($contactID, $multivalues);
It is not possible to write it like that, this would be right solution: $multivalues = array( 'name_of_your_multivalue_custom' => array('value1', 'value2', 'value3'), 'name_of_your_other_custom' => 'XY', ); $setCustoms = $api->setContactCustoms($contactID, $multivalues);
// function setContactCustoms($id, $customs) { if (!is_array($customs)) trigger_error('Second argument must be an array', E_USER_ERROR); foreach($customs as $key => $val) { if (is_array($val)) { foreach($val as $val2) { $params[] = array( 'name' => $key, 'content' => $val2 ); } } else { $params[] = array( 'name' => $key, 'content' => $val ); } } //.... }