function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
karuna sunkarakaruna sunkara 

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.
Jamz_2010Jamz_2010
Hi,

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
karuna sunkarakaruna sunkara
Thanks james, Able to connect it, i forgot to add oauth, now its working fine after adding it.
Jamz_2010Jamz_2010
Thats great, if what I put helped then please mark it as the best answer :)