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

Issue with requesting insights

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hello. 

I am having an issue with accounts.locations.reportInsights

Here is my request I am making:

  $.ajax({
    url: 'https://mybusiness.googleapis.com/v4/accounts/***/locations:reportInsights',
    method: 'POST',
	data: {
		"locationNames": [
							"accounts/***/locations/***",
							"accounts/***/locations/***",
						],
		"basicRequest": {
							"metricRequests":[{"metric": "ALL"}],
						},
    },
	dataType: 'json',
    beforeSend: function(xhr) {
      xhr.setRequestHeader("Authorization", "Bearer " + oauthToken)
    },
  }).done((data) => {
	console.log(data);
  })

The error I am receiving is as follows: 

"{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"locationNames[]\": Cannot bind query parameter. Field 'locationNames[]' could not be found in request message.\nInvalid JSON payload received. Unknown name \"basicRequest[metricRequests][0][metric]\": Cannot bind query parameter. Field 'basicRequest[metricRequests][0][metric]' could not be found in request message.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "description": "Invalid JSON payload received. Unknown name \"locationNames[]\": Cannot bind query parameter. Field 'locationNames[]' could not be found in request message."
          },
          {
            "description": "Invalid JSON payload received. Unknown name \"basicRequest[metricRequests][0][metric]\": Cannot bind query parameter. Field 'basicRequest[metricRequests][0][metric]' could not be found in request message."
          }
        ]
      }
    ]
  }
}
"

Please advise.

 

Thank you

1 Expert replyverified_user
Marked as Best Answer.
Solution
Accepted by topic author Peter S
1w

Re: Issue with requesting insights

[ Edited ]
Google Employee
# 2
Google Employee

Hi @Peter S,

 

After looking at the code you provided, I noticed that the timeRange field is missing in BasicMetricsRequest method when retrieving the location insights. Please add timeRange field in your code to see if it fixes your issue:

POST https://mybusiness.googleapis.com/v4/accounts/***/locations:reportInsights
{
"locationNames":
 [
 "accounts/***/locations/***",
“accounts/***/locations/***”
],
  
"basicRequest": {
"metricRequests": [{"metric": "ALL"}],
"timeRange": {
"startTime": "2017-10-01T04:00:00.00000000Z",
"endTime": "2017-11-10T04:00:00.00000000Z",
},
},
}

 

Also we suggest you follow the Make a simple HTTP request step-by-step guide on the Google Developers site and try use the OAuth 2.0 Playground to step through the auth flow, and examine the HTTP request/response at each step. This usually helps pinpoint where an application is passing the incorrect info.

 

Thanks,

The Google My Business API team

Issue with requesting insights

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

This got it working!

Thank you for your assistance

Experts in the Topic
Shalini S