How do I talk to the REST API of a JIRA installation that runs on a remote server?
Details
I’d like to work through this little example of how to interact with JIRA’s REST API.
This is the request I’d like to issue:
curl -u admin:admin -X POST --data @data.txt -H "Content-Type: application/json" http://localhost:2990/jira/rest/api/2/issue/
My JIRA application runs on an AWS machine with, say, the following URL:
http://aws-url:8080
This is the R call I used for sending the POST request:
httr::POST("http://aws-url:8080/jira/rest/api/2/issue/",
"-u" = "myuser:mypassword",
"--data" = "@data.json",
"-H" = "Content-Type: application/json")
However, I get the following 404
response:
Response [http://aws-url:8080/jira/rest/api/2/issue/]
Date: 2016-07-15 14:28
Status: 404
Content-Type: text/html;charset=UTF-8
Size: 2.76 kB
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-C...
<ul class="atlassian-footer">
<li>
Atlassian JIRA <a class="seo-link" rel="nofollow" href="https://www.atlassi...
<span id="footer-build-information">(v7.1.9#71013-<span title='1aa0586d78ef...
...
So I’m guessing I either misspecified the URL (or am still misunderstanding how the REST API of my JIRA instance needs to be contacted) and/or misspecified the call to POST
?
Sorry, not really familiar with the whole web technology stack yet. The question is related to this one
Update
Tried this request instead, but got the same result:
httr::POST(url,
body = "-u myuser:mypassword --data @data.json",
encode = "json"
)
2
Answers
URL structure
Seems like the actual URL needs to be like this:
or
instead of
assuming that your JIRA instance runs on port
8080
I'm not quite sure why it's okay to drop the
context
(which would bejira
in my case) from the URL as this resource suggests the URL structure needs to be like this:The only explanation I have for that as a web-dev n00b is that I'm already explicitly adressing the JIRA instance by it's port number somehow? I might however be mixing up the meaning of
context
andapi-name
as well (not that deep into that stuff yet ;-)). Could it be thatapi-name
gets a default value if omitted?GET
requestThis GET request
gives me a
200
response with all the issue details of an issue that already existed.POST
requestThe actual
POST
request needs to look like this:and gives you a
201
response404 means “not found”, so there’s simply something wrong with url you use.
What do you get if you paste something like this in a browser?
Also if you access JIRA through the browser, do you use http://aws-url:8080/jira or does it have something else than /jira?