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

Unicode C++ Example

#include <CkRestW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    CkRestW rest;
    bool success;

    //  URL: https://your-domain.atlassian.net/rest/api/2/issue
    bool bTls = true;
    int port = 443;
    bool bAutoReconnect = true;
    success = rest.Connect(L"your-domain.atlassian.net",port,bTls,bAutoReconnect);
    if (success != true) {
        wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

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

    CkJsonObjectW json;
    json.UpdateString(L"fields.project.id",L"10000");
    json.UpdateString(L"fields.summary",L"something is wrong");
    json.UpdateString(L"fields.issuetype.id",L"10000");
    json.UpdateString(L"fields.assignee.name",L"matt");
    json.UpdateString(L"fields.priority.id",L"3");
    json.UpdateString(L"fields.labels[0]",L"bugfix");
    json.UpdateString(L"fields.labels[1]",L"blitz_test");
    json.UpdateString(L"fields.description",L"description");
    json.UpdateString(L"fields.fixVersions[0].id",L"10001");
    json.UpdateString(L"fields.customfield_10005",L"blah blah");

    rest.AddHeader(L"Content-Type",L"application/json");
    rest.AddHeader(L"Accept",L"application/json");

    CkStringBuilderW sbRequestBody;
    json.EmitSb(sbRequestBody);
    CkStringBuilderW sbResponseBody;
    success = rest.FullRequestSb(L"POST",L"/rest/api/2/issue",sbRequestBody,sbResponseBody);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    int respStatusCode = rest.get_ResponseStatusCode();
    if (respStatusCode >= 400) {
        wprintf(L"Response Status Code = %d\n",respStatusCode);
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",rest.responseHeader());
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",sbResponseBody.getAsString());
        return;
    }

    CkJsonObjectW jsonResponse;
    jsonResponse.LoadSb(sbResponseBody);

    const wchar_t *id = 0;
    const wchar_t *key = 0;
    const wchar_t *self = 0;

    id = jsonResponse.stringOf(L"id");
    key = jsonResponse.stringOf(L"key");
    self = jsonResponse.stringOf(L"self");
    }

Sample JSON Response Body

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