AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

My Business
4.5K members online now
4.5K members online now
For developers who are using the Google My Business API to manage locations
Guide Me
star_border
Reply

400 - "Request contains an invalid argument" on patch request

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi,

 

I have problem after migrating to v3 api. I get location from API with "get" request and it works fine. But when i want to do "patch" request to update location I get:

 

{
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "errors": [
      {
        "message": "Request contains an invalid argument.",
        "domain": "global",
        "reason": "badRequest"
      }
    ],
    "status": "INVALID_ARGUMENT"
  }
}

I'm setting location name as first parameter on "patch" request (same as when executing "get" request when it works fine). Second is instance of Google_Service_Mybusiness_Location. Third is array with optional parameters when I have something like this:

 

 

$optParams = [
  'languageCode' => 'pl-PL',
  'validateOnly' => false,
  'fieldMask' => 'primaryPhone',
];

The only change (for test) i make is phone number update:

$location->setPrimaryPhone(PHONE_NUMBER);

And now something I don't understand. I have tested this through OAuth 2.0 Playground. I do "get" request to get one location data and copy json with result. Then I switch to "patch" request, paste json in request body, put location uri in request URI field with "?languageCode=pl-PL" and everything works fine - I get 200 on response.

 

1 Expert replyverified_user

Re: 400 - "Request contains an invalid argument" on patch request

Google Employee
# 2
Google Employee

Hi @McDonalds I,

 

I don’t have enough information from you to troubleshoot this issue you posted. Please post the full PATCH request including the query parameters and request body you used for OAuth 2.0 Playground as well as your source code for updating the primaryPhone field of the specified location with the PHP client library.

 

Please make sure you omit the read-only name field of a Location object when creating or updating a location via the API.

 

Another issue that may be related to your problem is the 400 Bad Request error due to an invalid JSON payload when sending a PATCH request to update the specified location with the PHP client library. A workaround for this issue is to create a new Location object for a location update using the PHP client library.

 

The following is a code snippet for avoiding the 400 Bad Request error when updating the primaryPhone field of the specified location with the PHP client library:

 $name = $location->name;

 $location = new Google_Service_Mybusiness_Location();

 $location->primaryPhone = "(201) 555-5555";

 

 try {

   $updatedlocation = $locations->patch($name, $location, array('languageCode' => 'en', 'fieldMask' => 'primaryPhone', 'validateOnly' => FALSE));

 } catch (Exception $e) {

   print "Caught exception: " . $e->getMessage() . "\n";

 }

 

Thanks,

Terry