I am doing callout from one salesforce org to another saleforce org to get access token but i am getting this error {"error":"unsupported_grant_type","error_description":"grant type not supported"}

I tried using my domain url as well, didnt worked

In connected app i have following access Access and manage your data (api) Provide access to your data via the Web (web) Perform requests on your behalf at any time (refresh_token, offline_access) Allow access to your unique identifier (openid)

HttpRequest req = new HttpRequest();
String CLIENT_ID = 'xyz';
String CLIENT_SECRET = 'xyz';
req.setBody('grant_type=code' + '&client_id='+CLIENT_ID + 
        '&client_secret='+CLIENT_SECRET + '&redirect_uri=https://xxx.my.salesforce.com/');
Http http = new Http();
HTTPResponse response = http.send(req);
System.debug('Body ' + response.getBody());
System.debug('Status ' + response.getStatus());
System.debug('Status code ' + response.getStatusCode());

Please help. Thanks in advance.

1 Answer 1


response_type=code corresponds to the authorization grant type (flow) in oAuth. In Salesforce universe this is known as a Web Server flow. All oAuth flows follow a prescribed sequence of steps. This particular flow involves a redirect with an authorization code which you then exchange for an access token (see docs). The snippet of code you posted is not obtaining an authorization token. Instead you're attempting to get the access token as the first step and that won't work in this specific flow.

For Salesforce-to-Salesforce calls with no user "present" (user's identity is not required for authorization), JWT Bearer flow is the recommended option. A Named Credential can issue a JWT out of the box and exchange it for the access token. See the JWT Token Exchange option and related explanation in this answer for more details on how it works.

HttpRequest req = new HttpRequest();
Http http = new Http();
HTTPResponse res = http.send(req);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .