Visual FoxPro 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'

Visual FoxPro Example

LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJsonResponse
LOCAL lcId
LOCAL lcKey
LOCAL lcSelf

loRest = CreateObject('Chilkat_9_5_0.Rest')

*  URL: https://your-domain.atlassian.net/rest/api/2/issue
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("your-domain.atlassian.net",lnPort,lnBTls,lnBAutoReconnect)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

loRest.SetAuthBasic("jira@example.com","JIRA_API_TOKEN")

loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.UpdateString("fields.project.id","10000")
loJson.UpdateString("fields.summary","something is wrong")
loJson.UpdateString("fields.issuetype.id","10000")
loJson.UpdateString("fields.assignee.name","matt")
loJson.UpdateString("fields.priority.id","3")
loJson.UpdateString("fields.labels[0]","bugfix")
loJson.UpdateString("fields.labels[1]","blitz_test")
loJson.UpdateString("fields.description","description")
loJson.UpdateString("fields.fixVersions[0].id","10001")
loJson.UpdateString("fields.customfield_10005","blah blah")

loRest.AddHeader("Content-Type","application/json")
loRest.AddHeader("Accept","application/json")

loSbRequestBody = CreateObject('Chilkat_9_5_0.StringBuilder')
loJson.EmitSb(loSbRequestBody)
loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestSb("POST","/rest/api/2/issue",loSbRequestBody,loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

lnRespStatusCode = loRest.ResponseStatusCode
IF (lnRespStatusCode >= 400) THEN
    ? "Response Status Code = " + STR(lnRespStatusCode)
    ? "Response Header:"
    ? loRest.ResponseHeader
    ? "Response Body:"
    ? loSbResponseBody.GetAsString()
    RELEASE loRest
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJsonResponse = CreateObject('Chilkat_9_5_0.JsonObject')
loJsonResponse.LoadSb(loSbResponseBody)

lcId = loJsonResponse.StringOf("id")
lcKey = loJsonResponse.StringOf("key")
lcSelf = loJsonResponse.StringOf("self")

RELEASE loRest
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody
RELEASE loJsonResponse

Sample JSON Response Body

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