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
grahamjroygrahamjroy 

Invalid Session ID with Curl

Hi.

 

I have an application (built in Ruby) that logs into my saleforce account and retrieves the token in the response. When I try and use this token with curl however I am always just getting the error that:

 

 

  "message" : "Session expired or invalid",
  "errorCode" : "INVALID_SESSION_ID"

 

 

I have seen a couple of other posts that I have tried to revolve the problem with:

 

I definitely have the user set up with API access as per here

 

I also have an escaping character in the token which I am handling using a variable on my machine as per here

 

So my steps are:

 

I have a Ruby on Rails app that redirects me to salesforce and make me log in. The callback URL is then triggered which returns my token (with the escape character) like nnnnnnnnnnnnnnnn!nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn

 

I store this token variable in my .bash_profile file as

 

export token=nnnnnnnnnnnnnnnn!nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn

 

and if I run echo $token from the console it outputs the token correctly.

 

I then try and perform a curl command to the salesforce api constructed like:

 

 

curl https://na1.salesforce.com/services/data/v20.0/ -H "Authorisation: OAuth "$token -H "X-PrettyPrint:1"

Has anyone else experienced this problem, or is there something wrong witht he way I am trying to pass the token value?

 

 

SuperfellSuperfell

You spelt Authorization wrong

grahamjroygrahamjroy

Hi

 

Thanks for the reply. I still get the same error when I spell it your way.

 

 

curl https://na11.salesforce.com/services/data/v20.0/ -H "Authorization: OAuth "$token -H "X-PrettyPrint:1"

 

 

Cheers

SuperfellSuperfell

You're missing a quote after $token, it should be. if you use -v you can see more of the request/response which will help with diagnostics.

 

curl https://na11.salesforce.com/services/data/v20.0/ -H "Authorization: OAuth "$token" -H "X-PrettyPrint:1"

SuperfellSuperfell

Also, depending on which format you're using for the oauth call, the token my be URL encoded, and need decoding before use.

Michael B.ax1212Michael B.ax1212

I'm having a similar problem, how do you determine if the token is URL encoded?  How would one decode it?

 

Thanks,

Michael

Michael B.ax1212Michael B.ax1212

Solved my own problem, was a combination of escaping the "!" and using the write server.