Failed to invoke method addToGroup on new contact

Hi,
I’m using PHP SDK with OAuth. I’ve had to mix regular requests with XML including in addToGroup.

I’m running into an issue where I get the above error when trying to add tags on a contact I’ve just created. It works perfectly fine on an existing contact. When I step through and pause after adding the contact, but before the tags get added, I can see the contact properly in InfusionSoft in the browser, minus the tags of course, but then continuing still gives the error.

I’ve had it sleep in case it was going too fast, but that didn’t seem to make a difference.

Here is the stack:

Fatal error: Uncaught fXmlRpc\Exception\FaultException: Failed to invoke method addToGroup in class com.infusionsoft.api.xmlrpc.XmlRpcContactService: For input string: "" in C:\Apache24\htdocs\Keap\vendor\infusionsoft\php-sdk\src\Infusionsoft\Http\InfusionsoftSerializer.php on line 34
( ! ) Infusionsoft\Http\HttpException: Failed to invoke method addToGroup in class com.infusionsoft.api.xmlrpc.XmlRpcContactService: For input string: "" in C:\Apache24\htdocs\Keap\vendor\infusionsoft\php-sdk\src\Infusionsoft\Http\InfusionsoftSerializer.php on line 34
Call Stack
#	Time	Memory	Function	Location
1	0.1754	409896	{main}( )	...\index.php:0
2	0.9455	1271808	IS->addOrders( )	...\index.php:39
3	10.2315	2953496	IS->buildContactFromNew( )	...\IS.php:193
4	10.8192	2963976	IS->addTags( )	...\IS.php:162
5	15.0939	2963976	Infusionsoft\Api\ContactService->addToGroup( )	...\IS.php:222
6	15.0939	2963976	Infusionsoft\Infusionsoft->request( )	...\ContactService.php:43
7	15.0939	2971896	Infusionsoft\Http\InfusionsoftSerializer->request( )	...\Infusionsoft.php:456

Here is my code calling this, but again, it works perfectly fine if the contact already exists:

foreach ($arrayOfTags as $tag) {
        $this->infusionsoft->contacts('xml')->addToGroup($cid,$tag);
}

$cid is valid, as is each $tag.

What is going on here and how can I get around it?
Thanks,

Update: I’m an idiot

I’m going to blame this on being sick, but of course this was due to the ID being blank. I wasn’t getting it from the return of adding the contact. I’ll leave this here for future reference for someone who made the same mistake.