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
Jarod AJarod A 

Call Apex REST Controller Anonymously?

Hi there,

I have a question about the current capabilities of the platform, specifically whether or not it is still possible to call an Apex Class (REST Controller) WITHOUT any type of authentication token.

I'd like to do something very similar to what is described here: https://sfdcpanther.wordpress.com/2017/10/02/create-anonymous-salesforce-apex-rest-api-with-force-com-platform/comment-page-1/?unapproved=16634&moderation-hash=55f27da1ca3642e19c81c11a00c65de6#comment-16634

Unfortunately, that does not seem to work as I get a 401 Unauthorized with an error code of "INVALID_SESSION_ID" despite my attempts.  

All of the documentation I've read describes an authentication step first, so has there been some change on the SFDC side to require authentication since the blog above was posted 5 years ago (I've been unable to find a specific post that clearly states such a change, but it may be out there)?  Is there another way to accomplish anonymous access besides what was described in that blog?

Thanks in advance!
VinayVinay (Salesforce Developers) 
Hi Jarod,

REST API callouts might be performed via different internal IP addresses, INVALID_SESSION_ID might be returned when using the access token if the mentioned preference is enabled.

You would need to relax or turn off setting, check steps mentioned below to resolve the issue.

https://help.salesforce.com/s/articleView?id=000387018&type=1

Please mark as Best Answer if above information was helpful.

Thanks,