PHP: Cannot pass datatype Long (> 2147483647) in SOAP requests

It looks like the IDs with datatype Long are somehow getting corrupted before or while you are making the SOAP request.

I had experience this issue while working with the Adwords API v200909. Its using the PHP5's native SOAP class. I had created a new Adgroup in the Sandbox and while I am updating it, I am getting the following error message.

SoapFault Object ( [message:protected] => [EntityNotFound.INVALID_ID @ operations[0].operand.adGroupId; trigger:'AdGroupId: 2147483647']

The adGroupId was '3121452289'.

I have found that this is the problem with PHP,

The PHP language does not support the 64 bit long data type. The
maximum integer value in PHP is 2147483647. This limitation can cause
PHP applications to generate bad requests if the ID element is larger
than 2147483647.

$AdgroupId = "9999999999999"; // BAD. Generates request with AdGroupId 2147483647

I got two options to fix this:

1. $AdgroupId = (float) "9999999999999"; // SAFE - If ID represented as a string variable


2. $AdgroupId = 9999999999999; // Safe - If ID represented as a numeric variable

1 comment: