I am currently working with various Google APIs. I already have approved access to the Google Business API and am successfully making several calls to its endpoints with the PHP SDK; even calls to some of the endpoints in the Business Verification API. However, when I make a request to fetchVerificationOptions of a defined location, I get a 400 error.
Google\Service\Exception
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"errors": [
{
"message": "Request contains an invalid argument.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest"
}
]
}
}
I have verified the location being passed in is correct and in the format of "locations/<LOCATION_ID>". I am using this same key in many other successful calls.
I've read all the documentation I can find on this subject many many times. The error makes me think the data I am sending in is wrong, but the documentation is pretty clear on what is expected - a language code and, optionally, a context. In my current case, the location is a CUSTOMER_LOCATION_ONLY type of business and requires a PostalAddress object be provided in this request via the context. The SDK makes this seem even easier with objects for each piece of the puzzle.
Here is my relevant PHP code:
$options = new FetchVerificationOptionsRequest;
$options->languageCode = 'en-US';
$context = new ServiceBusinessContext;
$context->setAddress($postalAddress);
$options->setContext($context);
$verificationOptions = GoogleBusinessProfileApi::getVerificationService()->locations->fetchVerificationOptions($locationName, $options);
I have verified that $postalAddress
in the code above is an instance of Google\Service\MyBusinessVerifications\PostalAddress
holding valid address details.
I have verified that $locationName
in the code above holds the correct value; my location ID in the format of "locations/<LOCATION_ID>".
GoogleBusinessProfileApi::getVerificationService()
in the code above returns an instance of Google\Service\MyBusinessVerifications
with my Google Client and all the authentication stuff taken care of. I use this method for all of my interactions and they work perfectly normal. Plus, the error doesn't indicate there is an issue with this part.
It is also worth noting that on my Google API Dev Console, I can see these requests coming in and ending with a 400 response. Though, that is as far as the metrics seem to go. I cannot find any deeper, more detailed information about the requests.
I am looking for anything - direction, ideas, thoughts. Anyone else deal with this before? Am I missing something obvious? Is this an issue with my code or the API itself? Anyone know how I can dig deeper on the Google console for these errors?
Thanks!
The Solution:
Set PostalAddress sublocality to null.
The Details:
With the help of a colleague, we figured out what was going on. I changed the code to call the older, deprecated version of the API. This returned a much more useful error message stating that the US doesn't use sublocalities in their addresses. I was setting that on my PostalAddress object, so I changed it to always be null and the request worked - on both the old and new API.
There were a lot of frustrating points around this problem.
While this doesn't seem to be a big issue on the web right now, I do hope that this can help someone else avoid some wasted time someday.
~Cheers~