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:
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.
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`.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.