Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to access JIRA API with the R package httr?

f55
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 5, 2019

I am trying to access a JIRA API with the R package httr, but I am having authentication issues and I can not access.

I could access the JIRA API with Postman. The latest official Postman release did not work (because of proxy configuration settings), but I could access the JIRA API with the beta version Postman Canary.

I have previously posted this issue in the httr github:

https://github.com/r-lib/httr/issues/584

And I have also posted this issue to the R Studio community:

https://community.rstudio.com/t/httr-authentication-issue-to-access-jira-api/27685

 

I think it is also a good idea to post this issue in the JIRA community, as someone may have experience with both JIRA APIs and the R package httr. I am copying below the same text I used in the previous postings.

 

I am trying to access a JIRA API with httr in R and I am having authentication issues.
I am also using proxy at work, but I found this link (#417) very useful (thank you!), because I could solve the proxy authentication error (407),.. but now I have error 401.

I am using the following code:

library(httr)
library(jsonlite)

url_jira_ini<-"https://jira.host/jira/rest/auth/1/session"
url_jira<-"https://jira.host/jira/rest/api/2/long_name"

credentials<-"username:password"
credentials <- base64_enc(credentials)
header_auth <- paste0("Basic ",credentials)

GET(url_jira,
add_headers(Authorization = header_auth),
set_cookies(atlassian.xsrf.token = "long_cookie_1",
JSESSIONID = "long_cookie_2"),
authenticate(user = "myusername",password = "mypassword",type="basic"),use_proxy("proxy.host",8080,username="myusername",password="mypassword", auth="basic"),verbose(),accept_json())

But after that I am getting error 401. I have tried without adding add_headers and set_cookies, but it still gives the same error.

I have tried to modify the use_proxy username and password and gives proxy authentication error (407) when I am using the wrong username and password (401 if they are correct).

But if I modify the username and password in the authenticate section, when I use wrong password and username it still gives error 401 (if the use_proxy section is using the correct username and password). When I use the correct password and username in authenticate also gives error 401.

In the first lines of the verbose output, it says 200 connection established, but in the following lines it appears status 401.

I could access to the JIRA API successfully using Postman (not the latest official Postman release, but a beta version, Postman Canary, which allowed to configure proxy with authentication). To access with Postman I had to first send a POST to url_jira_ini (the authentication site), and after that it generates 2 cookies (atlassian.xsrf.token and JSESSIONID), then I could send a GET to url_jira (the JIRA API that I want to access), which is using basic authentication and the cookie JSESSIONID to access the JIRA API.

In Postman, I have to add the following line in the body (raw):

{"username": "myusername" , "password" : "mypassword" }

Would it be possible to add a body in httr, keeping exactly the same line above used in Postman?
I tried to create a body (list) with that line, but it gives error. Any suggestions?

In case it may be useful, to access the JIRA API in Postman Canary (after configuring the proxy for authentication), I followed the next steps:

  • Delete all cookies previously generated by JIRA.
  • In the Authorization section, add Authorization "BasicAuth", and include username and password.
  • In the Body section, select "Raw" and "JSON (application/json)". And in the Body add the following text:
    {"username": "myusername" , "password" : "mypassword" }
  • Send a POST to the JIRA API authentication (url_jira_ini)
  • Check if it gives 200, and that it gives a JSESSIONID in the cookies (token needed to access the JIRA API).
  • Send a GET to the JIRA API (url_jira)

What should I do to access the JIRA API with httr?
Should I add additional headers in httr?

Please let me know if you need more information.
I need to solve this issue as soon as possible.
Thank you.

 

 

 

 

 

3 answers

0 votes
Rajkumar Balakrishnan October 24, 2021

Same here! It is so frustrating.

0 votes
Josh Merrell
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 4, 2021 edited

Is that URL something you can access in your internet browse? I get a 404 Not Found when I visit https://jira.host/jira/rest/api/2/long_name in Google Chrome.

When I use https://<my-team>.atlassian.net/jira/your-work  as the URL, the following returns a 200 OK:

GET(
url_jira,
add_headers(
Accept = "text/plain",
Authorization = credentials
),
authenticate(
user = my_username,
password = my_password,
type="basic"),
verbose(),
accept_json()
)

Of course, parsing the output is its own challenge.

And I can't use this to access https://<my_team>.atlassian.net/browse/<my_issue> - that gives me a 302 Found error with an `Error in curl::curl_fetch_memory(url, handle = handle) : URL using bad/illegal format or missing URL`. 

0 votes
Eric Morrow
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 22, 2019

I'm having the same issue.  I've used a similar connection setup in the past, but all of a sudden it does not work.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian community, loom ai, atlassian loom ai, loom, atlassian ai, record recaps of meetings, meeting recaps, loom recaps, share meeting recaps,

Loom’s guide to great meetings 📹

Join us to learn how your team can stay fully engaged in meetings without worrying about writing everything down. Dive into Loom's newest feature, Loom AI for meetings, which automatically takes notes and tracks action items.

Register today!
AUG Leaders

Atlassian Community Events