Chilkat Online Tools

Objective-C / Atlassian Confluence Cloud / Update content template

Back to Collection Items

#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.h>
#import <CkoHttpResponse.h>
#import <NSString.h>

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

CkoHttp *http = [[CkoHttp alloc] init];
BOOL success;

// Use this online tool to generate code from sample JSON: Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "templateId": "<string>",
//   "name": "<string>",
//   "templateType": "<string>",
//   "body": {
//     "value": "<string>",
//     "representation": "<string>"
//   },
//   "description": "<string>",
//   "labels": [
//     {
//       "prefix": "ipsum dolor Excepteur Duis",
//       "name": "nulla et ipsum voluptate consectetur",
//       "id": "nostrud enim proident cupidatat eu",
//       "label": "enim Lorem veniam amet"
//     },
//     {
//       "prefix": "amet",
//       "name": "officia adipisicing ut labo",
//       "id": "ipsum in tempor",
//       "label": "est occaecat magna"
//     }
//   ],
//   "space": {
//     "key": "<string>"
//   }
// }

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"templateId" value: @"<string>"];
[json UpdateString: @"name" value: @"<string>"];
[json UpdateString: @"templateType" value: @"<string>"];
[json UpdateString: @"body.value" value: @"<string>"];
[json UpdateString: @"body.representation" value: @"<string>"];
[json UpdateString: @"description" value: @"<string>"];
[json UpdateString: @"labels[0].prefix" value: @"ipsum dolor Excepteur Duis"];
[json UpdateString: @"labels[0].name" value: @"nulla et ipsum voluptate consectetur"];
[json UpdateString: @"labels[0].id" value: @"nostrud enim proident cupidatat eu"];
[json UpdateString: @"labels[0].label" value: @"enim Lorem veniam amet"];
[json UpdateString: @"labels[1].prefix" value: @"amet"];
[json UpdateString: @"labels[1].name" value: @"officia adipisicing ut labo"];
[json UpdateString: @"labels[1].id" value: @"ipsum in tempor"];
[json UpdateString: @"labels[1].label" value: @"est occaecat magna"];
[json UpdateString: @"space.key" value: @"<string>"];

// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = @"<access_token>";
[http SetRequestHeader: @"Content-Type" value: @"application/json"];

CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];

CkoHttpResponse *resp = [http PTextSb: @"PUT" url: @"https://your-domain.atlassian.net/wiki/rest/api/template" textData: sbRequestBody charset: @"utf-8" contentType: @"application/json" md5: NO gzip: NO];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
[resp GetBodySb: sbResponseBody];

CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[jResp LoadSb: sbResponseBody];
jResp.EmitCompact = NO;

NSLog(@"%@",@"Response Body:");
NSLog(@"%@",[jResp Emit]);

int respStatusCode = [resp.StatusCode intValue];
NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
if (respStatusCode >= 400) {
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",resp.Header);
    NSLog(@"%@",@"Failed.");

    return;
}

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "templateId": "id ipsum ut",
//   "name": "sit dolor sint dolore",
//   "description": "magna",
//   "labels": [
//     {
//       "prefix": "fugiat sit Ut in ea",
//       "name": "dolor in",
//       "id": "aliqua culpa veniam ea",
//       "label": "officia tempor ea"
//     },
//     {
//       "prefix": "exercitation culpa proident",
//       "name": "nulla mollit adipis",
//       "id": "laborum sint",
//       "label": "fugiat"
//     }
//   ],
//   "templateType": "in cillum",
//   "_expandable": {
//     "body": "anim aute officia in culpa"
//   },
//   "_links": {},
//   "body": {
//     "value": "aute sit pariatur consequat deserunt",
//     "representation": "anonymous_export_view",
//     "_expandable": {
//       "content": "nulla cillum reprehenderit"
//     },
//     "embeddedContent": [
//       {
//         "entityId": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         "entity": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         }
//       },
//       {
//         "entityId": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         "entity": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         }
//       }
//     ],
//     "webresource": {
//       "keys": [
//         {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         }
//       ],
//       "contexts": [
//         {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         }
//       ],
//       "uris": {
//         "all": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         "css": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         "js": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         }
//       },
//       "tags": {
//         "all": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         "css": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         "data": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         "js": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         }
//       },
//       "superbatch": {
//         "value": "<Error: Too many levels of nesting to fake this schema>"
//       }
//     }
//   }
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

