Getresponse API 2 (Adding Custom fields and contacts using PHP) -


im new coding , web development , diving deep end api's thing wish never had done! being said have progressed further expected. having problems when trying add custom fields add contact feature. im trying code add hidden form input fields when user hits thankyou page. dont want use getresponses own form builder main page better use api. have code running when comes adding contact when add set_contact_customs code not execute , fails following error: (request have return error: array) understand set_contact_customs array im clueless have done wrong.. advice , appreciated still learning basics picking on experts great learning curve. thanks.

--- below working version without set_contact_customs ----

<?php // add contact selected campaign id try{ $result_contact = $client->add_contact( $api_key, array ( 'campaign' => 'my-camp-id', 'name' => $fullname, 'email' => $emailaddress ) );  echo "<p style='color: blue; font-size:24px;'>no errors, contact , custom fields have been added...</p>"; }  catch (exception $e) {  echo $e->getmessage(); }  ?> 

--- here code causes problems (with set_contact_customs) ----

    <?php // add contact selected campaign id try{ $result_contact = $client->add_contact( $api_key, array ( 'campaign' => 'my-camp-id', 'name' => $fullname, 'email' => $emailaddress ) ); $result_contact = $client->set_contact_customs(         $api_key,             array(                 'survey type' => $surveytype,                 'survey cost' => $surveycost                 ) ); echo "<p style='color: blue; font-size:24px;'> contact added </p>"; }  catch (exception $e) {  echo $e->getmessage(); }  ?> 

  1. api 2 doesn't exist: in getresponse they say version "1.5.0 - last json/rpc version of our api", if speaking 10 months ago. preparing beta-test v3. assume speaking 1.5 , answer (i'm not familiar v3, maybe there it's different).

  2. you must send contact id set_contact_customs, , didn't.

  3. when says, "request error: array", doesn't relate array (even though problem in array, because don't send in contact id), sending array response error messages.

  4. i'd love tell you, contact id in order send it, i'm looking myself now. :)

update:

ok, combined pieces on internet, , here's working format.

  1. you don't need add_contact , update it, can in 1 go, adding 'customs' parameter add_contact call (gr say, shouldn't expect contact added immediately, might not whom update, if call function right away).

    the fields add_contact described here.

  2. the 'customs' parameter should differently. instead of:

    array(     'survey type' => $surveytype,     'survey cost' => $surveycost     ) 

    it should be:

    array(     array( 'name' => 'survey type', 'content' => $surveytype ),     array( 'name' => 'survey cost', 'content' => $surveycost )     ) 

    by way, tested, - blessedly, don't need define in gr ui custom fields first, whatever send, added or updated (in limits custom field names , values).

    i got error, when tried send 1 custom field empty content, when calling add_contact. when sent set_contact_customs, didn't error; wanted see, if delete field or field value - didn't thing.

  3. if still wish update existing contact, here's how send contact id update call:

    $result = $client->set_contact_customs(    $api_key, array(       'contact' => $contact_id,       'customs' => $custom_fields_array     ) ); 
  4. to first find contact id, should call get_contacts. , since it's been said (i haven't tested it), in different campaigns contacts same email address have different contact id, should pass both campaign, , email it.

    as can see, campaign can sent in 'campaigns' parameter (then campaign id, got add_contact, should used), or in 'get_campaigns' (then campaign name or prefix can used).

    here's call campaign id, code:

    $result = $client->get_contacts(     $api_key, array(        'campaigns' => array( 'my-camp-id' ),        'email' => array( 'equals' => $emailaddress )     ) ); 
  5. to retrieve contact id get_contacts, same recommended retrieving campaign id:

    $contact_id = array_pop( array_keys( $result ) ); if ( empty( $contact_id ) ) {     //still not ok } else {     //you can call set_contact_customs } 
  6. in order error message more descriptive, instead of 'request have return error: array', open jsonrpcclient.php, surely include in file these gr function calls, , following line:

    !is_null($response['error']) => 'request have return error: ' . $response['error'], 

    and replace following, @ least:

    !is_null($response['error']) => 'request have returned error: ' . var_export($response['error'], true), 

    now code use beloved var_export function , if make mistake, see in error log like:

    request have returned error: array (   'message' => 'invalid params',   'code' => -32602, ) 

i dedicate thorough answer those, helped me endlessly here on stackoverflow, giving answers else's questions, years ago. thank you! answer save time, efforts, , mood, too. :)


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -