You need to sign in to do that
Don't have an account?
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?
Hi Ugo,
I think you need to put the URL last on the curl command line:
Cheers,
Pat
Hi Pat,
I tried that but unfortunately it does not work either.
Ugo
What error message did you get the second time? What OS are you on - Windows/Mac/Linux? (It makes a difference in the quotes).
I am running curl-7.30.0-ssl-sspi-zlib-static-bin-w32 under win7. Here is my exact command:
curl -k -H "Authorization: Bearer 00D...tep5" -X GET https://na15.salesforce.com/services/data/v27.0/chatter/users/me
which returns exactly the following
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]
The same identical request information used under Workbench REST Explorer works just fine. So there is something wrong with the curl command I am using, but I cannot figure out what.
Hmm - tried to recreate, compensating for the different quoting on Mac OS X, but it just works:
$ curl -k -H 'Authorization: Bearer 00D...WWP' -X GET https://na9.salesforce.com/services/data/v27.0/chatter/users/me
{"address":{"state":"CA", ...LOTS MORE JSON...
Try verbose (curl -v ...) and see if there are any clues. In particular, look at how the Authorization header is being sent - check that the token is intact.
Also double check the instance - does it definitely say na15 in the OAuth response? Are you on the same IP address from which you authenticated?
I tried to get the access token using the username and password flow (instead of using the Web Server flow as I had been doing before), and then use the same curl request on the Chatter resource, and it worked.
Then I tried again my Web Server flow, and finally also that access token started to work with my curl request.
I have no clue of what might have caused it to start working. I read in another thread that somebody else noticed a similar erratic behavior ...
I know this is a very old topic, but still actual for me. I fixed is using double quotes(") arround the -H "Authorization:..." part.
This sould work:
curl -k https://na15.salesforce.com/services/data/v27.0/chatter/users/me -H "Authorization: Bearer 00D...vZ1"
Hopefully this helps someone.