function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Michał BajdekMichał Bajdek 

JSON from HttpResponse

I have following code:
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);
            HttpResponse response = httpProtocol.send(request);
            system.debug( , '## ' + response.toString() );
            System.debug( , '@#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: 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?
Prosenjit Sarkar 7Prosenjit Sarkar 7
 Hi Michal, 
 Have you added the endpoint in remote site settings ? Please check.
Michał BajdekMichał Bajdek
yes, I did it
srinu reddy 30srinu reddy 30
Hi Michal 
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!!

Prosenjit Sarkar 7Prosenjit Sarkar 7
Hi 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 ?
Michał BajdekMichał Bajdek
I do not know why but it works now. I didn't do anything. Maybe it was temporary problem with server