You need to sign in to do that
Don't have an account?
Adam Drissel 1
Getting REST API error message that isn't found anywhere
When I make a call to the API (code below) I get the following error message returned:
Here is the code I am using:
I've tried a "GET" call as well and get the same exact response. What "version" is unknown? My URL is formatted exactly as the Salesforce REST API documentation has it.
Please help ASAP.
System.HttpResponse[Status=Unknown Version, StatusCode=400]
Here is the code I am using:
public static void callRestApi(){ String instance = getSFDCInstance(); String sessionId = getSessionId(); String url = instance+'/services/data/v37.0/sobjects/Case/describe/ -H \"Authorization: Bearer'+sessionId+'\"'; system.debug(url); Http h = new Http(); HttpRequest req = new HttpRequest(); req.setEndpoint(url); req.setMethod('POST'); req.setHeader('Charset', 'UTF-8'); req.setHeader('Content-Type', 'text/plain'); system.debug(req); HttpResponse res = h.send(req); String body = res.getBody(); system.debug(body); }
I've tried a "GET" call as well and get the same exact response. What "version" is unknown? My URL is formatted exactly as the Salesforce REST API documentation has it.
Please help ASAP.
Code is for you . Use this one
public class callRestApi {
public static void callRestApi1(){
String sessionId =UserInfo.getSessionId();
Http h = new Http();
//curl https://NA50.salesforce.com/services/data/v30.0/sobjects/Account/describe/approvalLayouts/ -H "Authorization: Bearer token"
HttpRequest req = new HttpRequest();
// req.setEndpoint('https://'+'NA50.salesforce.com'+'/services/data/v37.0/sobjects/case/describe -H \"Authorization: Bearer '+sessionId+'\"');
req.setMethod('GET');
String val ='https://fscttt-dev-ed.my.salesforce.com/services/data/v37.0/sobjects/case/describe' ;
System.debug('===================>'+val);
req.setEndpoint(val);
req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
HttpResponse res = h.send(req);
System.debug('res Status'+res.getStatus());
String body = res.getBody();
system.debug('=='+body);
}
}
Please follow some best practices and patterns . this code was for testing
I am trying to make the API call from within a Lightning App. I've been reading up a little more on this and it seems to explain why I continue to get the "Session Invalid" error status even if everything is correct. According to the Lightning Dev Manual (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_api_calls_platform.htm) I can invoke it from my Apex Controller, as long as I used Named Credentials. But, I have tried that and get the same error there.
Any wisdom on that?