title: How to get and use Rundeck JSESSIONID
body: <p>I am trying to get the a valid session id but so far with no success.</p>
  
  <p>I am trying to work with the rundeck API, with <a href="http://rundeck.org/docs/api/#password-authentication" rel="nofollow noreferrer">password authentication</a>:</p>
  
  <blockquote>
    <p>To submit authentication, submit a POST request to the URL:
    $RUNDECK_SERVER_URL/j_security_check </p>
    
    <p>With these parameters:
    j_username: rundeck username j_password: password</p>
  </blockquote>
  
  <p>Like the docs suggest, I am running:</p>
  
  <pre><code>&gt;&gt;&gt; import request
  &gt;&gt;&gt; jsessionid = requests.post("http://localhost:4440/j_security_check", data=
  {"j_username": "admin", "j_password": "admin" }, 
  allow_redirects=False).cookies['JSESSIONID']
  </code></pre>
  
  <p>Resulting the log:</p>
  
  <pre><code>09/04/2017 03:22:59 PM - DEBUG - Starting new HTTP connection (1): 
  10.200.101.21
  09/04/2017 03:22:59 PM - DEBUG - http://localhost:4440 "POST 
  /j_security_check?j_username=admin&amp;j_password=admin HTTP/1.1" 302 0
  </code></pre>
  
  <p>But the <code>jsessionid</code> is never valid for the next api calls, for example:</p>
  
  <pre><code>&gt;&gt;&gt; response = requests.post("http://localhost:4440/api/14/project/my_project/hi
  story" , headers={ "Content-Type": 'application/xml', 'X-Rundeck-
  Auth-Token': jsessionid })
  &gt;&gt;&gt; response.content
  "&lt;result error='true' apiversion='20'&gt;&lt;error code='unauthorized'&gt;
  &lt;message&gt;(Token:lhefo****) is not authorized for: /api/14/project/weekly_builds/history&lt;/message&gt;&lt;/error&gt;&lt;/result&gt;"
  </code></pre>
  
  <p>However, if for <code>jsessionid</code> I am using the token I can see in the Rundeck UI (in <a href="http://localhost:4440/user/profile" rel="nofollow noreferrer">http://localhost:4440/user/profile</a>), then the API call works good and I get the history.</p>
  
  <p>Any ideas of what I am doing wrong? Or what I am missing?</p>
  
  <p>Thanks.</p>