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

Patch Location 500 Internal Server Error

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

Hello,

I am receiving an error when patching a location as follows:

POST https://mybusiness.googleapis.com/v3/accounts/111082343647321204004/locations/204434037610004575?fieldMask=serviceArea.businessType

Headers:

accept-encoding=[gzip]
user-agent=[Google-API-Java-Client]
x-http-method-override=PATCH
x-goog-api-format-version=2

Body:

{
"serviceArea" : {
"businessType" : "CUSTOMER_LOCATION_ONLY"
}
}

The error is a 500 Internal Server Error:

{
  "code" : 500,
  "message" : "Internal error encountered.",
  "status" : "INTERNAL"
}

Can you please explain why this error is occurring and why no details are provided?

Thanks!

 

2 Expert replyverified_user

Re: Patch Location 500 Internal Server Error

Google Employee
# 2
Google Employee

Hi @Marcus G,

 

Judging from the source code you provided, we suggest you please include the languageCode and validateOnly parameters in URL while sending a PATCH request for updating a location to avoid 500 Internal Server Error.

 

Thanks,

The Google My Business API team

Re: Patch Location 500 Internal Server Error

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Thanks Shalini,

 

I have added these parameters as you recommended, but am still receiving the same error:

POST https://mybusiness.googleapis.com/v3/accounts/111082343647321204004/locations/204434037610004575?fieldMask=serviceArea.businessType&languageCode=en&validateOnly=false

Error response:

{
  "code" : 500,
  "message" : "Internal error encountered.",
  "status" : "INTERNAL"
}

Can you investigate further please?  Thank you!

Re: Patch Location 500 Internal Server Error

Google Employee
# 4
Google Employee

Hi @Marcus G,

 

As far as I’m concerned, you should only provide the ServiceAreaBusiness object for an update in a PATCH request. You should receive a 500 Internal Server Error if you insert the ServiceAreaBusiness object for creation in a POST request. We will update you in this thread when the issue about the 500 Internal Server Error for including the ServiceAreaBusiness object in a POST request to create a new location has been resolved.

 

Thanks,

Terry

Patch Location 500 Internal Server Error

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

Hi Terry,

Thanks for your reply.  I am indeed attempting a PATCH request, as shown in my original post.  I mistakenly omitted the x-http-method-override=PATCH header from my second example, but it does produce the same 500 Internal Server Error as noted above.

Re: Patch Location 500 Internal Server Error

Google Employee
# 6
Google Employee

Hi @Marcus G,

 

Your URI tells me your are sending a POST request to create a new location:

POST https://mybusiness.googleapis.com/v3/accounts/111082343647321204004/locations/204434037610004575?fieldMask=serviceArea.businessType&languageCode=en&validateOnly=false

 

Try putting the correct URI for a PATCH request to update the specified location instead of using the header:

PATCH https://mybusiness.googleapis.com/v3/accounts/111082343647321204004/locations/204434037610004575?fieldMask=serviceArea.businessType&languageCode=en&validateOnly=false

 

Thanks,

Terry

Re: Patch Location 500 Internal Server Error

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭

Hi Terry,

I am using the v3.1 Java client, here is the relevant code snippet:

    public static Location patch(Credential credential) throws IOException {
        Location location = new Location();
        ServiceAreaBusiness serviceArea = new ServiceAreaBusiness();
        serviceArea.setBusinessType("CUSTOMER_LOCATION_ONLY");
        location.setServiceArea(serviceArea);

        Mybusiness gmb = new Mybusiness.Builder(new NetHttpTransport(), new JacksonFactory(), credential).build();
        Mybusiness.Accounts.Locations.Patch patch = gmb.accounts().locations()
                .patch("accounts/111082343647321204004/locations/204434037610004575", location)
                .setLanguageCode("en")
                .setFieldMask("serviceArea.businessType")
                .setValidateOnly(false);
        patch.getRequestHeaders().set("X-GOOG-API-FORMAT-VERSION", 2);

        HttpRequest request = patch.buildHttpRequest();
        System.out.println(String.format("request=%s %s", request.getRequestMethod(), request.getUrl()));
        System.out.println(String.format("headers=%s", request.getHeaders()));
        System.out.println(String.format("location=%s", location.toPrettyString()));

        try {
            return patch.execute();
        } catch (GoogleJsonResponseException exception) {
            System.err.println(String.format("exception=%s", exception));
        }
        return null;
    }