NSString *prefix = 0;
NSString *id = 0;
NSString *label = 0;
NSString *entityIdValue = 0;
NSString *entityValue = 0;
NSString *value = 0;

NSString *templateId = [jResp StringOf: @"templateId"];
NSString *name = [jResp StringOf: @"name"];
NSString *description = [jResp StringOf: @"description"];
NSString *templateType = [jResp StringOf: @"templateType"];
NSString *Body = [jResp StringOf: @"_expandable.body"];
NSString *Value = [jResp StringOf: @"body.value"];
NSString *Representation = [jResp StringOf: @"body.representation"];
NSString *Content = [jResp StringOf: @"body._expandable.content"];
NSString *AllValue = [jResp StringOf: @"body.webresource.uris.all.value"];
NSString *CssValue = [jResp StringOf: @"body.webresource.uris.css.value"];
NSString *JsValue = [jResp StringOf: @"body.webresource.uris.js.value"];
AllValue = [jResp StringOf: @"body.webresource.tags.all.value"];
CssValue = [jResp StringOf: @"body.webresource.tags.css.value"];
NSString *DataValue = [jResp StringOf: @"body.webresource.tags.data.value"];
JsValue = [jResp StringOf: @"body.webresource.tags.js.value"];
NSString *SuperbatchValue = [jResp StringOf: @"body.webresource.superbatch.value"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"labels"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    prefix = [jResp StringOf: @"labels[i].prefix"];
    name = [jResp StringOf: @"labels[i].name"];
    id = [jResp StringOf: @"labels[i].id"];
    label = [jResp StringOf: @"labels[i].label"];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"body.embeddedContent"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    entityIdValue = [jResp StringOf: @"body.embeddedContent[i].entityId.value"];
    entityValue = [jResp StringOf: @"body.embeddedContent[i].entity.value"];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"body.webresource.keys"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    value = [jResp StringOf: @"body.webresource.keys[i].value"];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"body.webresource.contexts"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    value = [jResp StringOf: @"body.webresource.contexts[i].value"];
    i = i + 1;
}

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
    "templateId": "<string>",
    "name": "<string>",
    "templateType": "<string>",
    "body": {
        "value": "<string>",
        "representation": "<string>"
    },
    "description": "<string>",
    "labels": [
        {
            "prefix": "ipsum dolor Excepteur Duis",
            "name": "nulla et ipsum voluptate consectetur",
            "id": "nostrud enim proident cupidatat eu",
            "label": "enim Lorem veniam amet"
        },
        {
            "prefix": "amet",
            "name": "officia adipisicing ut labo",
            "id": "ipsum in tempor",
            "label": "est occaecat magna"
        }
    ],
    "space": {
        "key": "<string>"
    }
}'
https://your-domain.atlassian.net/wiki/rest/api/template

Postman Collection Item JSON

