+ Start a Discussion
ugougo 

OAuth problem

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

 

curl -k https://login.salesforce.com/services/oauth2/token -d "grant_type=password" -d "client_id=[clientid]" -d "client_secret=[clientsecret]" -d "username=[myusername]" -d "password=[mypassword][mysecuritytoken]"

 

which returns

 

{"id":"https://login.salesforce.com/id/00Di0000000JgfhEAC/005i0000000dbdwAAA",
"issued_at":"1366942091291",
"instance_url":"https://na15.salesforce.com",
"signature":"yZsqE5VvYAZb+2dVw2zUNFsTllZxy9JjZBMFxYIGcAI=",
"access_token":"00D...vZ1"}

 

Then I do

 

curl -k https://na15.salesforce.com/services/data/v27.0/chatter/users/me -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?

jody_blyjody_bly

Have you gone through the Chatter REST API quick start? 

http://www.salesforce.com/us/developer/docs/chatterapi/Content/quickstart.htm

 

 

ugougo

Yes, I have

jody_blyjody_bly

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 https://na15.salesforce.com/services/data/v27.0/chatter/users/me -H 'Authorization: Bearer 00D...k1k'

ugougo

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

jody_blyjody_bly

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

http://wiki.developerforce.com/page/Workbench

 

 

ugougo

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
15.salesforce.com/services/data/v27.0/chatter/users/me -H 'Authorization: Bearer
 00D...B1Q'

 

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.

jody_blyjody_bly

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

ugougo

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.

jody_blyjody_bly
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.)