How do you apply tags using the Infusionsoft PHP SDK

Hello,

How does one attach a tag to a contact using the Infusionsoft PHP SDK?

I haven’t been able to figure it out, but I do know there is an endpoint for it https://developer.infusionsoft.com/docs/rest/#!/Tags/applyTagToContactIdsUsingPOST

I already have the Tag_id + the contact_id so any additional assistance would be very appreciated.

That’s a rest endpoint but the sdk has wrapper functions and the legacy has the xml-rpc method grpAssign(). Using the current sdk you would use the contact objects method addToGroup. So what you’ve listed a link to is the rest implementation. The sdk implementation is

https://developer.infusionsoft.com/docs/xml-rpc/#contact-add-a-tag-to-a-contact

Ah thank you!

That was exactly what I needed.

Hello again, thought I’d add this to this ticket, as its a follow up

I’m getting an error when i attempt to access the addToGroup()

Fatal error: Uncaught Error: Call to undefined method Infusionsoft\Api\Rest\ContactService::addToGroup() in /srv/bindings/205bfae7fd4b4136b6b8fd4af791de3a/code/wp-content/themes/sovereign-silver/functions.php:1406 Stack trace: #0 /srv/bindings/205bfae7fd4b4136b6b8fd4af791de3a/code/wp-includes/rest-api/class-wp-rest-server.php(936): rest_api_order_products(Object(WP_REST_Request)) #1 /srv/bindings/205bfae7fd4b4136b6b8fd4af791de3a/code/wp-includes/rest-api/class-wp-rest-server.php(321): WP_REST_Server->dispatch(Object(WP_REST_Request)) #2 /srv/bindings/205bfae7fd4b4136b6b8fd4af791de3a/code/wp-includes/rest-api.php(266): WP_REST_Server->serve_request('/Component/v1/o...') #3 /srv/bindings/205bfae7fd4b4136b6b8fd4af791de3a/code/wp-includes/class-wp-hook.php(286): rest_api_loaded(Object(WP)) #4 /srv/bindings/205bfae7fd4b4136b6b8fd4af791de3a/code/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #5 /srv/bindings/205bfae7fd4b4136b6b8fd4af791de3a/code/wp-includes/plugin.php(515): WP_Hook->do_action(Array) #6 in /srv/bindings/205bfae7fd4b4136b6b8fd4af791de3a/code/wp-content/themes/sovereign-silver/functions.php on line 1406

I should have the api properly setup as I create a contact first (which works)
example
$infusionsoft->contacts()->addToGroup($id, $tag_id);
Please advice.

Hi @Darlene_Nicholson,

That error almost always means that the parameter list doesn’t match but in this case it looks like you’re trying to call REST as a local endpoint on a Wordpress site? I could be missing something there so the only thing that might clarify is if you share the actual code that you are implementing and describe how you’re implementing it. I’d say you have a function in functions.php that is reporting the error? Also, if you’re using the sdk which uses xml-rpc then the message is referencing REST so which is it you’re actually using?

Hi @Darlene_Nicholson, I would recommend applying a tag to a contact using the REST endpoint rather than XML-RPC like this: $infusionsoft->contacts()->find($id)->addTags([$tag_id]);