40

Is it possible to create an issue in jira using REST api? I didn't find this in the documentation (no POST for issues), but I suspect it's possible.

A wget or curl example would be nice.

9 Answers 9

40

POST to this URL

https://<JIRA_HOST>/rest/api/2/issue/

This data:

{
"fields": {
   "project":
   { 
      "key": "<PROJECT_KEY>"
   },
   "summary": "REST EXAMPLE",
   "description": "Creating an issue via REST API",
   "issuetype": {
      "name": "Bug"
   }
  }
}

In received answer will be ID and key of your ISSUE:

{"id":"83336","key":"PROJECT_KEY-4","self":"https://<JIRA_HOST>/rest/api/2/issue/83336"}

Don't forget about authorization. I used HTTP-Basic one.

10
  • Can you tell me more about the authorization you mentioned? Is there any need to pass the username & password of the project owner? Or would REST accept the POST with just the URL, Header (json) and Data?
    – Tru
    Apr 5, 2013 at 12:44
  • I'm actually getting an error saying "400 Bad Request...field: summary cannot be set"
    – Tru
    Apr 5, 2013 at 12:46
  • 1
    @Tru yes. HTTP-Basic autorization is type of autorization. AFAIK there is another possible options for autorization. From manual: The prefered authentication methods are HTTP Basic (when using SSL) and OAuth, which are both documented in the JIRA REST API Tutorials. Other supported methods include: HTTP Cookies, Trusted Applications, and os_username/os_password query parameters.
    – msangel
    Apr 5, 2013 at 15:17
  • Could you write an example of the exact curl call to use with the HTTP Basic authorization?
    – FORTRAN
    Apr 29, 2014 at 19:08
  • curl -D- -u fred:fred -X GET -H "Content-Type: application/json" kelpie9:8081/rest/api/2/issue/createmeta
    – Alaa-GI
    Apr 14, 2015 at 8:44
9

The REST API in JIRA 5.0 contains methods for creating tasks and subtasks.

(At time of writing, 5.0 is not yet released, although you can access 5.0-m4 from the EAP page. The doco for create-issue in 5.0-m4 is here).

7

As of the latest released version (4.3.3) it is not possible to do using the REST API. You can create issues remotely using the JIRA SOAP API.

See this page for an example Java client.

1
  • For some reason (lack of standard compliance), the soap api implies a dependency on axis, specifically. I can't introduce this in my application. I'm quite sure there is a way (possibly: writing a jira plugin, which I'll do if I don't have any better solution).
    – ymajoros
    May 5, 2011 at 7:04
4

This is C# code:

string postUrl = "https://netstarter.jira.com/rest/api/latest/issue";

var httpWebRequest = (HttpWebRequest)WebRequest.Create(postUrl);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
httpWebRequest.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes("JIRAMMS:JIRAMMS"));

using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
    string json = @"{""fields"":{""project"":{""key"": ""JAPI""},""summary"": ""REST EXAMPLE"",""description"": ""Creating an issue via REST API 2"",""issuetype"": {""name"": ""Bug""}}}";

    streamWriter.Write(json);
    streamWriter.Flush();
    streamWriter.Close();

    var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
    {
        var result = streamReader.ReadToEnd();
    }
}
3

To answer the question more direct, i.e. using cURL.

To use cURL to access JIRA REST API in creating a case, use

curl -D- -u <username>:<password> -X POST --data-binary "@<filename>"  -H "Content-Type: application/json" http://<jira-host>/rest/api/2/issue/

And save this in your < Filename> (please edit the field per your Jira case) and save in the folder you call the cURL command above.

{
    "fields": {
       "project":
       { 
           "key": "<PROJECT_KEY>"
       },
       "summary": "REST EXAMPLE",
       "description": "Creating an issue via REST API",
       "issuetype": {
           "name": "Bug"
       }
   }
}

This should works. (note sometimes if it errors, possibly your content in the Filename is incorrect).

2

Now you can use REST + JSON to create issues.

To check which json fields you can set to create the issue use: https://jira.host.com/rest/api/2/issue/createmeta

For more information please see the JIRA rest documentation: https://docs.atlassian.com/jira/REST/6.2.4/

1
  • The ability to use the REST API to do more than read data was part of JIRA 5.x for anyone who wants to know. The REST API hasn't changed that much since then.
    – mdoar
    May 8, 2014 at 17:28
1

To send the issue data with REST API we need to construct a valid JSON string comprising of issue details.

A basic example of JSON string:

 {“fields” : { “project” : { “key” : “@KEY@” } , “issuetype” : { “name” : “@IssueType@” } } }

Now, establish connection to JIRA and check for the user authentication. Once authentication is established, we POST the REST API + JSON string via XMLHTTP method. Process back the response and intimate user about the success or failure of the response.

So here JiraService being an XMLHTTP object, something like this will add an issue, where EncodeBase64 is a function which returns encrypted string.

Public Function addJIRAIssue() as String
With JiraService
    .Open "POST", <YOUR_JIRA_URL> & "/rest/api/2/issue/", False
    .setRequestHeader "Content-Type", "application/json"
    .setRequestHeader "Accept", "application/json"
    .setRequestHeader "Authorization", "Basic " & EncodeBase64
    .send YOUR_JSON_STRING

    If .Status <> 401 Then
        addJIRAIssue = .responseText
    Else
        addJIRAIssue = "Error: Invalid Credentials!"
    End If

End With

Set JiraService = Nothing
End Sub

You can check out a complete VBA example here

2
  • Thanks, but I accepted an answer 2 years ago and I'll stick with it. I was interested in the API doc, not really in a vb example (i.e. the only thing I was interested in was what would be in YOUR_JSON_STRING here).
    – ymajoros
    Sep 3, 2014 at 10:53
  • 3
    sure, no issues. just wanted to post the answer so that when some one with VBA and JIRA needs come to this link, they might find this useful . I agree with you and the accepted answer is perfect.
    – cyboashu
    Sep 3, 2014 at 13:09
1

In order to create an issue, set a time estimate and assign it to yourself, use this:

  1. Generate an Atlassian token

  2. Generate & save a base64-encoded auth token:

    export b64token="$(echo "<your_email>:<generated_token>" | openssl base64)"

  3. Make a POST request:

curl -X POST \
  https://<your_jira_host>.atlassian.net/rest/api/2/issue/ \
     -H 'Accept: */*' \
     -H 'Authorization: Basic $b64token \
     -d '{
       "fields":{
         "project":{
           "key":"<your_project_key (*)>"
         },
         "issuetype":{
           "name":"Task"
         },
         "timetracking":{
           "remainingEstimate":"24h"
        },
         "assignee":{
           "name":"<your_name (**)>"
       },
       "summary":"Endpoint Development"
     }
   }'

Remarks:

(*) Usually a short, capitalized version of the project description such as: ...atlassian.net/projects/UP/.

(**) if you don't know your JIRA name, cURL GET with the same Authorization as above to https://<your_jira_host>.atlassian.net/rest/api/2/search?jql=project=<any_project_name> and look for issues.fields.assignee.name.

0

Just stumbling on this and am having issues creating an issue via the REST API.

issue_dict = {
    'project': {'key': "<Key>"},
    'summary': 'New issue from jira-python',
    'description': 'Look into this one',
    'issuetype': {'name': 'Test'},
}
new_issue = jira.create_issue(issue_dict)

new_issue returns an already existing issue and doesn't create one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.