The output of running this method with the proper Credential is as follows:

request=POST https://mybusiness.googleapis.com/v3/accounts/111082343647321204004/locations/204434037610004575?fieldMask=serviceArea.businessType&languageCode=en&validateOnly=false
headers={accept-encoding=[gzip], user-agent=[Google-API-Java-Client], x-http-method-override=PATCH, x-goog-api-format-version=2}
location={serviceArea={businessType=CUSTOMER_LOCATION_ONLY}}
exception=com.google.api.client.googleapis.json.GoogleJsonResponseException: 500 Internal Server Error
{
  "code" : 500,
  "message" : "Internal error encountered.",
  "status" : "INTERNAL"
}

Interestingly, if I call setValidateOnly(true) then the patch succeeds and returns the expected location values.  It's only when I actually try to update the location with setValidateOnly(false) that I get the cryptic error.

Re: Patch Location 500 Internal Server Error

[ Edited ]
Google Employee
# 8
Google Employee

Hi @Marcus G,

 

Try providing a complete ServiceAreaBusiness object and changing the fieldMask to “serviceArea” to see if it fixes the issue. Apparently, if your location doesn’t already have a ServiceAreaBusiness object, you should trigger a 500 Internal Server Error with the "serviceArea.businessType" fieldMask in a PATCH request when using the Java client library, and the following 400 Bad Request error when using OAuth 2.0 Playground:

 

{
 "error": {
   "status": "INVALID_ARGUMENT",
   "message": "Request contains an invalid argument.",
   "code": 400,
   "details": [
     {
       "errorDetails": [
         {
           "field": "service_area",
           "message": "service_area is required",
           "code": 2
         }
       ],
       "@type": "type.googleapis.com/google.mybusiness.v3p1.ValidationError"
     }
   ]
 }
}

 

In addition, if your location doesn’t have an associated Google+ page, you can’t see the edited service area for your business in the UI.

 

Thanks,

Terry

Re: Patch Location 500 Internal Server Error

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭

Hi Terry,

This particular location already has a serviceArea defined, so it's unclear to me why updating the businessType fails.  I did try your suggestion of sending the entire serviceArea object, which resulted in a new exception.  Here's the full code and its results:

 

    public static Location getAndPatchServiceArea(Credential credential) throws IOException {
        final String locationName = "accounts/111082343647321204004/locations/204434037610004575";
        Mybusiness gmb = new Mybusiness.Builder(new NetHttpTransport(), new JacksonFactory(), credential).build();

        Mybusiness.Accounts.Locations.Get get = gmb.accounts().locations().get(locationName);
        ServiceAreaBusiness serviceArea = get.execute().getServiceArea();

        Location location = new Location();
        location.setServiceArea(serviceArea);

        Mybusiness.Accounts.Locations.Patch patch = gmb.accounts().locations()
                .patch(locationName, location)
                .setLanguageCode("en")
                .setFieldMask("serviceArea")
                .setValidateOnly(false);
        patch.getRequestHeaders().set("X-GOOG-API-FORMAT-VERSION", 2);

        HttpRequest request = patch.buildHttpRequest();
        System.out.println(String.format("request=%s %s", request.getRequestMethod(), request.getUrl()));
        System.out.println(String.format("headers=%s", request.getHeaders()));
        System.out.println(String.format("location=%s", location.toPrettyString()));

        try {
            return patch.execute();
        } catch (GoogleJsonResponseException exception) {
            System.err.println(String.format("exception=%s", exception));
        }
        return null;
    }

