I’ve been using the PHP SDK to interact with the API, and I have managed to successfully create contacts and include a couple of custom fields. I’m not trying to add a tag to the contacts as I create them so trigger a campaign. However, I have tried many different formats but with no success. The best thing I’ve been able to get so far is a message: “Tags can’t be added or removed through this object”.
I have created a new contact tag, which has an id of 103.
Here is a screenshot of the array from my request. Note: It works perfectly fine if I remove the tag_ids.
So, how can I successfully add tags while creating a new contact? The field is there in the documentation, so I assume it’s possible.
Thanks,
1 Like
If you’re using the SDK with that request then you’ve got two different API’s mixed together. The SDK uses the PHP wrapper but does NOT involve JSON. The JSON record you’re showing is only used with the REST API.
@John_Borelli - Can you help me understand this better? I thought I was using the REST API through the PHP SDK (as evidenced by my conversation with one of the developers in this ticket: Call to undefined method Infusionsoft\Api\Rest\ContactService::add() · Issue #136 · infusionsoft/infusionsoft-php · GitHub).
Also, the screenshot I showed above is not JSON. It’s a PHP array I’m passing into the request.
Ok, so like most things…let’s try starting at the beginning. Post the source in question otherwise we’ll continue to get tripped up by words.
@John_Borelli - Ok. Here’s the code. Assume that I’ve already setup my $infusionsoft object correctly - token is good, and that the fields I’m pulling from are valid data. I’ve already tested all of that and it’s correct. Again, it works completely fine if I just remove the tag_ids from the array.
$contact = array(
'email_addresses' => array(
array(
'email' => $data['preparer']['email'],
'field' => 'EMAIL1'
)
),
'given_name' => $data['preparer']['first_name'],
'family_name' => $data['preparer']['last_name'],
'company' => array(
'company_name' => $data['preparer']['org_name']
),
'addresses' => array(
array(
'field' => 'BILLING',
'line1' => $data['preparer']['mailing_street'],
'line2' => $data['preparer']['mailing_second'],
'locality' => $data['preparer']['mailing_city'],
'postal_code' => $data['preparer']['mailing_zip'],
'region' => "US-".$data['preparer']['mailing_st_abbr'],
'country_code' => 'USA'
)
),
'custom_fields' => array(
array(
'id' => 4, // 4 = Form Edit Url
'content' => $data['edit_link']
),
array(
'id' => 2, // 4 = Trustpilot review url
'content' => $inviteUrl
)
),
'tag_ids' => [103] // 'sendProductReview' contact tag
);
$infusionsoft->contacts()->create($contact);
Also, I’ve tried all of the following formats for tag_ids, and none of worked:
'tag_ids' => [103]
'tag_ids' => array(103)
'tag_ids' => array(array(103))
'tag_ids' => 103
Hi @Jer_Fortenberry. I’m sorry for the confusion but tags cannot be applied when creating a new contact record, they must be applied as a separate API call. The tag_ids
property that appears on the contact record is read only which is why you’re receiving the error message “Tags can’t be added or removed through this object”.
1 Like
@Nicholas_Trecina - Thank you for the more definitive info on this. Is there a reason that the API documentation doesn’t seem to make this clear? Is there a key to reading the documentation that I’m missing?
@Jer_Fortenberry @John_Borelli The PHP SDK uses both the XML-RPC and the REST APIs. For more detail see the README.md.
@Jer_Fortenberry There isn’t a reason why the documentation can’t make this more clear. I will file a ticket for us to get this fixed.
2 Likes
Years later… human life is still being lost.
- time I will want back on my deathbed.
- time that needs to be explained to clients.
- time that turns into lost wages.
It looks like the documentation has been updated now