+ Start a Discussion
gslatergslater 

INVALID_SESSION_ID message in curl when I try to call web service

I'm calling the webservice in curl like this:

 

curl "https://na12.salesforce.com/services/apexrest/****/profiledata?PARAM1=12345&PARAM2=DUMMY&LAST_SYNC_DATETIME=2012-07-22T09:00:00Z" -k -H 'Authorization: Bearer <SESSIONID> -H "X-PrettyPrint: 1"

 

where <SESSIONID> was obtained from calling UserInfo.getSessionId() from Execute Anonymous in Eclipse.

However it always fails with errorCode "INVALID_SESSION_ID" and message "Session expired or invalid".

 

Where am I going wrong?  I couldn't make sense of OAuth but I read in the docs you could just replace OAuth with Bearer and a sessionId for testing purposes.

Best Answer chosen by Admin (Salesforce Developers) 
sf_evolutionsf_evolution

Hi-

There obviously are multiple ways to do this, but my best bet was to always use the XML interface.

 

CURL -k "https://www.salesforce.com/services/Soap/c/6.0" -H "Content-Type: text/xml" -H "SoapAction: \"\"" -d "<?xml version='1.0' encoding='utf-8'?> <soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'> <soap:Body> <login xmlns='urn:enterprise.soap.sforce.com'> <username>joeUser</username><password>joesPasswordAndTOKEN</password> </login> </soap:Body> </soap:Envelope> "

 

 

...Notice "joesPasswordAndTOKEN"   - you have to pass both your password and token.

 

 

 

All Answers

sf_evolutionsf_evolution

Hi-

There obviously are multiple ways to do this, but my best bet was to always use the XML interface.

 

CURL -k "https://www.salesforce.com/services/Soap/c/6.0" -H "Content-Type: text/xml" -H "SoapAction: \"\"" -d "<?xml version='1.0' encoding='utf-8'?> <soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'> <soap:Body> <login xmlns='urn:enterprise.soap.sforce.com'> <username>joeUser</username><password>joesPasswordAndTOKEN</password> </login> </soap:Body> </soap:Envelope> "

 

 

...Notice "joesPasswordAndTOKEN"   - you have to pass both your password and token.

 

 

 

This was selected as the best answer
WEN JIEWEN JIE

Hi gslater,

 

Try this :

curl -X GET https://ap1.salesforce.com/services/data/v23.0/ -H "Authorization: OAuth Access_Token" -H "X-PrettyPrint:1"

 

 

Thank you!