I'm trying to use the REST API with OAuth2 in PHP. The problem is that I followed this tutorial : http://developer.force.com/cookbook/recipe/interact-with-the-forcecom-rest-api-from-php And when I try to run my this code I have this error :

Client error: `POST https://login.salesforce.com/services/oauth2/token` resulted in a `400 Bad Request` 

response: {"error":"invalid_grant","error_description":"expired authorization code"}

I suppose that I need to configure something on my Salesforces Connected App but after around 3h of googling I can't find where is my problem.

Do you have an idea?


  • 1
    Did you call /services/oauth2/authorize first? You need get your authorization token first, then call back to get your access token. Make sure you're getting a authorization token back.
    – sfdcfox
    Feb 26, 2018 at 16:49
  • Actually I'm using Laravel and github.com/omniphx/forrest. The first call is to /services/oauth2/authorize (where I log in) and my second call is to /services/oauth2/token and it's at this step that I have this error message. Feb 26, 2018 at 16:54
  • @sfdcfox I still have this message after a new day of research Feb 27, 2018 at 14:21

1 Answer 1


I resolved my problem, I already used my authorization token previously in my code.

  • could you please explain more your answer? I am having same issue, once you authorize how cna you get the auth token?
    – manza
    Jan 31, 2020 at 3:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.