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
David Bailey 16David Bailey 16 

An Apex Integration Services Module cURL Issue, Encountered, Have I

Into the Apex Integration Services module, happily, I began.

In the Apex Web Services unit, blissfully, I continued.

At the Retrieve Data with a Custom GET Method section, without incident, I arrived.

Into the Retrieve Data Using cURL sub-section, with rapt anticipation, I delved.

The cURL command line tool, dutifully, I installed.

My 
 
Session ID: 00D36000000KIKL, 
Reccord ID: 50036000003Sv7IAAS
Instance: appliedconcepts-dev-ed.my


I saved.

The
 
'curl https://appliedconcepts-dev-ed.my.salesforce.com/services/apexrest/Cases/50036000003Sv7IAAS -H "Authorization: Bearer 00D36000000KIKL" -H "X-PrettyPrint:1"'

cURL command, diligently, I constructed.

A Windows command prompt, quickly, I opened.

The 
 
"[ {
  "message" : "Session expired or invalid",
  "errorCode" : "INVALID_SESSION_ID"
} ]"

error message, sadly, I encountered.

More on cURL from the Resources section, with mounting trepidation, I perused.

At a dead-end, afterward, I am.

About what has going wrong, perplexed, I wonder.

At the foot of the Salesforce masters, humbly, now, I bow.

 
Best Answer chosen by David Bailey 16
David Bailey 16David Bailey 16
Kind Sirs (Steven May, Ryan D and Sandhya),

You have solved my problem.  Steven appears to have be the initial solver on June 12, 2016.  Ryan confirned it and Sandhya pointed me to it on July 30, 2016.  

The text in the Apex Integration Services module's Apex Web Services unit that suggests using the Session Id displayed in the Workbench for the cURL command, appears to be incorect, at least in my configuration.  That Session Id is the short-form one, and does not work, resulting in the Invalid Session Id error.  The long-form Session Id, that can be acquired by using the UserInto.getSessionId() call in, say the Developer Console's Execute Anonymous Window DOES work.

Also, the requirement mentioned in a previous post that says you must escape the exclamation point in the Session Id, is not required if you bound the Authorization string in double quotes.  In any case, here is the cURL command that works ...
 
C:\Users\David Bailey>curl https://appliedconcepts-dev-ed.my.salesforce.com/services/apexrest/Cases/50036000003Sv7IAAS -H "Authorization: Bearer 00D36000000KIKL!AQEAQJ8rqI13cSqsNjSHVcmQWMaIj0oA31BMQnMHPM.58emZGq2LGMHUXo12cEE7W3YL.kfeC8t7TYn_nGLAN2LTHCn52Ecc" -H "X-PrettyPrint:1"

And here is the resulting output ...
 
{
  "attributes" : {
    "type" : "Case",
    "url" : "/services/data/v37.0/sobjects/Case/50036000003Sv7IAAS"
  },
  "CaseNumber" : "00001035",
  "Subject" : "Bigfoot Sighting!",
  "Status" : "New",
  "Origin" : "Phone",
  "Priority" : "Low",
  "Id" : "50036000003Sv7IAAS"
}

Gentlemen, I thank you.  You can see so far into the distance when you stand on the shoulders of giants!   (:>)     Cheers.

David

All Answers

SandhyaSandhya (Salesforce Developers) 
Hi David Bailey,

You have an additional space in your call
Authorization: Bearer
to
Authorization:Bearer
the code should be
'curl https://appliedconcepts-dev-ed.my.salesforce.com/services/apexrest/Cases/50036000003Sv7IAAS -H "Authorization:Bearer 00D36000000KIKL" -H "X-PrettyPrint:1"'
I got the same error, and when I removed space, I was able to get a response.


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



 
David Bailey 16David Bailey 16
Dear Sandyha,

Thank you for your response.  I 'did' remove the space character between Authorization: and Bearer, as you suggested.  But, when I re-tried the command, I got the same error.  Perhaps the issue is something else.   By the way, I got the Session ID from the Workbench Info > Session Information > Connection > Endpoint, as instructed in the Apex Web Services Trailhead unit.  To wit ...