{
  "name": "Update content template",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"templateId\": \"<string>\",\n    \"name\": \"<string>\",\n    \"templateType\": \"<string>\",\n    \"body\": {\n        \"value\": \"<string>\",\n        \"representation\": \"<string>\"\n    },\n    \"description\": \"<string>\",\n    \"labels\": [\n        {\n            \"prefix\": \"ipsum dolor Excepteur Duis\",\n            \"name\": \"nulla et ipsum voluptate consectetur\",\n            \"id\": \"nostrud enim proident cupidatat eu\",\n            \"label\": \"enim Lorem veniam amet\"\n        },\n        {\n            \"prefix\": \"amet\",\n            \"name\": \"officia adipisicing ut labo\",\n            \"id\": \"ipsum in tempor\",\n            \"label\": \"est occaecat magna\"\n        }\n    ],\n    \"space\": {\n        \"key\": \"<string>\"\n    }\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/api/template",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "template"
      ]
    },
    "description": "Updates a content template. Note, blueprint templates cannot be updated\nvia the REST API.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\n'Admin' permission for the space to create a space template or 'Confluence Administrator'\nglobal permission to create a global template."
  },
  "response": [
    {
      "name": "Returned if the template is updated.",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"templateId\": \"<string>\",\n    \"name\": \"<string>\",\n    \"templateType\": \"<string>\",\n    \"body\": {\n        \"value\": \"<string>\",\n        \"representation\": \"<string>\"\n    },\n    \"description\": \"<string>\",\n    \"labels\": [\n        {\n            \"prefix\": \"officia ea in eu\",\n            \"name\": \"commodo mollit\",\n            \"id\": \"veniam minim nisi quis officia\",\n            \"label\": \"commodo\"\n        },\n        {\n            \"prefix\": \"cupidatat dolor aliqua laboris\",\n            \"name\": \"officia amet\",\n            \"id\": \"voluptate ad quis p\",\n            \"label\": \"eu sit adipisicing ea Ut\"\n        }\n    ],\n    \"space\": {\n        \"key\": \"<string>\"\n    }\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/template",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "template"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"templateId\": \"id ipsum ut\",\n \"name\": \"sit dolor sint dolore\",\n \"description\": \"magna\",\n \"labels\": [\n  {\n   \"prefix\": \"fugiat sit Ut in ea\",\n   \"name\": \"dolor in\",\n   \"id\": \"aliqua culpa veniam ea\",\n   \"label\": \"officia tempor ea\"\n  },\n  {\n   \"prefix\": \"exercitation culpa proident\",\n   \"name\": \"nulla mollit adipis\",\n   \"id\": \"laborum sint\",\n   \"label\": \"fugiat\"\n  }\n ],\n \"templateType\": \"in cillum\",\n \"_expandable\": {\n  \"body\": \"anim aute officia in culpa\"\n },\n \"_links\": {},\n \"body\": {\n  \"value\": \"aute sit pariatur consequat deserunt\",\n  \"representation\": \"anonymous_export_view\",\n  \"_expandable\": {\n   \"content\": \"nulla cillum reprehenderit\"\n  },\n  \"embeddedContent\": [\n   {\n    \"entityId\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    \"entity\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    }\n   },\n   {\n    \"entityId\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    \"entity\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    }\n   }\n  ],\n  \"webresource\": {\n   \"keys\": [\n    {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    }\n   ],\n   \"contexts\": [\n    {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    }\n   ],\n   \"uris\": {\n    \"all\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    \"css\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    \"js\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    }\n   },\n   \"tags\": {\n    \"all\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    \"css\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    \"data\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    \"js\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    }\n   },\n   \"superbatch\": {\n    \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n   }\n  }\n }\n}"
    },
    {
      "name": "Returned if the calling user does not have permission to update the\ntemplate.",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"templateId\": \"<string>\",\n    \"name\": \"<string>\",\n    \"templateType\": \"<string>\",\n    \"body\": {\n        \"value\": \"<string>\",\n        \"representation\": \"<string>\"\n    },\n    \"description\": \"<string>\",\n    \"labels\": [\n        {\n            \"prefix\": \"officia ea in eu\",\n            \"name\": \"commodo mollit\",\n            \"id\": \"veniam minim nisi quis officia\",\n            \"label\": \"commodo\"\n        },\n        {\n            \"prefix\": \"cupidatat dolor aliqua laboris\",\n            \"name\": \"officia amet\",\n            \"id\": \"voluptate ad quis p\",\n            \"label\": \"eu sit adipisicing ea Ut\"\n        }\n    ],\n    \"space\": {\n        \"key\": \"<string>\"\n    }\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/template",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "template"
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}