Tcl Jira - Issues: Create Issue

Back to Index

Creates an issue or a sub-task from a JSON representation.

Documentation: https://developers.atlassian.com/cloud/jira/platform/rest/#api-api-2-issue-post

CURL Command

curl -X POST --user jira@example.com:JIRA_API_TOKEN \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '
    {
      "fields": {
        "project": {
          "id": "10000"
        },
        "summary": "something is wrong",
        "issuetype": {
          "id": "10000"
        },
        "assignee": {
          "name": "matt"
        },
        "priority": {
          "id": "3"
        },
        "labels": [
          "bugfix",
          "blitz_test"
        ],
        "description": "description",
        "fixVersions": [
          {
            "id": "10001"
          }
        ],
        "customfield_10005": "blah blah"
      }
    }' \
  --url 'https://your-domain.atlassian.net/rest/api/2/issue'

Tcl Example


load ./chilkat.dll

set rest [new_CkRest]

#  URL: https://your-domain.atlassian.net/rest/api/2/issue
set bTls 1
set port 443
set bAutoReconnect 1
set success [CkRest_Connect $rest "your-domain.atlassian.net" $port $bTls $bAutoReconnect]
if {[expr $success != 1]} then {
    puts "ConnectFailReason: [CkRest_ConnectFailReason $rest]"
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    exit
}

CkRest_SetAuthBasic $rest "jira@example.com" "JIRA_API_TOKEN"

set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "fields.project.id" "10000"
CkJsonObject_UpdateString $json "fields.summary" "something is wrong"
CkJsonObject_UpdateString $json "fields.issuetype.id" "10000"
CkJsonObject_UpdateString $json "fields.assignee.name" "matt"
CkJsonObject_UpdateString $json "fields.priority.id" "3"
CkJsonObject_UpdateString $json "fields.labels[0]" "bugfix"
CkJsonObject_UpdateString $json "fields.labels[1]" "blitz_test"
CkJsonObject_UpdateString $json "fields.description" "description"
CkJsonObject_UpdateString $json "fields.fixVersions[0].id" "10001"
CkJsonObject_UpdateString $json "fields.customfield_10005" "blah blah"

CkRest_AddHeader $rest "Content-Type" "application/json"
CkRest_AddHeader $rest "Accept" "application/json"

set sbRequestBody [new_CkStringBuilder]

CkJsonObject_EmitSb $json $sbRequestBody
set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestSb $rest "POST" "/rest/api/2/issue" $sbRequestBody $sbResponseBody]
if {[expr $success != 1]} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbRequestBody
    delete_CkStringBuilder $sbResponseBody
    exit
}

set respStatusCode [CkRest_ResponseStatusCode $rest]
if {[expr $respStatusCode >= 400]} then {
    puts "Response Status Code = $respStatusCode"
    puts "Response Header:"
    puts [CkRest_responseHeader $rest]
    puts "Response Body:"
    puts [CkStringBuilder_getAsString $sbResponseBody]
    delete_CkRest $rest
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbRequestBody
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jsonResponse [new_CkJsonObject]

CkJsonObject_LoadSb $jsonResponse $sbResponseBody

set id [CkJsonObject_stringOf $jsonResponse "id"]
set key [CkJsonObject_stringOf $jsonResponse "key"]
set self [CkJsonObject_stringOf $jsonResponse "self"]

delete_CkRest $rest
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jsonResponse

Sample JSON Response Body

{
  "id": "10023",
  "key": "SCRUM-24",
  "self": "https://chilkat.atlassian.net/rest/api/2/issue/10023"
}