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
sashamsasham 

Pls help me on this

How do i access Api (public rest api , no need acsess token ) form postmen or runscope. but i woks in workbench 
It showing an error  invalid session id . It works in production not in sanbox 
Prakash NawalePrakash Nawale
Hi Sasham,

Can you please add more details about your scenario.
sashamsasham
There is a public  custom Rest  Api(post method - login api ) (acsess token is not required, it use session id) which is in sanbox and production in salesforce . When i try to call this api in sanbox using postman , it gives me an error - "message": "Session expired or invalid",
        "errorCode": "INVALID_SESSION_ID" but it works  when i use work bench . 
I call this api in prodction using postman . it works and got the sucess message . 
It is not working in sanbox . 
 
sashamsasham
@RestResource(urlMapping='/v1/MyApi/*')
global class test_publicapi {
 @httppost
    global static void login(string email,string password)
    {        
        RestRequest req=RestContext.request;
        restresponse res=restcontext.response; 
        req.addHeader('Access-Control-Allow-Origin', '*');
         res.addHeader('Access-Control-Allow-Origin', '*');           
        req.addHeader('Access-Control-Allow-Headers', 'session_id');
        res.addHeader('Access-Control-Allow-Headers', 'session_id');
        req.addHeader('Access-Control-Expose-Headers', 'session_id');
        res.addHeader('Access-Control-Expose-Headers', 'session_id');
        string pwd; 
        boolean valid;
        JSONGenerator r=JSON.createGenerator(true);
       
        try{
             r.writeStartObject();
             r.writeStringField('status','success');
             r.writeEndObject();
        }
        catch(Exception e)
        {
            r.writeStartObject();
            r.writeStringField('status','error');
            r.writeStringField('message',e.getMessage());
            r.writeEndObject();
            res.responseBody=blob.valueof(r.getAsString());
            
        }
    }
    
    
}