Skip to content

Getting Invalid Argument error from Google Business Profile API while trying to create a location #3530

@ahsanaasim

Description

@ahsanaasim

I am using Google's Business API to add a location from my Node.js application, but I'm encountering the following error:

{
    "error": "Request contains an invalid argument."
}

I am using the googleapis npm package and tried by commenting out all optional fields, leaving only the required fields in the request body. But, I'm still encountering an error. Here is my code:

app.post('/add-location', async (req, res) => {
    const { location, tokens } = req.body;
    oauth2Client.setCredentials(tokens);

    const mybusinessbusinessinformation = google.mybusinessbusinessinformation('v1');
    try {
        const response = await mybusinessbusinessinformation.accounts.locations.create({
            parent: 'accounts/' + process.env.ACCOUNT_ID,
            validateOnly: true,
            requestId: uuidv4(),
            requestBody: {


                // "name": "EVgo Charging Station",
                // "languageCode": "en",
                // "storeCode": "EVG123",
                "title": "EVgo Charging Station",
                // "phoneNumbers": {
                //     "primaryPhone": "+1 123-456-7890"
                // },
                // "categories": {
                //     "primaryCategory": {
                //         "name": "categories/gcid:electric_vehicle_charging_station",
                //         "displayName": "Electric vehicle charging station",
                //     },
                // },
                // "storefrontAddress": {
                //     "regionCode": "US",
                //     "locality": "Durham",
                //     "postalCode": "27707",
                //     "addressLines": ["4711 Hope Valley Rd", "Woodcroft Shopping Center"]
                // },
                // "websiteUri": "https://evgo.com",
                // "regularHours": {
                //     "periods": [
                //         {
                //             "openDay": "MONDAY",
                //             "openTime": {
                //                 "hours": 0,
                //                 "minutes": 0
                //             },
                //             "closeDay": "SUNDAY",
                //             "closeTime": {
                //                 "hours": 23,
                //                 "minutes": 59
                //             }
                //         }
                //     ]
                // },
                // "specialHours": {
                //     "specialHourPeriods": [
                //         {
                //             "startDate": {
                //                 "year": 2024,
                //                 "month": 12,
                //                 "day": 25
                //             },
                //             "endDate": {
                //                 "year": 2024,
                //                 "month": 12,
                //                 "day": 25
                //             },
                //             "closed": true
                //         }
                //     ]
                // },
                // "labels": [
                //     "EV Charging",
                //     "Fast Charging"
                // ],
                // "latlng": {
                //     "latitude": 35.951033,
                //     "longitude": -78.956228
                // },
                // "openInfo": {
                //     "status": "OPEN",
                //     "canReopen": true
                // },
                // "metadata": {
                //     "mapsUri": "https://maps.google.com/?q=EVgo+Charging+Station",
                //     "newReviewUri": "https://maps.google.com/review?place_id=ChIJzxbB6Gs7bIcRZZrPTeyb-0A"
                // },
                "profile": {
                    "description": "Fast and reliable electric vehicle charging station."
                },
                // "relationshipData": {
                //     "parentChain": "EVgo"
                // },
                // "moreHours": [
                //     {
                //         "hoursTypeId": "DRIVE_THROUGH",
                //         "periods": [
                //             {
                //                 "openDay": "MONDAY",
                //                 "openTime": {
                //                     "hours": 0,
                //                     "minutes": 0
                //                 },
                //                 "closeDay": "SUNDAY",
                //                 "closeTime": {
                //                     "hours": 23,
                //                     "minutes": 59
                //                 }
                //             }
                //         ]
                //     }
                // ],
            },
            auth: oauth2Client
        });
        console.log(response)
        res.send(response.data);
    } catch (error) {
        console.error(error)
        res.status(400).send({ error: error.message });
    }
});

here is detailed log

