You need to sign in to do that
Don't have an account?
Michał Bajdek
JSON from HttpResponse
I have following code:
And I am trying to send request to google maps api and recieve an answer as JSON. My variable "endpoint" contains following value:
https://maps.googleapis.com/maps/api/geocode/json?address=Lodz Tuszynska 101/7&key=[myAPIKey]
and when I am trying to do it manually via FIrefox i get proper JSON representation, but in apex I get: "12:41:58:073 USER_DEBUG [17]|INFO|## System.HttpResponse[Status=Bad Request, StatusCode=400]" . I have tried to replace all spaces to "%" in my endpoint but it did not work. COuld you please give me some advice what I am doing wrong?
Http httpProtocol = new Http(); HttpRequest request = new HttpRequest(); system.debug(logginglevel.INFO , '$$ ' + ValueProvider.constructEndpoint(addressToDetermineCoordinates)); String endpoint = ValueProvider.constructEndpoint(addressToDetermineCoordinates); System.debug(Logginglevel.INFO , '#$ endpoint url: ' + endpoint); request.setEndpoint(endpoint); request.setMethod('GET'); HttpResponse response = httpProtocol.send(request); system.debug(logginglevel.info , '## ' + response.toString() ); System.debug(logginglevel.info , '@#response' + response.getBody());
And I am trying to send request to google maps api and recieve an answer as JSON. My variable "endpoint" contains following value:
https://maps.googleapis.com/maps/api/geocode/json?address=Lodz Tuszynska 101/7&key=[myAPIKey]
and when I am trying to do it manually via FIrefox i get proper JSON representation, but in apex I get: "12:41:58:073 USER_DEBUG [17]|INFO|## System.HttpResponse[Status=Bad Request, StatusCode=400]" . I have tried to replace all spaces to "%" in my endpoint but it did not work. COuld you please give me some advice what I am doing wrong?
Have you added the endpoint in remote site settings ? Please check.
Thanks,
Prosenjit
I am Not Getting Ander Stand ,But As I understand U used This Class For getting End Point Url ValueProvider.constructEndpoint(addressToDetermineCoordinates)); Dont Use httpProtocol.send(request); This Method Use InThis Way
Http ht=new Http();
HttpResponse response = ht.send(request);
This Solution Might Help You
Any Thing Suspices!!
Regards
Srinivsa
Both the cases are same. He had changed the variable name of the http class.
Hi Michal,
can you please share the endpoint name which you are getting in System.debug at line 5 ?
Thanks
Prosenjit.