The output is:

request=POST https://mybusiness.googleapis.com/v3/accounts/111082343647321204004/locations/204434037610004575?fieldMask=serviceArea&languageCode=en&validateOnly=false
headers={accept-encoding=[gzip], user-agent=[Google-API-Java-Client], x-http-method-override=PATCH, x-goog-api-format-version=2}
location={serviceArea={"businessType":"CUSTOMER_AND_BUSINESS_LOCATION","places":{"placeInfos":[{"name":"Las Vegas, Nevada 89107","placeId":"ChIJE_h1YnTByIARBz0cGYV-GY4"},{"name":"Las Vegas, Nevada 89108","placeId":"ChIJGz8pdPXqyIARRZcUA1sOco4"},{"name":"Las Vegas, Nevada 89128","placeId":"ChIJtyczTRjAyIARXvU2Mb7woWI"},{"name":"Las Vegas, Nevada 89129","placeId":"ChIJS_GXqH-TyIARZMhnSHDKVCM"},{"name":"Las Vegas, Nevada 89130","placeId":"ChIJW1H9g1vqyIARwSSaIlQ9QcQ"},{"name":"Las Vegas, Nevada 89131","placeId":"ChIJl7vmr7LryIAR_q55Gz_F1oQ"},{"name":"Las Vegas, Nevada 89134","placeId":"ChIJAcUP2GCVyIARMb9KmQ3ftKw"},{"name":"Las Vegas, Nevada 89138","placeId":"ChIJia0XHDy-yIARCN_51GXLqB4"},{"name":"Las Vegas, Nevada 89144","placeId":"ChIJNarpWcS_yIARz80l5OVwnM4"},{"name":"Las Vegas, Nevada 89145","placeId":"ChIJMQxeD3jAyIARog5XGELql6s"},{"name":"Las Vegas, Nevada 89149","placeId":"ChIJP20GwliTyIARN6fzhVCzeRk"},{"name":"Las Vegas, Nevada 89166","placeId":"ChIJ83h_tFiSyIARI4uCqjNI6Co"},{"name":"North Las Vegas, Nevada 89030","placeId":"ChIJe0htGuvCyIARxLTVLkpMIFo"},{"name":"North Las Vegas, Nevada 89031","placeId":"ChIJm8hCGlDoyIARXNxi9B5Qfr4"},{"name":"North Las Vegas, Nevada 89032","placeId":"ChIJxz3IVQnCyIARMH3_8Ju0c5E"},{"name":"North Las Vegas, Nevada 89081","placeId":"ChIJO5LJWIHoyIARRvpBQwDb6z8"},{"name":"North Las Vegas, Nevada 89084","placeId":"ChIJEY6Hxd_CyIARbcNlCDBQzZM"},{"name":"North Las Vegas, Nevada 89086","placeId":"ChIJWfYy_fToyIARUOP7qx1XXa8"},{"name":"Las Vegas, Nevada 89106","placeId":"ChIJsUsWAcrDyIARxXyFh_iUH0w"},{"name":"Blue Diamond, Nevada 89004","placeId":"ChIJlaiZwE-6yIARDHLu1ppRrO8"},{"name":"Sloan, Nevada 89054","placeId":"ChIJHcA5hBfLyIARvmMLTHq0B_I"},{"name":"Las Vegas, Nevada 89102","placeId":"ChIJ44Xlv_jDyIARprS8GWWlQEU"},{"name":"Las Vegas, Nevada 89103","placeId":"ChIJnxXsMZXGyIARRm5JNCgSLWk"},{"name":"Las Vegas, Nevada 89113","placeId":"ChIJlWyqQxO4yIARZPXtdlDlL7w"},{"name":"Las Vegas, Nevada 89117","placeId":"ChIJbxk24p7AyIARiqWiIPvgOhY"},{"name":"Las Vegas, Nevada 89118","placeId":"ChIJnXBgOEDGyIARBUXf79O4dUw"},{"name":"Las Vegas, Nevada 89124","placeId":"ChIJDY9TremZyIARM0VZ8r1y8xA"},{"name":"Las Vegas, Nevada 89135","placeId":"ChIJ_ej3yNO9yIARESkJp5yACp8"},{"name":"Las Vegas, Nevada 89139","placeId":"ChIJhfIiwLLJyIARyB8_cxZcRhI"},{"name":"Las Vegas, Nevada 89141","placeId":"ChIJETt0a1vJyIARoKdexaVz2wg"},{"name":"Las Vegas, Nevada 89143","placeId":"ChIJU6OGDeiSyIARa1v4tSzrVmo"},{"name":"Las Vegas, Nevada 89146","placeId":"ChIJr-36ESXByIARkBC4zqGbfxg"},{"name":"Las Vegas, Nevada 89147","placeId":"ChIJ9WV7h6m4yIARtrrkuK1jKP0"},{"name":"Las Vegas, Nevada 89148","placeId":"ChIJidumG1u4yIARPz_7sfsH1xo"},{"name":"Las Vegas, Nevada 89161","placeId":"ChIJvUhORwbSyIAR7Y1DT89xCXc"},{"name":"Las Vegas, Nevada 89178","placeId":"ChIJmaQ32Nu3yIARhZvoVtmU1no"},{"name":"Las Vegas, Nevada 89179","placeId":"ChIJk1CXFLvJyIARxE4k8LwL57A"},{"name":"Pahrump, Nevada 89048","placeId":"ChIJBZCQ8wU5xoAR_-M7TIWBMEk"},{"name":"Pahrump, Nevada 89061","placeId":"ChIJHbKviZA9xoARLKNZwf_biZY"},{"name":"Las Vegas, Nevada 89158","placeId":"ChIJiTjg4DHEyIARSBR-p3k8J9c"},{"name":"Nipton, California 92364","placeId":"ChIJAz4eNZlnz4AR3QOQ8CgEJg8"}]}}}
exception=com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
  "code" : 400,
  "message" : "Request contains an invalid argument.",
  "status" : "INVALID_ARGUMENT",
  "details" : [ {
    "@type" : "type.googleapis.com/google.mybusiness.v3p1.ValidationError",
    "errorDetails" : [ {
      "code" : 3,
      "field" : "service_area.places.place_info.place_id",
      "message" : "service_area.places.place_info.place_id is invalid",
      "value" : "ChIJm8hCGlDoyIARXNxi9B5Qfr4"
    } ]
  } ]
}

