googleapis / google-api-java-client-services

Generated Java code for Google APIs
Apache License 2.0
624 stars 353 forks source link

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

Open mkalkowski83 opened 1 year ago

mkalkowski83 commented 1 year ago

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

emmileaf commented 1 year ago

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!

mkalkowski83 commented 1 year ago

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

burkedavison commented 1 month ago

Improve documentation