Session ID from Workbench Connection folder ...

The modified command I tried is now ...
 
C:\Users\David Bailey>curl https://appliedconcepts-dev-ed.my.salesforce.com/services/apexrest/Cases/50036000003Sv7IAAS -H "Authorization:Bearer 00D36000000KIKL" -H "X-PrettyPrint:1"

But the error still persists ...
 
[ {
  "message" : "Session expired or invalid",
  "errorCode" : "INVALID_SESSION_ID"
} ]

If you think of anything else, kindly let me know.  I'm pursuing further Google research as we speak.  Again, thanks,

David
David Bailey 16David Bailey 16
Kind Sirs (Steven May, Ryan D and Sandhya),

You have solved my problem.  Steven appears to have be the initial solver on June 12, 2016.  Ryan confirned it and Sandhya pointed me to it on July 30, 2016.  

The text in the Apex Integration Services module's Apex Web Services unit that suggests using the Session Id displayed in the Workbench for the cURL command, appears to be incorect, at least in my configuration.  That Session Id is the short-form one, and does not work, resulting in the Invalid Session Id error.  The long-form Session Id, that can be acquired by using the UserInto.getSessionId() call in, say the Developer Console's Execute Anonymous Window DOES work.

Also, the requirement mentioned in a previous post that says you must escape the exclamation point in the Session Id, is not required if you bound the Authorization string in double quotes.  In any case, here is the cURL command that works ...
 
C:\Users\David Bailey>curl https://appliedconcepts-dev-ed.my.salesforce.com/services/apexrest/Cases/50036000003Sv7IAAS -H "Authorization: Bearer 00D36000000KIKL!AQEAQJ8rqI13cSqsNjSHVcmQWMaIj0oA31BMQnMHPM.58emZGq2LGMHUXo12cEE7W3YL.kfeC8t7TYn_nGLAN2LTHCn52Ecc" -H "X-PrettyPrint:1"

And here is the resulting output ...
 
{
  "attributes" : {
    "type" : "Case",
    "url" : "/services/data/v37.0/sobjects/Case/50036000003Sv7IAAS"
  },
  "CaseNumber" : "00001035",
  "Subject" : "Bigfoot Sighting!",
  "Status" : "New",
  "Origin" : "Phone",
  "Priority" : "Low",
  "Id" : "50036000003Sv7IAAS"
}

Gentlemen, I thank you.  You can see so far into the distance when you stand on the shoulders of giants!   (:>)     Cheers.

David
This was selected as the best answer
Angela LockhartAngela Lockhart
I've tried both solutions and neither work for me. 
 
new-host:~ dawnlockhart$ curl https://brave-badger-214854-dev-ed.my.salesforce.com/services/apexrest/Cases/50041000003YJ2gAAG -H "Authorization:Bearer 00D41000001MR67" -H "X-PrettyPrint:1"
[ {
  "message" : "Session expired or invalid",
  "errorCode" : "INVALID_SESSION_ID"
} ]new-host:~ dawnlockhart$
new-host:~ dawnlockhart$ curl https://brave-badger-214854-dev-ed.my.salesforce.com/services/apexrest/Cases/50041000003YJ2gAAG -H "Authorization:00D41000001MR67!ARIAQO4w96smPKPaPim_WnHQVKK791ayWVneanYS8MGGArZ_UufKlMnEk9OMPE3ScoI_4ABdeydu8EsJR7P25e4FiJFG_S0e" -H "X-PrettyPrint:1"
-bash: !ARIAQO4w96smPKPaPim_WnHQVKK791ayWVneanYS8MGGArZ_UufKlMnEk9OMPE3ScoI_4ABdeydu8EsJR7P25e4FiJFG_S0e": event not found


 
Mark Brown 33Mark Brown 33
I didn't need to remove the sace between auth and Bearer but i DID have to wrap the session key in DOUBLE QUOTES