{"id":5813,"date":"2015-12-02T13:23:03","date_gmt":"2015-12-02T12:23:03","guid":{"rendered":"http:\/\/www.b.shuttle.de\/hayek\/hayek\/jochen\/wp\/blog-en\/?p=5813"},"modified":"2019-07-09T13:57:05","modified_gmt":"2019-07-09T11:57:05","slug":"jira-rest-api","status":"publish","type":"post","link":"https:\/\/wp.jochen.hayek.name\/blog-en\/2015\/12\/02\/jira-rest-api\/","title":{"rendered":"the JIRA REST API, how to authenticate, \u2026"},"content":{"rendered":"\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Jira_(software)\">https:\/\/en.wikipedia.org\/wiki\/Jira_(software)<\/a><\/li><li><a href=\"https:\/\/developer.atlassian.com\/jiradev\/jira-apis\/jira-rest-apis\/jira-rest-api-tutorials\/jira-rest-api-example-basic-authentication\">https:\/\/developer.atlassian.com\/jiradev\/jira-apis\/jira-rest-apis\/jira-rest-api-tutorials\/jira-rest-api-example-basic-authentication<\/a><\/li><li><a href=\"https:\/\/developer.atlassian.com\/jiradev\/jira-apis\/jira-rest-apis\/jira-rest-api-tutorials\/jira-rest-api-example-cookie-based-authentication\">https:\/\/developer.atlassian.com\/jiradev\/jira-apis\/jira-rest-apis\/jira-rest-api-tutorials\/jira-rest-api-example-cookie-based-authentication<\/a><\/li><li><a href=\"https:\/\/metacpan.org\/module\/json_pp\">https:\/\/metacpan.org\/module\/json_pp<\/a>&nbsp;\u2013 a nice utility, that also does JSON pretty-printing; it comes with&nbsp;<a href=\"http:\/\/search.cpan.org\/perldoc?JSON\">http:\/\/search.cpan.org\/perldoc?JSON<\/a><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">There are certainly legion of reasons to use a REST API and also to use the JIRA REST API, I wanted to create a linear &#8220;diary&#8221; of JIRA actions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is our sample JIRA issue URL:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">http:\/\/kelpie9:8081\/browse\/QA-31<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is its corresponding REST URL:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">http:\/\/kelpie9:8081\/rest\/api\/2\/issue\/QA-31<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Find yourself a working sample JIRA issue URL use the corresponding REST URL in your browser, save the JSON returned to a file!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You usually want to read &#8220;pretty&#8221; \/ tidied JSON, so before you start reading&nbsp;JSON, find yourself a JSON-tidy utility:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"http:\/\/wp.Jochen.Hayek.name\/blog-en\/tag\/json-tidy\/\">http:\/\/wp.Jochen.Hayek.name\/blog-en\/tag\/json-tidy\/<\/a><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Usually we want to retrieve JSON from JIRA through REST URLs via the curl utility.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">CAVEAT: See my note on the <em>cookie jar<\/em> below!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is the &#8220;simple example&#8221;, that the page referred to above (&#8220;<em>Basic Authentication<\/em>&#8220;) shows you:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>$ curl -D- -u fred:fred -X GET<br>\n-H \"Content-Type: application\/json\"<br>\nhttp:\/\/kelpie9:8081\/rest\/api\/2\/search?jql=assignee=fred<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If your JIRA site requires you to use &#8220;Basic Authentication&#8221;, you have to&nbsp;encode <em>username:password<\/em> base64-wise, and this is how to&nbsp;do it:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>$&nbsp;echo -n fred:fred | base64<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So if you want to use &#8220;<em>Basic Authentication<\/em>&#8221; with these credentials, this is how &#8230; (using our sample REST&nbsp;URL):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>$ curl -D- -X GET<br>\n-H \"Authorization: Basic $(echo -n fred:fred | base64)\"<br>\n-H \"Content-Type: application\/json\"<br>\n\"http:\/\/kelpie9:8081<strong>\/rest\/api\/2\/issue\/<\/strong>QA-31\"<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">During my experiments I got locked out of the company&#8217;s <em>Active Directory<\/em> \/&nbsp;<em>SSO<\/em> quite a few times &#8212; and I had to call the help desk in order to get my account reset. This is what JIRA tells you, once it decides you have to go through a&nbsp;<em>CAPTCHA_CHALLENGE<\/em> procedure, because you are behaving a little too suspicious:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>HTTP\/1.1 403 Forbidden<br>\nServer: Apache-Coyote\/1.1<br>\nX-AREQUESTID:&nbsp;...<br>\nX-Seraph-LoginReason: AUTHENTICATED_FAILED<br>\nSet-Cookie: JSESSIONID=...; Path=\/; Secure; HttpOnly<br>\nWWW-Authenticate: OAuth realm=\"https%3A%2F%2Fjira.___.com\"<br>\nX-Content-Type-Options: nosniff<br>\nX-Authentication-Denied-Reason: <strong>CAPTCHA_CHALLENGE<\/strong>; login-url=https:\/\/jira.___.com\/login.jsp<br>\nContent-Type: text\/html;charset=UTF-8<br>\nContent-Length: 6494<br>\nDate: Wed, 02 Dec 2015 11:59:15 GMT<br>\n<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But once you are beyond this, making use of&nbsp;the&nbsp;JIRA REST API works like a charm.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Update: Although I certainly had not failed (&#8220;basic&#8221;) authentication, JIRA got my Active Directory \/ SSO account locked again and again. My new strategy:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>1st logon through &#8220;basic authentication&#8221; and store the cookie jar<\/li><li>further authentications (during a script run) though the cookie stored before&nbsp;&#8212; yes, I will supply you with examples here in the near future<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Wishlist:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>instead of shell+curl use perl+libcurl<\/li><li>use the &#8220;epic link&#8221; to get the &#8220;epic link nice name&#8221; in order to describe the issue as &#8220;issue# + epic-link-nice-name + summary&#8221;<\/li><li>extend the tool to also deal with&nbsp;Atlassian Confluence<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/en.wikipedia.org\/wiki\/Jira_(software) https:\/\/developer.atlassian.com\/jiradev\/jira-apis\/jira-rest-apis\/jira-rest-api-tutorials\/jira-rest-api-example-basic-authentication https:\/\/developer.atlassian.com\/jiradev\/jira-apis\/jira-rest-apis\/jira-rest-api-tutorials\/jira-rest-api-example-cookie-based-authentication https:\/\/metacpan.org\/module\/json_pp&nbsp;\u2013 a nice utility, that also does JSON pretty-printing; it comes with&nbsp;http:\/\/search.cpan.org\/perldoc?JSON There are certainly legion of reasons to use a REST API and also to use the JIRA REST API, I wanted to create a linear &#8220;diary&#8221; of JIRA actions. This is our sample JIRA issue URL: http:\/\/kelpie9:8081\/browse\/QA-31 This is its [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false,"_share_on_mastodon":"0"},"categories":[29,289,834],"tags":[900,1126],"class_list":["post-5813","post","type-post","status-publish","format-standard","hentry","category-atlassian-jira","category-json","category-rest","tag-authentication","tag-jq"],"share_on_mastodon":{"url":"","error":""},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paO0kP-1vL","jetpack_likes_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/5813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/comments?post=5813"}],"version-history":[{"count":2,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/5813\/revisions"}],"predecessor-version":[{"id":10651,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/posts\/5813\/revisions\/10651"}],"wp:attachment":[{"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/media?parent=5813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/categories?post=5813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.jochen.hayek.name\/blog-en\/wp-json\/wp\/v2\/tags?post=5813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}