0

Error: {"error":"unsupported_grant_type","error_description":"grant type not supported"}

Code:

String username     = '****@gmail.com';
String password     = '***********WwmQ***';
String endPoint     = 'https://test.salesforce.com/services/oauth2/token';
String clientid  = '****************';
String clientsecret = '****************8';
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(endPoint);
req.setMethod('POST');
req.setHeader('Content-Type','application/json');
req.setBody('grant_type=password'+'&client_id='+clientid+'&client_secret='+clientsecret +'&username='+username+'&password='+password);
HttpResponse res = http.send(req);
System.debug('Body ' + res.getStatusCode());
2
  • You have the wrong Content-Type, you should be using application/x-www-form-urlencoded Commented Feb 1, 2019 at 6:57
  • i changed the Content-Type but still it is not working Commented Feb 1, 2019 at 7:37

1 Answer 1

0

I guess you are not appending security token to your password string.

Please check below article from Salesforce.

You must append the user’s security token to their password A security token is an automatically-generated key from Salesforce. For example, if a user's password is mypassword, and their security token is XXXXXXXXXX, then the value provided for this parmeter must be mypasswordXXXXXXXXXX. For more information on security tokens see “Reset Your Security Token” in the online help.

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_username_password_oauth_flow.htm

1
  • In Password i have given "Reset security token" of the user Commented Feb 1, 2019 at 7:34

You must log in to answer this question.

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