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


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.setBody('grant_type=password'+'&client_id='+clientid+'&client_secret='+clientsecret +'&username='+username+'&password='+password);
HttpResponse res = http.send(req);
System.debug('Body ' + res.getStatusCode());
  • 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


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.


  • 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 .