0% found this document useful (0 votes)
9 views

JIRA REST API Example Create Issue 7897248

The document provides an overview of using the JIRA REST API to create issues, including examples for creating standard issues, sub-tasks, and issues with custom fields. It outlines the necessary API endpoints, data formats, and responses for various scenarios. Additionally, it explains how to include time tracking information during issue creation if enabled in JIRA settings.

Uploaded by

Pawan kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

JIRA REST API Example Create Issue 7897248

The document provides an overview of using the JIRA REST API to create issues, including examples for creating standard issues, sub-tasks, and issues with custom fields. It outlines the necessary API endpoints, data formats, and responses for various scenarios. Additionally, it explains how to include time tracking information during issue creation if enabled in JIRA settings.

Uploaded by

Pawan kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

6/26/22, 8:54 PM JIRA REST API Example Create Issue 7897248

We’re making changes to our server and Data Center products, including the end of sale for new server licenses on February 2, 2021 and
the end of support for server on February 2, 2024. Learn what this means for you.

Jira Server Guides Reference Resources Search... Log in

JIRA Developer Documentation : JIRA REST API Example -


Create Issue

Applicable: JIRA 5.0 and later.

The Rest API allows you to create an issue.

The JIRA REST api allows you to easily create an issue. You can POST a single JSON document.

The examples shown here use curl with an input file denoted by the "--data @filename" syntax and the file
data is shown separately

Field meta-data for creating issues


The fields that are available when creating an issue are available via the REST API, e.g.

1 http://localhost:8090/rest/api/2/issue/createmeta
2

This will return all of the create metadata for all issue types across all projects.

You most likely want a subset of that information, for example for a specific project and issue type, which you can ask for
by specifying the project ids, project names, issue type ids, or issue type names in the URL. For example, to get the create
metadata for the Bug issue type in the JRA project:

1 http://localhost:8090/rest/api/2/issue/createmeta?projectKeys=JRA&issuetypeNames=Bug&expand=projects.
2

See the Discovering meta-data for creating issues tutorial for more information

Examples of creating an issue


Example of creating an issue using project keys and field names.
This simple create request

Request

1 curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json" http://localhost
2

Data

https://developer.atlassian.com/server/jira/platform/jira-rest-api-example-create-issue-7897248/ 1/7
6/26/22, 8:54 PM JIRA REST API Example Create Issue 7897248

1 {
2 "fields": {
"project":
{
"key": "TEST"
},
"summary": "REST ye merry gentlemen.",
"description": "Creating of an issue using project keys and issue type names using the REST AP
"issuetype": {
"name": "Bug"
}
}
}

Response

1 {
2 "id":"39000",
"key":"TEST-101",
"self":"http://localhost:8090/rest/api/2/issue/39000"
}

Example of creating an issue using project ids and issue type ids.
Programs using REST may have queried the set of projects and issue ids (for example via createmeta above), and not want
to use the names of projects or issue types. They can just as easily use ids, as in the example below:

Request

1 curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json" http://localhost
2

Data

1 {
2 "fields": {
"project":
{
"id": "10110"
},
"summary": "No REST for the Wicked.",
"description": "Creating of an issue using ids for projects and issue types using the REST API
"issuetype": {
"id": "1"
}
}
}

Response

The response provides the issue id, key, and the URL to the issue (which can then be used to GET additional data, PUT
updates, etc) via the REST API.

1 {
2 "id":"39001",
"key":"TEST-102",
"self":"http://localhost:8090/rest/api/2/issue/39001"
}

https://developer.atlassian.com/server/jira/platform/jira-rest-api-example-create-issue-7897248/ 2/7
6/26/22, 8:54 PM JIRA REST API Example Create Issue 7897248

Example of creating a sub-task


Creating a sub-task is similar to creating a regular issue, with two important differences:

the issueType field must correspond to a sub-task issue type (you can use /issue/createmeta to discover sub-
task issue types), and
you must provide a parent field in the issue create request containing the id or key of the parent issue.

Because a sub-task is essentially a special type of issue, the sub-task creation request and response are very similar to
issue creation, as you can see from the following examples.

Request

1 curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json" http://localhost
2

Data

1 {
2 "fields":
{
"project":
{
"key": "TEST"
},
"parent":
{
"key": "TEST-101"
},
"summary": "Sub-task of TEST-101",
"description": "Don't forget to do this too.",
"issuetype":
{
"id": "5"
}
}
}

Response

The response provides the sub-task id, key, and the URL to the issue (which can then be used to GET additional data, PUT
updates, etc) via the REST API.

1 {
2 "id":"39002",
"key":"TEST-103",
"self":"http://localhost:8090/rest/api/2/issue/39002"
}

Example of creating an issue using custom fields


Since custom field names are not unique within a JIRA instance, custom fields are referred to by the field ID, in the REST
API. The same custom field name would have different ids across different JIRA instances. For example, on one JIRA
instance, "Story Points" might have the id "10000" while on another instance the id might be "10101".

In REST in JIRA, customfields are referenced by "customfield_" + the id of the custom field.

So the "Story Points" custom field, with id = "10000", would be referenced as "customfield_10000" for the field name in
the JIRA REST API.

