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'

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;

    rest = CkRest_Create();

    //  URL: https://your-domain.atlassian.net/rest/api/2/issue/SCRUM-15
    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,"update.summary[0].set","Bug in business logic");
    CkJsonObject_UpdateString(json,"update.labels[0].add","triaged");
    CkJsonObject_UpdateString(json,"update.labels[1].remove","blocker");
    CkJsonObject_UpdateNumber(json,"fields.customfield_10010","1");
    CkJsonObject_UpdateString(json,"historyMetadata.type","myplugin:type");
    CkJsonObject_UpdateString(json,"historyMetadata.description","text description");
    CkJsonObject_UpdateString(json,"historyMetadata.descriptionKey","plugin.changereason.i18.key");
    CkJsonObject_UpdateString(json,"historyMetadata.activityDescription","text description");
    CkJsonObject_UpdateString(json,"historyMetadata.activityDescriptionKey","plugin.activity.i18.key");
    CkJsonObject_UpdateString(json,"historyMetadata.actor.id","tony");
    CkJsonObject_UpdateString(json,"historyMetadata.actor.displayName","Tony");
    CkJsonObject_UpdateString(json,"historyMetadata.actor.type","mysystem-user");
    CkJsonObject_UpdateString(json,"historyMetadata.actor.avatarUrl","http://mysystem/avatar/tony.jpg");
    CkJsonObject_UpdateString(json,"historyMetadata.actor.url","http://mysystem/users/tony");
    CkJsonObject_UpdateString(json,"historyMetadata.generator.id","mysystem-1");
    CkJsonObject_UpdateString(json,"historyMetadata.generator.type","mysystem-application");
    CkJsonObject_UpdateString(json,"historyMetadata.cause.id","myevent");
    CkJsonObject_UpdateString(json,"historyMetadata.cause.type","mysystem-event");
    CkJsonObject_UpdateString(json,"historyMetadata.extraData.keyvalue","extra data");
    CkJsonObject_UpdateString(json,"historyMetadata.extraData.goes","here");
    CkJsonObject_UpdateString(json,"properties[0].key","key1");
    CkJsonObject_UpdateString(json,"properties[0].value","can be set at issue create or update time");
    CkJsonObject_UpdateString(json,"properties[1].key","key2");
    CkJsonObject_UpdateString(json,"properties[1].value","and there can be multiple properties");

    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,"PUT","/rest/api/2/issue/SCRUM-15",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;
    }



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

    }