ActiveCampaign / activecampaign-api-php

MIT License
115 stars 76 forks source link

Adding custom fields with add contact api #53

Closed elieandraos closed 8 years ago

elieandraos commented 8 years ago

I am trying to add custom fields to the contact like in described in the api: http://www.activecampaign.com/api/example.php?call=contact_add

// ...
'field[345,0]'           => 'field value',

the response error is the following:

There was an error processing custom field 345. Try encoding each 'field[]' parameter
pevans commented 8 years ago

Hmm... the form is correct, supposing that you have a custom field with the id that you are passing in. Could you submit a ticket through the help section in your account with some form of the code you're using to make the API call?

Thanks!

elieandraos commented 8 years ago

Sure. Will do.

nathanwaters commented 7 years ago

Getting the same issue with custom fields using personalization tags, eg field[%CITY%,0]. What's the fix?

Edit: Fixed. I'm guessing the wrapper doesn't process multiple tags. Had to split the field parameter into a separate array like so:

  $contact = array(
    'p[1]'                   => 1,
    'status[1]'              => 1,
    'email'                    => 'john@doe',
      'first_name'               => 'John',
      'last_name'                => 'Doe'
    );
  $contact['field'] = array(
    '%CITY%,0'      => 'city',
    '%STATE%,0'      => 'state',
    '%POSTCODE%,0'      => 'postcode'
  );
nickrouty commented 6 years ago

@nathanwaters I know this was awhile ago... but you da' man. Thanks for adding that solution in there. The docs/examples aren't clear on it at all.

msavvy commented 6 years ago

It seems that i'm having some issues with the api. I have the following:

`$url = $credentials['api_url'];

    $params = array(
      'api_key' => $credentials['api_key'],
      'api_action' => $api_action,
      'api_output' => 'serialize',
    );

    $list = 'p[' . $credentials['list_id'] . ']';
    $status = 'status[' . $credentials['list_id'] . ']';

    $token = filter_xss($token);

    if($api_action == 'contact_add') {
      $post = array(
        'email' => $email,
        'first_name' => $firstname,
        'last_name' => $lastname,
        'tags' => $tags,
        $list => $credentials['list_id'],
        $status => 1,
      );

      $post['field'] = array(
        '%TOKEN%,0' => $token,
        '%SAVVYREDIRECTURL%,0' => $redirect_url,
        '%PHONE%,0' => '131234',
      );
    }
    elseif($api_action == 'contact_edit') {

      $post = array(
        'id' => $contact_id,
        'first_name' => $firstname,
        'last_name' => $lastname,
        $list => $credentials['list_id'],
      );

      $post['field'] = array(
        '%TOKEN%,0' => $token,
        '%SAVVYREDIRECTURL%,0' => $redirect_url,
        '%PHONE%,0' => '131234',
      );
    }`

what it did is it just saves the token, but not the customurl and the phone fields.

may i please ask what's wrong or what's missing? thanks.

bartboy011 commented 6 years ago

@msavvy On which of those is that happening? Or is it both?

Also, are you using this wrapper? I ask because if so, you wouldn't need api_key nor api_action params since the wrapper handles those for you. If you aren't using the wrapper, then that's your issue, you'd need to look at the documentation on making an API call without the wrapper which can be found here - https://www.activecampaign.com/api/example.php?call=contact_add

Nikitapcrafter commented 2 years ago

I am trying to fetch custom field data from deals. so please suggest any API fo this.