C 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'

C Example

#include <C_CkRest.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkJsonObject json;
    HCkStringBuilder sbRequestBody;
    HCkStringBuilder sbResponseBody;
    int respStatusCode;
    HCkJsonObject jsonResponse;
    const char *id;
    const char *key;
    const char *self;

    rest = CkRest_Create();

    //  URL: https://your-domain.atlassian.net/rest/api/2/issue
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRest_Connect(rest,"your-domain.atlassian.net",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        return;
    }

    CkRest_SetAuthBasic(rest,"jira@example.com","JIRA_API_TOKEN");

    json = CkJsonObject_Create();
    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");

    sbRequestBody = CkStringBuilder_Create();
    CkJsonObject_EmitSb(json,sbRequestBody);
    sbResponseBody = CkStringBuilder_Create();
    success = CkRest_FullRequestSb(rest,"POST","/rest/api/2/issue",sbRequestBody,sbResponseBody);
    if (success != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    respStatusCode = CkRest_getResponseStatusCode(rest);
    if (respStatusCode >= 400) {
        printf("Response Status Code = %d\n",respStatusCode);
        printf("Response Header:\n");
        printf("%s\n",CkRest_responseHeader(rest));
        printf("Response Body:\n");
        printf("%s\n",CkStringBuilder_getAsString(sbResponseBody));
        CkRest_Dispose(rest);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    jsonResponse = CkJsonObject_Create();
    CkJsonObject_LoadSb(jsonResponse,sbResponseBody);

    id = CkJsonObject_stringOf(jsonResponse,"id");
    key = CkJsonObject_stringOf(jsonResponse,"key");
    self = CkJsonObject_stringOf(jsonResponse,"self");


    CkRest_Dispose(rest);
    CkJsonObject_Dispose(json);
    CkStringBuilder_Dispose(sbRequestBody);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jsonResponse);

    }

Sample JSON Response Body

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