Unicode C Jira - Issues: Edit an Issue

Back to Index

Edits the issue from a JSON representation. This example updates the issue having key = "SCRUM-15". A successful update is indicated by a response status code equal to 204 with an empty response body.

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

CURL Command

curl -X PUT --user jira@example.com:JIRA_API_TOKEN \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '
    {
      "update": {
        "summary": [
          {
            "set": "Bug in business logic"
          }
        ],
        "labels": [
          {
            "add": "triaged"
          },
          {
            "remove": "blocker"
          }
        ]
      },
      "fields": {
        "customfield_10010": 1
      },
      "historyMetadata": {
        "type": "myplugin:type",
        "description": "text description",
        "descriptionKey": "plugin.changereason.i18.key",
        "activityDescription": "text description",
        "activityDescriptionKey": "plugin.activity.i18.key",
        "actor": {
          "id": "tony",
          "displayName": "Tony",
          "type": "mysystem-user",
          "avatarUrl": "http://mysystem/avatar/tony.jpg",
          "url": "http://mysystem/users/tony"
        },
        "generator": {
          "id": "mysystem-1",
          "type": "mysystem-application"
        },
        "cause": {
          "id": "myevent",
          "type": "mysystem-event"
        },
        "extraData": {
          "keyvalue": "extra data",
          "goes": "here"
        }
      },
      "properties": [
        {
          "key": "key1",
          "value": "can be set at issue create or update time"
        },
        {
          "key": "key2",
          "value": "and there can be multiple properties"
        }
      ]
    }' \
  --url 'https://your-domain.atlassian.net/rest/api/2/issue/SCRUM-15'

Unicode C Example

#include <C_CkRestW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkStringBuilderW sbResponseBody;
    int respStatusCode;

    rest = CkRestW_Create();

    //  URL: https://your-domain.atlassian.net/rest/api/2/issue/SCRUM-15
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    success = CkRestW_Connect(rest,L"your-domain.atlassian.net",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        return;
    }

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

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"update.summary[0].set",L"Bug in business logic");
    CkJsonObjectW_UpdateString(json,L"update.labels[0].add",L"triaged");
    CkJsonObjectW_UpdateString(json,L"update.labels[1].remove",L"blocker");
    CkJsonObjectW_UpdateNumber(json,L"fields.customfield_10010",L"1");
    CkJsonObjectW_UpdateString(json,L"historyMetadata.type",L"myplugin:type");
    CkJsonObjectW_UpdateString(json,L"historyMetadata.description",L"text description");
    CkJsonObjectW_UpdateString(json,L"historyMetadata.descriptionKey",L"plugin.changereason.i18.key");
    CkJsonObjectW_UpdateString(json,L"historyMetadata.activityDescription",L"text description");
    CkJsonObjectW_UpdateString(json,L"historyMetadata.activityDescriptionKey",L"plugin.activity.i18.key");
    CkJsonObjectW_UpdateString(json,L"historyMetadata.actor.id",L"tony");
    CkJsonObjectW_UpdateString(json,L"historyMetadata.actor.displayName",L"Tony");
    CkJsonObjectW_UpdateString(json,L"historyMetadata.actor.type",L"mysystem-user");
    CkJsonObjectW_UpdateString(json,L"historyMetadata.actor.avatarUrl",L"http://mysystem/avatar/tony.jpg");
    CkJsonObjectW_UpdateString(json,L"historyMetadata.actor.url",L"http://mysystem/users/tony");
    CkJsonObjectW_UpdateString(json,L"historyMetadata.generator.id",L"mysystem-1");
    CkJsonObjectW_UpdateString(json,L"historyMetadata.generator.type",L"mysystem-application");
    CkJsonObjectW_UpdateString(json,L"historyMetadata.cause.id",L"myevent");
    CkJsonObjectW_UpdateString(json,L"historyMetadata.cause.type",L"mysystem-event");
    CkJsonObjectW_UpdateString(json,L"historyMetadata.extraData.keyvalue",L"extra data");
    CkJsonObjectW_UpdateString(json,L"historyMetadata.extraData.goes",L"here");
    CkJsonObjectW_UpdateString(json,L"properties[0].key",L"key1");
    CkJsonObjectW_UpdateString(json,L"properties[0].value",L"can be set at issue create or update time");
    CkJsonObjectW_UpdateString(json,L"properties[1].key",L"key2");
    CkJsonObjectW_UpdateString(json,L"properties[1].value",L"and there can be multiple properties");

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

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);
    sbResponseBody = CkStringBuilderW_Create();
    success = CkRestW_FullRequestSb(rest,L"PUT",L"/rest/api/2/issue/SCRUM-15",sbRequestBody,sbResponseBody);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    respStatusCode = CkRestW_getResponseStatusCode(rest);
    if (respStatusCode >= 400) {
        wprintf(L"Response Status Code = %d\n",respStatusCode);
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkRestW_responseHeader(rest));
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody));
        CkRestW_Dispose(rest);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }



    CkRestW_Dispose(rest);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbRequestBody);
    CkStringBuilderW_Dispose(sbResponseBody);

    }