You need to sign in to do that
Don't have an account?
Error in REST API call after getting the token
Hi, I am trying to make root call (or any other call like query as well), I am getting the below error:
System.HttpResponse[Status=Bad Request, StatusCode=400]
Below is the code snippet, please let me know what am I missing here.
Http http = new Http();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
req.setEndpoint('https://login.salesforce.com/services/data/v24.0');
req.setMethod('GET');
System.debug('Token in root() - '+token); //Getting this value from "https://login.salesforce.com/services/oauth2/token" call
String authVal = 'OAuth '+token;
req.setHeader('Authorization',authVal);
// Invoke web service call
String result = '';
try {
res = http.send(req);
result = res.getBody();
} catch(System.CalloutException e) {
System.debug(res.toString());
}
the line that says setEndoint("https://login.saleforce.com/....") can't use login.salesforce.com, it needs to be na1.salesforce.com, or whichever instance your org is on (this is part of the token response if you want to discover it dynamically)
All Answers
Only authentication services are available at login.salesforce.com, if you want to access the regular rest api then you need to use the correct instanceUrl/hostname for the user you're using.
Thanks Simon, can you be litle more elaborate if possible with what you want me to change to make it work?
What I am trying currently is -
In my developer Org, I am trying to run the basic REST calls (from same Org APEX class/VF) like generating token, making root call, query calls etc.
I am successfull in generating token but rest of the calls are not working currently with the mentioned error.
I worked with an pre-release org with same code sometime back, which used to return me correct result.
Thanks you for your help.
Regards,
Subhajit
the line that says setEndoint("https://login.saleforce.com/....") can't use login.salesforce.com, it needs to be na1.salesforce.com, or whichever instance your org is on (this is part of the token response if you want to discover it dynamically)
Thanks Simon,it works fine now, thanks for your input.
Regards,
Subhajit