To summarize, this code is simply retrieving the existing serviceArea and sending it back unmodified in a patch request.  So this brings up the following questions:

  • If placeId=ChIJm8hCGlDoyIARXNxi9B5Qfr4 is invalid, how did it get associated with the location to begin with?
  • If I must filter out invalid places, is there a programmatic way to determine if a given placeId is valid before sending the patch request?
  • Are patch requests that update parts of an existing serviceArea (places, radius, businessType) even supported, or must I always include the full serviceArea? 

Re: Patch Location 500 Internal Server Error

Google Employee
# 10
Google Employee

Hi @Marcus G,

 

I can’t tell from your source code whether the business information you provide for this location is correct, so I suggest you troubleshoot this issue with the OAuth 2.0 Playground. The Place ID ChIJm8hCGlDoyIARXNxi9B5Qfr4 is not found according to the Reverse Geocoding by Place ID tool. Therefore, you might want to check whether there’s an error for your service-area business in the UI. The Google My Business API doesn’t provide a programmatic way to determine if a given placeId is valid, so you should use the Google Places API for that purpose, and direct any questions that you may have for the Google Places API to its Support Options for Google Places API Web Service page.

 

Yes, you can send a PATCH request with a fieldMask to update part of the ServiceAreaBusiness object. Just make sure the ServiceAreaBusiness object already exists in the specified location so that you won’t trigger the errors I mentioned in my previous post.

 

Thanks,

Terry