If you're looking to always set a specific field, such as "Story Points", you should first GET the createmeta information for
the issue type, and then get the appropriate custom field id for that field name.

In the example below, we have a field called "Explanation" that is a Free Text Field in JIRA, and the id of that field is 11050,
so we reference the field as "customfield_11050". Notice that the name of the field "Explanation" is not used anywhere.

https://developer.atlassian.com/server/jira/platform/jira-rest-api-example-create-issue-7897248/ 3/7
6/26/22, 8:54 PM JIRA REST API Example Create Issue 7897248
Request

1 curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json" http://localhost
2

Data

1 {
2 "fields": {
"project":
{
"key": "TEST"
},
"summary": "Always do right. This will gratify some people and astonish the REST.",
"description": "Creating an issue while setting custom field values",
"issuetype": {
"name": "Bug"
},
"customfield_11050" : "Value that we're putting into a Free Text Field."
}
}

Response

Again, the issue created is returned in the response.

1 {
2 "id":"39002",
"key":"TEST-103",
"self":"http://localhost:8090/rest/api/2/issue/TEST-103"
}

Examples of how to set custom field data for other field types:
CascadingSelectField

1 "customfield_10001": {"value": "green", "child": {"value":"blue"} }


2

The value associated with "name" ("green" in this example) is the parent option selected, then "blue" is the child option }

DatePickerField

1 "customfield_10002": "2011-10-03"
2

The format is: YYYY-MM-DD

DateTimeField

1 "customfield_10003": "2011-10-19T10:29:29.908+1100"
2

This format is ISO 8601: YYYY-MM-DDThh:mm:ss.sTZD

FreeTextField

1 "customfield_10004": "Free text goes here. Type away!"


2

GroupPicker

"customfield_10005": { "name": "jira-developers" }

https://developer.atlassian.com/server/jira/platform/jira-rest-api-example-create-issue-7897248/ 4/7
6/26/22, 8:54 PM JIRA REST API Example Create Issue 7897248

1
2

Like users, groups are specified by name (or id).

Labels

1 "customfield_10006": ["examplelabelnumber1", "examplelabelnumber2"]


2

Labels are arrays of strings

MultiGroupPicker

1 "customfield_10007": [{ "name": "admins" }, { "name": "jira-developers" }, { "name": "jira-users" }]


2

Like users, groups are specified by name, or id.

MultiSelect

1 "customfield_10008": [ {"value": "red" }, {"value": "blue" }, {"value": "green" }]


2

MultiUserPicker

1 "customfield_10009": [ {"name": "jsmith" }, {"name": "bjones" }, {"name": "tdurden" }]


2

Array of users

NumberField

1 "customfield_10010": 42.07
2

Just a number (not a number in a string)

ProjectPicker

1 "customfield_10011": { "key": "JRADEV" }


2

You can also specify the project by project ID

1 { "id":"10000" }
2

RadioButtons

1 "customfield_10012": { "value": "red" }


2

You can also specify the selection by id

SelectList

1 "customfield_10013": { "value": "red" }


2

You can also specify the selection by id

SingleVersionPicker

https://developer.atlassian.com/server/jira/platform/jira-rest-api-example-create-issue-7897248/ 5/7
6/26/22, 8:54 PM JIRA REST API Example Create Issue 7897248

1 "customfield_10014": { "name": "5.0" }


2

You can also specify the version by id

TextField

1 "customfield_10015": "Is anything better than text?"


2

URLField

1 "customfield_10016": "http://www.atlassian.com"
2

UserPicker

1 "customfield_10017": { "name":"brollins" }
2

VersionPicker

1 "customfield_10018": [{ "name": "1.0" }, { "name": "1.1.1" }, { "name": "2.0" }]


2

You can also specify a version by id

Adding a worklog entry during create


If you want to set the time tracking fields in a JIRA issue when creating the issue, the create data should include a section
like the following:

1 "timetracking":
2 {
"originalEstimate": "1d 2h",
"remainingEstimate": "3h 25m"
}

Time tracking must be enabled to set these fields. In addition, if you are using the JIRA "Legacy" time tracking mode (set
by a JIRA Administrator), then only the remaining estimate can be set, so the "originalestimate" field should not be
included in the REST request.

Request

No different from any of the other examples, the create is simply a POST:

1 curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json" http://localhost
2

Data

Again, this data is if Legacy mode for time tracking is off.

https://developer.atlassian.com/server/jira/platform/jira-rest-api-example-create-issue-7897248/ 6/7
6/26/22, 8:54 PM JIRA REST API Example Create Issue 7897248

1 {
2 "fields": {
"project":
{
"key": "TEST"
},
"summary": "Who seeks a faultless friend RESTs friendless.",
"description": "Creating an issue and setting time tracking fields",
"issuetype": {
"name": "Bug"
},
"timetracking":
{
"originalEstimate": "1d 2h",
"remainingEstimate": "3h 25m"
}
}
}

Response

1 {
2 "id":"39003",
"key":"TEST-104",
"self":"http://localhost:8090/rest/api/2/issue/TEST-104"
}

Rate this page:

System status

Privacy

Developer Terms

Trademark

© 2022 Atlassian

https://developer.atlassian.com/server/jira/platform/jira-rest-api-example-create-issue-7897248/ 7/7

You might also like