Loading

This session is not valid for use with the REST API" Error When Using client_credentials Grant Type in Postman

Fecha de publicación: May 3, 2026
Descripción

When using the client_credentials OAuth grant type in Postman to call a custom Apex REST endpoint, a "401 Unauthorized — This session is not valid for use with the REST API" error may occur even when an access token is successfully obtained. This error occurs because the Connected App configured for the client_credentials grant type is missing the "Managed user data via APIs (API)" OAuth scope. Without this scope, access tokens generated via the client_credentials flow are not authorized to call REST API endpoints, including custom Apex REST classes at /services/apexrest/.

Screenshot showing a 401 Unauthorized error response in Postman when calling a custom Apex REST endpoint. The response body displays: This session is not valid for use with the REST API.

Solución

To resolve the "401 Unauthorized — This session is not valid for use with the REST API" error when using the client_credentials grant type, add the required OAuth scope to the Connected App:


1. Add the 'Managed user data via APIs (API)' OAuth scope to the connected app's selected OAuth Scopes.

2. Test the API call again using the 'client_credentials' grant type in Postman after adding the OAuth scope.

3. Save the Connected App and wait a few minutes for the change to propagate across Salesforce infrastructure, then re-test your API call      in Postman.

Número del artículo de conocimiento

005226515

 
Cargando
Salesforce Help | Article