I'm trying to get an access token using following curl:

 curl --data grant_type=password&client_id=Y&client_secret=Z&username=A&password=B+C 

where Y = Consumer Key, Z = secret, A = username and B = password and C = security token.

I get the following error:

{"error":"invalid_grant","error_description":"authentication failure"}

I followed the instructions at https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_username_password_oauth_flow.htm. If anyone can tell me what I've done wrong, it would be brilliant. I've no clue why im getting this error.

  • Are you making a POST request here? I am not sure how to make a POST request in curl, but if you are not doing it now, please check that and try. Commented May 17, 2017 at 9:35
  • 1
    @SaumyaRanjanSatapathy (from the curl man page) -d, --data <data> (HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F, --form.
    – martin
    Commented May 17, 2017 at 9:37
  • @jones this is working for me by the way. (I put the data in single quotes, but otherwise it's the same as what you have in your question)
    – martin
    Commented May 17, 2017 at 9:40
  • Thanks @martin for the clarification. I use chrome POSTMAN app for testing my services where we set the HTTP method explicitly, hence got the doubt. Commented May 17, 2017 at 9:41
  • 1
    For some reason it worked using a different CURL website, I wasn't aware it could be website specific. Sorry for the confusion.
    – jones
    Commented May 17, 2017 at 9:59

1 Answer 1


This could be related to the login issue salesforce reported as fixed, however at least on the instance I'm on this issue is still ongoing for logins through the API.

From the report on status.salesforce.com, that you can find below, using the instance url https://<yourinstance>.salesforce.com instead of https://login.salesforce.com should fix the problem.

Salesforce login error issue
May 17th 2017, 8:42 am

On May 17, 2017, The Salesforce Technology Team mitigated an intermittent login issue affecting a subset of customers. The issue began at 03:45 UTC and was resolved as of 05:47 UTC. Some customers may have experienced an intermittent error when attempting to login to test.salesforce.com or login.salesforce.com instead of directly to their instance. Thank you for your continued business and patience during this situation.

  • "using the instance url should fix the problem"? how do I obtain a instance url for my instance? I'm trying to access the api to get data to display on a website, no user login interaction
    – jones
    Commented May 17, 2017 at 9:22
  • The data is hosted on a specific instance, so logging in via the browser (using any user of the same organization) redirects you to your instance. From the URL in the browser you can obtain the instance to use. Commented May 17, 2017 at 9:28
  • Using eu2.salesforce.com/services/oauth2/token gives the same error
    – jones
    Commented May 17, 2017 at 9:40

You must log in to answer this question.

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