function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

OAuth problem

I use the password flow to get the access token like this:


curl -k -d "grant_type=password" -d "client_id=[clientid]" -d "client_secret=[clientsecret]" -d "username=[myusername]" -d "password=[mypassword][mysecuritytoken]"


which returns




Then I do


curl -k -H 'Authorization: Bearer 00D...vZ1'


but I get this error response:


[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]

curl: (6) Could not resolve host: Bearer
curl: (6) Could not resolve host: 00D...vZ1'


Any idea of what is wrong?


Have you gone through the Chatter REST API quick start?




Yes, I have


I saw the same behavior you're seeing, but unfortunately I can't reproduce it consistently. 


I created this cURL request in a plain text editor then copied it into Terminal and got a successful response: 

curl -k -H 'Authorization: Bearer 00D...k1k'


I just tried the same, but it did not work for me.


Do I have to set something before doing the call, like adding my IP address to Salesforce's trusted network? (I actually did that, but it did not help).


Can you try using Workbench to see if you're able to make requests:




I just tried using the Workbench REST Explorer, and it worked just fine: I got all my correct user information back


Then I tried again what I believe is the exactly equivalent curl command, like this:


C:\Tools\Curl\curl-7.30.0-ssl-sspi-zlib-static-bin-w32>  curl -k -X GET https://na -H 'Authorization: Bearer


and I get the response

[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]curl:
 (6) Could not resolve host: Bearer
curl: (6) Could not resolve host: 00D...B1Q'


So I am not sure what is the problem with my curl command.


Hmmm. I'm not a cURL expert -- hopefully someone else will jump in. Glad you can use Workbench, tho. Hopefully that will be helpful. 


I finally got it to work. I don't think I did anything different, it just started to work. I have no clue of what the difference could be.

Glad it started working but wish we knew why - looks like we both experienced the issue.
Eric Hirst 2Eric Hirst 2
I ran into similar issues last week working with some of the SF Trailhead examples.  The problem is pretty simple: a lot of the SF documentation uses single quotes around curl arguments, but when you use curl on Windows you need to wrap arguments in double quotes.

So -H 'Authorization: Bearer 00D...B1Q' should instead be -H "Authorization: Bearer 00D...B1Q" in this example.

(I realize this is an ancient question which has been answered elsewhere, but the answer currently doesn't come up easily in search results.)