Snippets

Adaptavist ScriptRunner For Jira Cloud Create An Issue With A Label From The Script Console

You are viewing an old version of this snippet. View the current version.
Revised by Kristian Walker c6721da
// Replace Demo below with the ID of your project
def projectKey = 'Demo'
def taskType = get('/rest/api/2/issuetype').asObject(List).body.find { it['name'] == 'Task' }['id']

post('/rest/api/2/issue')
        .header('Content-Type', 'application/json')
        .body(
        [
                fields: [
                        summary    : 'Task Summary',
                        description: "Don't forget to do this!.",
                        // Replace customfield_12345 with the ID of your custom labels field below
                        customfield_12345: ["ALabel"],
                        project    : [
                                key: projectKey
                        ],
                        issuetype  : [
                                id: taskType
                        ]
                ]
        ])
        .asString().body
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.