everyone.
I am trying to run batch, wich will fill the geolocation field on accounts. And for now, i have an issue with http request, that fails.
so, here it is
public static String[] getCoordinates(String commonAddress){
String[] Coordinates;
String url = 'https://maps.googleapis.com/maps/api/geocode/json?';
url += 'address=' + commonAddress;
url += '&sensor=false';
system.debug(Logginglevel.ERROR,'GeoUtilitiesCoordinates url: ' + url);
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setMethod('GET');
req.setEndpoint(url);
String responseBody;
if (!Test.isRunningTest()){
// Methods defined as TestMethod do not support Web service callouts
HttpResponse res = h.send(req);
system.debug('res // ' + res);
responseBody = res.getBody();
}
else {
// dummy data
responseBody = '\"location\" : { \"lat\" : 32.0719776,\"lng\" : 34.7914048}';
}
system.debug('responseBody // ' + responseBody);
/*
body parsing should be here
*/
return Coordinates;
}
The problem is - i have System.HttpResponse[Status=Bad Request, StatusCode=400] in my debug log.
but the request itself System.HttpRequest[Endpoint=https://maps.googleapis.com/maps/api/geocode/json?address=Nottingham,&sensor=false, Method=GET]
has a correct endpoint and it works fine in browser.
Response body says
Your client has issued a malformed or illegal request. That’s all we know.
What is the problem could be?