GaxiosError: Request contains an invalid argument.
    at Gaxios._request (/Users/workstation/Programming/Clients/-/gmb-microservice/node_modules/gaxios/build/src/gaxios.js:142:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async OAuth2Client.requestAsync (/Users/workstation/Programming/Clients/-/gmb-microservice/node_modules/google-auth-library/build/src/auth/oauth2client.js:429:18)
    at async /Users/workstation/Programming/Clients/-/gmb-microservice/server.js:52:26 {
  config: {
    url: 'https://mybusinessbusinessinformation.googleapis.com/v1/accounts/102094468378068712054/locations?validateOnly=true&requestId=54e30089-a836-441c-8eb0-bdd936c0a979',
    method: 'POST',
    apiVersion: '',
    userAgentDirectives: [ [Object] ],
    paramsSerializer: [Function (anonymous)],
    data: { title: 'EVgo Charging Station', profile: [Object] },
    headers: {
      'x-goog-api-client': 'gdcl/7.2.0 gl-node/20.8.0',
      'Accept-Encoding': 'gzip',
      'User-Agent': 'google-api-nodejs-client/7.2.0 (gzip)',
      Authorization: '<<REDACTED> - See `errorRedactor` option in `gaxios` for configuration>.',
      'Content-Type': 'application/json'
    },
    params: {
      validateOnly: true,
      requestId: '54e30089-a836-441c-8eb0-bdd936c0a979'
    },
    validateStatus: [Function (anonymous)],
    retry: true,
    body: '{"title":"EVgo Charging Station","profile":{"description":"Fast and reliable electric vehicle charging station."}}',
    responseType: 'unknown',
    errorRedactor: [Function: defaultErrorRedactor],
    retryConfig: {
      currentRetryAttempt: 0,
      retry: 3,
      httpMethodsToRetry: [Array],
      noResponseRetries: 2,
      retryDelayMultiplier: 2,
      timeOfFirstRequest: 1722445004419,
      totalTimeout: 9007199254740991,
      maxRetryDelay: 9007199254740991,
      statusCodesToRetry: [Array]
    }
  },
  response: {
    config: {
      url: 'https://mybusinessbusinessinformation.googleapis.com/v1/accounts/102094468378068712054/locations?validateOnly=true&requestId=54e30089-a836-441c-8eb0-bdd936c0a979',
      method: 'POST',
      apiVersion: '',
      userAgentDirectives: [Array],
      paramsSerializer: [Function (anonymous)],
      data: [Object],
      headers: [Object],
      params: [Object],
      validateStatus: [Function (anonymous)],
      retry: true,
      body: '{"title":"EVgo Charging Station","profile":{"description":"Fast and reliable electric vehicle charging station."}}',
      responseType: 'unknown',
      errorRedactor: [Function: defaultErrorRedactor]
    },
    data: { error: [Object] },
    headers: {
      'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000',
      'cache-control': 'private',
      'content-encoding': 'gzip',
      'content-type': 'application/json; charset=UTF-8',
      date: 'Wed, 31 Jul 2024 16:56:44 GMT',
      server: 'ESF',
      'transfer-encoding': 'chunked',
      vary: 'Origin, X-Origin, Referer',
      'x-content-type-options': 'nosniff',
      'x-frame-options': 'SAMEORIGIN',
      'x-xss-protection': '0'
    },
    status: 400,
    statusText: 'Bad Request',
    request: {
      responseURL: 'https://mybusinessbusinessinformation.googleapis.com/v1/accounts/102094468378068712054/locations?validateOnly=true&requestId=54e30089-a836-441c-8eb0-bdd936c0a979'
    }
  },
  error: undefined,
  status: 400,
  code: 400,
  errors: [
    {
      message: 'Request contains an invalid argument.',
      domain: 'global',
      reason: 'badRequest'
    }
  ],
  [Symbol(gaxios-gaxios-error)]: '6.7.0'
}

Also, Is there detailed documentation available for the Google Business API in the googleapis npm package?

I am following the following URL for creating the request body

https://developers.google.com/my-business/reference/businessinformation/rest/v1/accounts.locations#Location

I have asked the same question in stackoverflow.
https://stackoverflow.com/questions/78817586/getting-invalid-argument-error-from-google-business-profile-api-while-trying-to

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs more infoThis issue needs more information from the customer to proceed.priority: p3Desirable enhancement or fix. May not be included in next release.type: questionRequest for information or clarification. Not an issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions