Api add multiple tags

Hi there,

I have some problems in adding multiple tag via api ( trough add new contact or add new tag ).

I think i have wrong input so if someone can fill one sample of right input.

When I post like in sample, only one tag is passed in contact tag list
sample:

$post = array(
    'email' => 'test@test.com', // contact email address (pass this OR the contact ID)
    // or multiple tags?
    tags[]' => 'tag1-sample',
   'tags[]' => 'tag2-sample',
  'tags[]' => 'tag3-sample',
);

Thank you

The code example in the documentation, that you are referring to, is bad PHP. You need to actually make the tags element an array and pass in each tag you want to use.

Pass a string (for one tag) or an array (for multiple tags).

Documentation: API Examples Using contact_tag_add

Code Example:

$post = array(
    'email' => 'test@test.com',
    'tags' => Array('tag1-sample','tag2-sample','tag3-sample')
);
1 Like

I managed to figure this out based on the way list work.
You need to number your tags and not use empty brackets.
Not Like This
$post = array(
‘email’ => $contactData[5],
‘tags[]’ => $contactData[7],
‘tags[]’ => $contactData[8],
);

Instead Do This:
$post = array(
‘email’ => $contactData[5],
‘tags[1]’ => $contactData[7],
‘tags[2]’ => $contactData[8],
);

Hey all,

Biannca here from our CX team. I just wanted to update this thread for anyone that comes across this - we’ve updated our API to v3 and if you want to add multiple tags via API through PHP, you should be inserting something along the lines of:

**$response = $client->request('POST', 'https://youraccountname.api-us1.com/api/3/contactTags', [
  'body' => '{"contactTag":{"contact":1,"tag":20}}',
  'headers' => [
    'accept' => 'application/json',
    'content-type' => 'application/json',**

Documentation:
https://developers.activecampaign.com/reference/create-contact-tag

Please don’t hesitate to reply back out or email us at help@activecampaign.com if you have any further questions.