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
Steven MaySteven May 

Apex Web Services Trailhead/Module getting the SessionID for cURL

The "Apex Web Services" trailhead unit/module says to get the session id form the Workbench -> Session Information menu option in the connection  folder.  But I don't know if I'm doing something wrong but I don't see any session id value listed there.

So I found another simple way to get the session id to pass into cURL command line as instructed by the trailhead.

Simply copy and paste the following line into the Execute Annoymous Window of the developer console and view the log file:

System.debug('Sessionid='+UserInfo.getSessionId());

 
Sarath lohi 4Sarath lohi 4
Thanks Steven !
SandhyaSandhya (Salesforce Developers) 
Hi Steven,

You can find under info dropdown --> session information -- > connection


User-added image
Please see below screenshot.

Hope this helps you.

Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
 
Thanks and Regards
Sandhya

 
Ryan DRyan D
I was just struggling with this exact issue.  Going through the Trailhead on webservices exactly as shown in the example, got the 'invalid session id' error.  After trying different combinations of the url the solution ended up being:
  • Use the 'long' version of the session Id obtained from a system debug of UserInfo.getSessionId() (short version obtained from workbench as in the screenshot above didn't work)
  • Use single quotes in the header parameters! (same exact command failed with double quotes)
  • Put the whole command on the same line (without carriage returns).  I'm no cUrl expert but there seemed to be weird behaviour if this wasn't just right.
  • Paste the command into your terminal and press Enter
Hope you Trailheaders find this if you're struggling with the module.

Trailhead module in question: https://developer.salesforce.com/trailhead/apex_integration_services/apex_integration_webservices
Stevie DStevie D
Just a note to extend on to Ryan D. Using curl on a windows 8 x64 machine I needed to use double quotes.
So the resulting command using the long version of the session Id that worked for me was this:
curl https://yourInstance.salesforce.com/services/apexrest/Cases/<Record_ID> -H "Authorization: Bearer <your_long_session_id>" -H "X-PrettyPrint:1"



 
Ted Husted NUTed Husted NU
On a Mac, I was able to use the long form with single quotes. 

It's disappointing that this issue has gone almost a year without being addressed. 
Chris DuarteChris Duarte
Hi Ted -- we have a link in Trailhead where you can send feedback about a particular unit. Until you sent in feedback via the link today, no one had reported this issue.

The feedback link is our primary channel for accepting feedback, though we also do our best with our small team to monitor these forums, Success Community, chatter, Twitter, Facebook, and email.

I'll get your feedback assigned to the writer today. Thanks for sending in your comments.
Ted Husted NUTed Husted NU
Thanks, Chris. I'm glad you will be able to followup. I utilized the feedback link to report this issue because I'm bloody-minded. I doubt that most people realize that the feedback link can be used for defect reports, as it feels like a marketing survey. Again, thanks for following up. -Ted. Ted Husted Release Engineer NimbleUser technology. for people. 1100 Pittsford-Victor Road, Pittsford NY 14534 (585) 454-8737 thusted@nimbleuser.com http://linkedin.com/in/husted Salesforce developers - Join us on http://DreamOps.org
Ted Husted NUTed Husted NU
Now I'm doubly grateful that you are looking into my missing badges, since we're ISV AppExchange Partners and wannabe Trailblazers * https://www.salesforce.com/company/news-press/press-releases/2017/05/170502-2.jsp -Ted. Ted Husted Release Engineer NimbleUser technology. for people. 1100 Pittsford-Victor Road, Pittsford NY 14534 (585) 454-8737 thusted@nimbleuser.com http://linkedin.com/in/husted Salesforce developers - Join us on http://DreamOps.org