[SalesForce] System.HttpResponse[Status=Not Found, StatusCode=404]

This webservice has been running perfectly for almost a year now.

However today I am seeing this error

|System.HttpResponse[Status=Not Found, StatusCode=404]

11:08:55.0 (509386280)|FATAL_ERROR|System.JSONException: Unexpected character ('d' (code 100)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]

Here's my code

        HttpRequest request = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http(); 
        request.setMethod(httpVerb);
        request.setEndpoint(host + endpoint);   
        request.setHeader ('Date', timestamp);
        request.setHeader('Authorization', rawSignature);
        request.setTimeout(120000);
        system.debug(System.now()+'-- Send Request To Server --');
        res = http.send(request);
        **system.debug(System.now()+'-- get Response --'+res.getBody());**
        return res.getBody();




    public static List<Map<string, integer>> getChartMap(String accountid){

        Account accObj = [SELECT Id,External_ID__c FROM Account where Id =: accountid];
        system.debug(System.now()+'-- getAPIData called with externalID From GetChartMap Method --');
        String jsonData = getAPIData(accObj.External_ID__c );
        system.debug(System.now()+'-- get Response in getChartMap method --'+jsonData);
        List<Map<string, integer>> finalMap = new List<Map<string, integer>>();        
        Integer currenMonth = Date.Today().Month();
        **Map<String, Object> results = (Map<String, Object>)JSON.deserializeUntyped(jsonData);**

        ....

    }

Debug Logs

11:08:55.0 (507563738)|CALLOUT_RESPONSE|[66]|**System.HttpResponse[Status=Not Found, StatusCode=404]**
11:08:55.0 (507598672)|HEAP_ALLOCATE|[66]|Bytes:34
11:08:55.0 (507721573)|VARIABLE_ASSIGNMENT|[66]**|res|"System.HttpResponse[Status=Not Found,** StatusCode=404]"|0x494d4d21
11:08:55.0 (507732287)|STATEMENT_EXECUTE|[67]
11:08:55.0 (507784731)|HEAP_ALLOCATE|[67]|Bytes:56
11:08:55.0 (507833394)|HEAP_ALLOCATE|[67]|Bytes:19
11:08:55.0 (507972732)|HEAP_ALLOCATE|[67]|Bytes:18
11:08:55.0 (508026872)|HEAP_ALLOCATE|[67]|Bytes:21
11:08:55.0 (508073145)|HEAP_ALLOCATE|[67]|Bytes:58
11:08:55.0 (508093952)|USER_DEBUG|[67]|**DEBUG|2020-04-28 15:08:56-- get Response --default backend - 404**
11:08:55.0 (508106389)|STATEMENT_EXECUTE|[68]
11:08:55.0 (508136746)|HEAP_ALLOCATE|[68]|Bytes:21
11:08:55.0 (508153645)|METHOD_EXIT|[76]|01p2S000003FgbV|GraphController.getAPIData(String)
11:08:55.0 (508164831)|VARIABLE_SCOPE_BEGIN|[76]|jsonData|String|false|false
11:08:55.0 (508187910)|VARIABLE_ASSIGNMENT|[76]|jsonData|"default backend - 40 (1 more) ..."

USER_DEBUG|[77]|DEBUG|2020-04-28 15:08:56-- get Response in getChartMap method --default backend - 404
11:08:55.0 (508280487)|STATEMENT_EXECUTE|[78]
11:08:55.0 (508319018)|HEAP_ALLOCATE|[78]|Bytes:4
11:08:55.0 (508522669)|VARIABLE_SCOPE_BEGIN|[78]|finalMap|List<Map<String,Integer>>|true|false
11:08:55.0 (508587328)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:4
11:08:55.0 (508607603)|VARIABLE_ASSIGNMENT|[78]|finalMap|[]|0x3371fc3f
11:08:55.0 (508615451)|STATEMENT_EXECUTE|[79]
11:08:55.0 (508670037)|HEAP_ALLOCATE|[79]|Bytes:4
11:08:55.0 (508699049)|VARIABLE_SCOPE_BEGIN|[79]|currenMonth|Integer|false|false
11:08:55.0 (508708582)|HEAP_ALLOCATE|[79]|Bytes:4
11:08:55.0 (508719881)|VARIABLE_ASSIGNMENT|[79]|currenMonth|4
11:08:55.0 (508726337)|STATEMENT_EXECUTE|[80]
11:08:55.0 (508789017)|HEAP_ALLOCATE|[80]|Bytes:24
11:08:55.0 (508806983)|SYSTEM_METHOD_ENTRY|[1]|JSON.JSON()
11:08:55.0 (508811815)|STATEMENT_EXECUTE|[1]
11:08:55.0 (508821367)|SYSTEM_METHOD_EXIT|[1]|JSON
11:08:55.0 (508843169)|METHOD_ENTRY|[80]||System.JSON.deserializeUntyped(String)
11:08:55.0 (509080864)|METHOD_EXIT|[80]||System.JSON.deserializeUntyped(String)
11:08:55.0 (509222994)|**FATAL_ERROR|System.JSONException: Unexpected character ('d' (code 100)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2]**

Best Answer

You need to check with the service provider. 404 means "file not found", so something changed on the far end. Further, it looks like the response is in HTML or something, instead of JSON, which is what you're expecting.

Related Topic