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
Janardhana ReddyJanardhana Reddy 

Session expired or invalid session when Rest API run on postman client

Hi ,
I was created rest api class below...

@RestResource(urlMapping='/sample controller/*')
global with sharing class RESTController {

  @HttpGet
  global static List<Campaign> getContacts() {
    RestRequest req = RestContext.request;
    RestResponse res = RestContext.response;
    
    String contactId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
    try{
    
    list<Campaign> camp = [SELECT id,parentid,name,program_grade_level__c,council_code__c,account__C FROM campaign WHERE id IN (SELECT campaignid from campaignmember where contactid=: contactId and active__c = true) AND job_code__c = 'DP' and Program_Grade_Level__c IN ('1-Daisy','2-Brownie','3-Junior')];
    return camp;
    }Catch(exception e){
     return null;   
    }
    
  }
}


when i am testing class through postman client getting error Session expired or invalid session.

Can help me how to solve this please.
KevinPKevinP
@RestResource methods still require an authenticated client session. You'll need to use Postman's oAuth setup, along with a connected app's oauth keys to authenticate with this call. 

Essentially, make sure you have an oAuth Access token and be sure to put it into the request headers.