• Jim Warner
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
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! 
I'm working on an integration between our client's Salesforce org and a third party.  They have a few REST API's that I need to call from Apex code and receive back some JSON data.  They have provided pretty good documentation.  They are using OAuth 2.0 for authentication.  The code will need to be run on a scheduled basis and may also be initiated by a user.  I'm a pretty skilled Windows developer in a variety of languages but am new to the force.com platform.  Any resources or sample code you could point me at would be much appreciated.  
I'm working on an integration between our client's Salesforce org and a third party.  They have a few REST API's that I need to call from Apex code and receive back some JSON data.  They have provided pretty good documentation.  They are using OAuth 2.0 for authentication.  The code will need to be run on a scheduled basis and may also be initiated by a user.  I'm a pretty skilled Windows developer in a variety of languages but am new to the force.com platform.  Any resources or sample code you could point me at would be much appreciated.  
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! 
I'm working on an integration between our client's Salesforce org and a third party.  They have a few REST API's that I need to call from Apex code and receive back some JSON data.  They have provided pretty good documentation.  They are using OAuth 2.0 for authentication.  The code will need to be run on a scheduled basis and may also be initiated by a user.  I'm a pretty skilled Windows developer in a variety of languages but am new to the force.com platform.  Any resources or sample code you could point me at would be much appreciated.