google-api-java-client-services icon indicating copy to clipboard operation
google-api-java-client-services copied to clipboard

How to sent X-GOOG-API-FORMAT-VERSION to get more information in error response?

Open mkalkowski83 opened this issue 1 year ago • 3 comments

Dear team, I'm trying to use an extra header that is written in this documentation https://developers.google.com/my-business/samples/#detailed_error_responses but it doesn't work. Below is my code:

val create = apiFactory
     .createBusinessInformationClient()
     .Accounts()
     .Locations()
     .create("accounts/{account_id}",
    Location()
// .setTitle("Test shop by API") - I comment this because I want to get an error about missing field
        .setLanguageCode("pl")
        .setCategories(Categories().setPrimaryCategory(Category().setName("categories/gcid:aadhar_center")))
        .setStorefrontAddress(
            PostalAddress()
           .setLanguageCode("en")
           .setAddressLines(listOf("Tagore 1"))
           .setLocality("Warsaw")
           .setPostalCode("00-123")
          .setRegionCode("PL")
      )
      .setOpenInfo(
          OpenInfo().setStatus("OPEN")
       )
       .setProfile(Profile().setDescription("Ale super sklep"))
  )
create.requestHeaders.set("X-GOOG-API-FORMAT-VERSION", "2")
create.validateOnly = true
create.execute()

only what I get from the response is:

{
  "code": 400,
  "details": [
    {
      "@type": "[type.googleapis.com/google.rpc.BadRequest](http://type.googleapis.com/google.rpc.BadRequest)"
    }
  ],
  "errors": [
    {
      "domain": "global",
      "message": "Request contains an invalid argument.",
      "reason": "badRequest"
    }
  ],
  "message": "Request contains an invalid argument.",
  "status": "INVALID_ARGUMENT"
}

What I'm doing wrong? Best Regards

mkalkowski83 avatar Mar 23 '23 08:03 mkalkowski83

Can you provide more details on what API and maven artifact you are using (as well as any additional information you can share as outlined in the issues template)? Thanks!

emmileaf avatar Mar 24 '23 17:03 emmileaf

Hi @emmileaf sure, more details are below:

Environment details Google MyBusiness Business Information

OS type and version: Java version:

openjdk version "18.0.2-ea" 2022-07-19
OpenJDK Runtime Environment (build 18.0.2-ea+9-Ubuntu-222.04)
OpenJDK 64-Bit Server VM (build 18.0.2-ea+9-Ubuntu-222.04, mixed mode, sharing)

Libs versions:

implementation("com.google.api-client:google-api-client:1.35.2")
implementation("com.google.auth:google-auth-library-oauth2-http:1.16.0")
implementation("com.google.apis:google-api-services-mybusinessbusinessinformation:v1-rev20221124-2.0.0")

Code example

val create = apiFactory
     .createBusinessInformationClient()
     .Accounts()
     .Locations()
     .create("accounts/{account_id}",
    Location()
// .setTitle("Test shop by API") - I comment this because I want to get an error about missing field
        .setLanguageCode("pl")
        .setCategories(Categories().setPrimaryCategory(Category().setName("categories/gcid:aadhar_center")))
        .setStorefrontAddress(
            PostalAddress()
           .setLanguageCode("en")
           .setAddressLines(listOf("Tagore 1"))
           .setLocality("Warsaw")
           .setPostalCode("00-123")
          .setRegionCode("PL")
      )
      .setOpenInfo(
          OpenInfo().setStatus("OPEN")
       )
       .setProfile(Profile().setDescription("Ale super sklep"))
  )
create.requestHeaders.set("X-GOOG-API-FORMAT-VERSION", "2")
create.validateOnly = true
create.execute()

Stack trace

{
  "code": 400,
  "details": [
    {
      "@type": "[type.googleapis.com/google.rpc.BadRequest](http://type.googleapis.com/google.rpc.BadRequest)"
    }
  ],
  "errors": [
    {
      "domain": "global",
      "message": "Request contains an invalid argument.",
      "reason": "badRequest"
    }
  ],
  "message": "Request contains an invalid argument.",
  "status": "INVALID_ARGUMENT"
}

External references such as API reference guides: https://developers.google.com/my-business/samples/#detailed_error_responses

mkalkowski83 avatar Mar 28 '23 06:03 mkalkowski83

Improve documentation

burkedavison avatar Sep 16 '24 19:09 burkedavison