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

GMB Insights Issue

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

Dear GMB Team,

 

we are currently trying to implement Insights into our System, however we are unable to identify this error:

{'error': {'status': 'INVALID_ARGUMENT', 'message': 'Request contains an invalid argument.', 'code': 400}}

 

We used the following dataset:

 

 data = {
 	'locationNames':
 		['bspotted'],
 	'basicRequest': {
 			"metricRequests": [
		    {
		      "metric": "ALL",
		      "options": [
		      	"AGGREGATED_DAILY",
		      ],
		    }
		  ],
		  "timeRange": {
		    "startTime": "2016-11-18T11:50:05.072147Z",
		    "endTime":"2017-01-17T02:50:05.072147Z"
		  },
 		}

 	}
1 Expert replyverified_user

Re: GMB Insights Issue

Visitor ✭ ✭ ✭
# 2
Visitor ✭ ✭ ✭

Hi,

I think you've this problem because you're using the "getLocationName()" method and you should use "getName()" instead. It must be something like accounts/XXXXXXXXXX/locations/XXXXXXXXXXXXX and not bspotted. Take a look on my code below. It's working. Good luck.

 

 

public void getReportInsights(String accountName) {

        
            ReportLocationInsightsRequest request = new ReportLocationInsightsRequest();

            List<String> locationsNames = new ArrayList<>();
            List<Location> locations = getLocations(accountName);
            int i = 0;
            for (Location location : locations){
                if(i==3) break;
                locationsNames.add(location.getName());
                i++;
            }

            request.setLocationNames(locationsNames);
            request.setBasicRequest(new BasicMetricsRequest());
            List<MetricRequest> metrics = new ArrayList<>();
            MetricRequest metric1 = new MetricRequest();
            MetricRequest metric2 = new MetricRequest();
            
            metric1.setMetric("QUERIES_DIRECT");
            metric2.setMetric("QUERIES_INDIRECT");

            metrics.add(metric1);
            metrics.add(metric2);

            request.getBasicRequest().setMetricRequests(metrics);
            TimeRange time = new TimeRange();
            time.setStartTime("2016-12-10T15:01:23.045123456Z");
            time.setEndTime("2017-01-10T15:01:23.045123456Z");
            request.getBasicRequest().setTimeRange(time);

        try {
            MyBusiness.Accounts.Locations.ReportInsights insights = getService().accounts().locations().reportInsights(accountName, request);
            ReportLocationInsightsResponse response = insights.execute();

            System.out.println(response.toString());

        } catch (IOException e) {
            e.printStackTrace();
        }
}

 

Marked as Best Answer.
Solution
Accepted by topic author Daniel K
January 2017

Re: GMB Insights Issue

Google Employee
# 3
Google Employee

Hi @Daniel K,

 

I notice from the HTTP request message you provided in your post that the format you are using for 'locationNames' is not correct. The locationNames represents the collection of locations to fetch insights for your business. I suggest you please change the 'locationNames': ['bspotted'] to "locationNames": [

"accounts/account_name/locations/locationId", ] in your request.

 

REQUEST:

{
 "locationNames": [
   "accounts/account_name/locations/locationId",
 ],
 "basicRequest" : {
         "metricRequests": [
            {
              "metric": "ALL",
              "options": [
                      "AGGREGATED_DAILY",
                    ],
            },  
         ],
         "timeRange": {
                       "startTime": "2016-11-18T11:50:05.072147Z",
                       "endTime":"2017-01-17T02:50:05.072147Z"
         },
   },
}

 

Thanks,

Shalini