You need to sign in to do that
Don't have an account?
Jim Warner
REST/JSON API Callout seems to return html
This question refers to the following:
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_json_jsonparser.htm
Following the example in the link above, I've added http://www.cheenath.com as a remote site. When I execute the following snippit of the example code in the Execute Anonomous Window of the developer console:
Http httpProtocol = new Http();
// Create HTTP request to send.
HttpRequest request = new HttpRequest();
// Set the endpoint URL.
String endpoint = 'http://www.cheenath.com/tutorial/sfdc/sample1/response.php';
request.setEndPoint(endpoint);
// Set the HTTP verb to GET.
request.setMethod('GET');
// Send the HTTP request and get the response.
// The response is in JSON format.
HttpResponse response = httpProtocol.send(request);
System.debug(response.getBody());
I get back what looks like html in the return value (in the log output) from the resspone.getBody() method call.
When I execute the full code in the parseJSONResponse method, I get the following error:
System.JSONException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]
So it looks like the JSONParser is also seeing html.
What's up with this? I get this same error on another 3rd Party site where I'm making a REST API Callout and expecting JSON as the return value. Seems like I must be missing something fundamental in how I'm making the REST calls. Am I looking at the wrong part of the response?
I have also tried setting the following in the request header:
req.setHeader('content-type', 'application/json');
It doesn't make any difference in what I get back in the body.
On the other 3rd Party website, when I execute some test PHP code that makes the same REST call, I do get JSON data back, so the API seems to be working.
Thanks for any help you can give!
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_json_jsonparser.htm
Following the example in the link above, I've added http://www.cheenath.com as a remote site. When I execute the following snippit of the example code in the Execute Anonomous Window of the developer console:
Http httpProtocol = new Http();
// Create HTTP request to send.
HttpRequest request = new HttpRequest();
// Set the endpoint URL.
String endpoint = 'http://www.cheenath.com/tutorial/sfdc/sample1/response.php';
request.setEndPoint(endpoint);
// Set the HTTP verb to GET.
request.setMethod('GET');
// Send the HTTP request and get the response.
// The response is in JSON format.
HttpResponse response = httpProtocol.send(request);
System.debug(response.getBody());
I get back what looks like html in the return value (in the log output) from the resspone.getBody() method call.
When I execute the full code in the parseJSONResponse method, I get the following error:
System.JSONException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]
So it looks like the JSONParser is also seeing html.
What's up with this? I get this same error on another 3rd Party site where I'm making a REST API Callout and expecting JSON as the return value. Seems like I must be missing something fundamental in how I'm making the REST calls. Am I looking at the wrong part of the response?
I have also tried setting the following in the request header:
req.setHeader('content-type', 'application/json');
It doesn't make any difference in what I get back in the body.
On the other 3rd Party website, when I execute some test PHP code that makes the same REST call, I do get JSON data back, so the API seems to be working.
Thanks for any help you can give!
which is not the data you would expect.
[1] https://twitter.com/tutorial/sfdc/sample1/response.php/cheenath
What other endpoints are you testing against?
http://betasandbox.api.chapterspot.info/search/members?client_userid=12345&client_id=triangle_connector&client_secret=b898f4086312ee94fc98982906b406e1fd
It seems to work fine in a browser, but not from Apex.
Even i am facing the issue.
Unexpected character ('E' (code 69)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]
I am calling a HTTP Get method in one of the Salesforce Org (Say SF2) from one more salesforce org (Say SF1)
Basically i am doing a future callout from SF1 from trigger,after insert ....if the Account Exist in SF2 then update the Acount references in SF1.
Here i am passing Single Account Id just for example...passing the Account name in the End Point URL and in SF2 querying the same and returning based on match found.
While Creating Account If i Give Account Name without Space e.g Test Account ,it gives below error :
Unexpected character ('E' (code 69)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]
But if i give TestAccount it passes and returns the result,may be its not taking the white spaces.
Just wanted to know how can i remove the space and again retrieve the same after sending back to external system to find the match.
May be i am missing something.
Thanks in Advance.