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

Objective-C Example

#import <CkoRest.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.h>

CkoRest *rest = [[CkoRest alloc] init];
BOOL success;

//  URL: https://your-domain.atlassian.net/rest/api/2/issue/SCRUM-15
BOOL bTls = YES;
int port = 443;
BOOL bAutoReconnect = YES;
success = [rest Connect: @"your-domain.atlassian.net" port: [NSNumber numberWithInt: port] tls: bTls autoReconnect: bAutoReconnect];
if (success != YES) {
    NSLog(@"%@%d",@"ConnectFailReason: ",[rest.ConnectFailReason intValue]);
    NSLog(@"%@",rest.LastErrorText);
    return;
}

[rest SetAuthBasic: @"jira@example.com" password: @"JIRA_API_TOKEN"];

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

[rest AddHeader: @"Content-Type" value: @"application/json"];
[rest AddHeader: @"Accept" value: @"application/json"];

CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestSb: @"PUT" uriPath: @"/rest/api/2/issue/SCRUM-15" requestBody: sbRequestBody responseBody: sbResponseBody];
if (success != YES) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

int respStatusCode = [rest.ResponseStatusCode intValue];
if (respStatusCode >= 400) {
    NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",rest.ResponseHeader);
    NSLog(@"%@",@"Response Body:");
    NSLog(@"%@",[sbResponseBody GetAsString]);
    return;
}