GetResponse-PHP-Wrapper icon indicating copy to clipboard operation
GetResponse-PHP-Wrapper copied to clipboard

Multiple customs in set_contact_customs

Open publicfun opened this issue 9 years ago • 4 comments

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

publicfun avatar May 15 '15 12:05 publicfun

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

robertstaddon avatar May 16 '15 19:05 robertstaddon

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' ), ),

publicfun avatar May 17 '15 15:05 publicfun

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);

robertstaddon avatar May 20 '15 16:05 robertstaddon

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 ); } } //.... }

publicfun avatar May 20 '15 18:05 publicfun