You need to sign in to do that
Don't have an account?

Getting Invalid Session ID for Rest API
Hi,
I have a created a Apex class as follows.
@RestResource(urlMapping='/showAccounts/*')
global class KarunaRESTController1
{
@HttpGet
global static LIST<Account> getAccounts()
{
List<Account> lst;
try
{
RestRequest req = RestContext.request;
String NameValue = req.params.get('name');
lst = [select name, AccountSource from Account where name=:NameValue LIMIT 100];
}
catch(Exception e)
{
system.debug('ERROR:'+e.getMessage());
}
return lst;
}
}
After successfully saving the class, when I try to invoke the url in the chorme- Rest Client, I am alwasy getting the Invalid session ID, even I pass the valid session. can you please share me how can I access my custom api.
https://na17.salesforce.com/services/apexrest/showAccounts
by passing authorization header as oauth. tried with oauth / bearer. none of them working.
I have a created a Apex class as follows.
@RestResource(urlMapping='/showAccounts/*')
global class KarunaRESTController1
{
@HttpGet
global static LIST<Account> getAccounts()
{
List<Account> lst;
try
{
RestRequest req = RestContext.request;
String NameValue = req.params.get('name');
lst = [select name, AccountSource from Account where name=:NameValue LIMIT 100];
}
catch(Exception e)
{
system.debug('ERROR:'+e.getMessage());
}
return lst;
}
}
After successfully saving the class, when I try to invoke the url in the chorme- Rest Client, I am alwasy getting the Invalid session ID, even I pass the valid session. can you please share me how can I access my custom api.
https://na17.salesforce.com/services/apexrest/showAccounts
by passing authorization header as oauth. tried with oauth / bearer. none of them working.
Can you access the API using the REST Explorer on Workbench? Where have you got your Session Id from (it sounds like there is a hidden character at the start/end)?
Also, the correct URL for your urlMapping would be "https://na17.salesforce.com/services/apexrest/showAccounts/<account_id>" if you want the API URL to be "https://na17.salesforce.com/services/apexrest/showAccounts" then you should change the url mapping to "RestResource(urlMapping='/showAccounts')"
Hope this helps...
Cheers,
James