The problem is if you SET variable by Curlcurl, Grepgrep, Headhead or Tailtail ++ then you will have a NEW Line in the END of your variable.
To remove the NEW Line set your last Curlcurl with $session like:
curl -H "X-RestSvcSessionId: ${session//[$'\t\r\n ']}" -X GET "http://a.b.c.d:xxxx/api/jobs"
This will remove the new line and tab (if any).
I had same error: check here