+ Start a Discussion
Kathryn BullockKathryn Bullock 

Error Message for JSON: Content cannot be displayed: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]

I am receiving this error message: Content cannot be displayed: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]

This is for a visualforce page.  Here is the Class:
public class AccountShippingController {
    public String trackingnumber {get;set;}
    public String shipmentStatus {get;set;}
    public String shipperAddr {get;set;}
    public String consigneeAddr {get;set;}

    public AccountShippingController(ApexPages.StandardController stdController){
        Account account =(Account)stdController.getRecord();
        account = [SELECT Id, XPO_Tracking__c FROM Account WHERE Id =:account.Id];
        String accountTracking = account.XPO_Tracking__c;
        String apiKey = 'XXXXXXXXXXXXXX';
        String requestEndpoint = 'https://app.ltl.xpo.com/appjs/tracking/#/tracking';
        requestEndpoint += 'details/' + accountTracking;
        requestEndpoint += '&APPID=' + apiKey;
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        HttpResponse response = http.send(request);
        if (response.getStatusCode() == 200) {
            Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
            trackingnumber = String.valueOf(results.get('referenceNumbers'));
            Map<String, Object> shipmentStatusDtlsResults = (Map<String, Object>)(results.get('shipmentStatusDtls'));
            shipmentStatus = String.valueOf(shipmentStatusDtlsResults.get('shipmentStatus'));
            shipperAddr = String.valueOf(shipmentStatusDtlsResults.get('shipperAddr'));
            consigneeAddr = String.valueOf(shipmentStatusDtlsResults.get('consigneeAddr'));
        } else {
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'There was an error retrieving the information.  Double check the Tracking Number, then contact a system administrator.');
(I have removed the API key)

And the VF Page is:
<apex:page standardController="Account" extensions="AccountShippingController" showHeader="false" sidebar="false">
           <apex:pageBlock title ="Shipping Information">
                    <apex:outputText label="Shipping Status" value="{!shipmentStatus}"/>
                    <apex:outputText label="Shipper Information" value="{!shipperAddr}"/>
                    <apex:outputText label="Consignee Information" value="{!consigneeAddr}"/>
Any and all suggestions are welcome!  
Alain CabonAlain Cabon

You get an XML response instead of a JSON response probably.

Http http = new Http();
HttpRequest request = new HttpRequest();
request.setHeader('Content-Type', 'application/json');

HttpResponse response = http.send(request);
Kathryn BullockKathryn Bullock
Thank you for the response!  This was eventually solved by changing the remote site access to https://api.ltl.xpo.com, however now I am slightly confused about whether or not I need to do an Oauth.