Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>
#include <C_CkHttpResponse.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkJsonObject json;
HCkStringBuilder sbRequestBody;
HCkHttpResponse resp;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int respStatusCode;
const char *prefix;
const char *id;
const char *label;
const char *entityIdValue;
const char *entityValue;
const char *value;
const char *templateId;
const char *name;
const char *description;
const char *templateType;
const char *Body;
const char *Value;
const char *Representation;
const char *Content;
const char *AllValue;
const char *CssValue;
const char *JsValue;
const char *DataValue;
const char *SuperbatchValue;
int i;
int count_i;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_Create();
// 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>"
// }
// }
json = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"templateId","<string>");
CkJsonObject_UpdateString(json,"name","<string>");
CkJsonObject_UpdateString(json,"templateType","<string>");
CkJsonObject_UpdateString(json,"body.value","<string>");
CkJsonObject_UpdateString(json,"body.representation","<string>");
CkJsonObject_UpdateString(json,"description","<string>");
CkJsonObject_UpdateString(json,"labels[0].prefix","ipsum dolor Excepteur Duis");
CkJsonObject_UpdateString(json,"labels[0].name","nulla et ipsum voluptate consectetur");
CkJsonObject_UpdateString(json,"labels[0].id","nostrud enim proident cupidatat eu");
CkJsonObject_UpdateString(json,"labels[0].label","enim Lorem veniam amet");
CkJsonObject_UpdateString(json,"labels[1].prefix","amet");
CkJsonObject_UpdateString(json,"labels[1].name","officia adipisicing ut labo");
CkJsonObject_UpdateString(json,"labels[1].id","ipsum in tempor");
CkJsonObject_UpdateString(json,"labels[1].label","est occaecat magna");
CkJsonObject_UpdateString(json,"space.key","<string>");
// Adds the "Authorization: Bearer <access_token>" header.
CkHttp_putAuthToken(http,"<access_token>");
CkHttp_SetRequestHeader(http,"Content-Type","application/json");
sbRequestBody = CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);
resp = CkHttp_PTextSb(http,"PUT","https://your-domain.atlassian.net/wiki/rest/api/template",sbRequestBody,"utf-8","application/json",FALSE,FALSE);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
return;
}
sbResponseBody = CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);
jResp = CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,FALSE);
printf("Response Body:\n");
printf("%s\n",CkJsonObject_emit(jResp));
respStatusCode = CkHttpResponse_getStatusCode(resp);
printf("Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
printf("Response Header:\n");
printf("%s\n",CkHttpResponse_header(resp));
printf("Failed.\n");
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
return;
}
CkHttpResponse_Dispose(resp);
// 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
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
templateId = CkJsonObject_stringOf(jResp,"templateId");
name = CkJsonObject_stringOf(jResp,"name");
description = CkJsonObject_stringOf(jResp,"description");
templateType = CkJsonObject_stringOf(jResp,"templateType");
Body = CkJsonObject_stringOf(jResp,"_expandable.body");
Value = CkJsonObject_stringOf(jResp,"body.value");
Representation = CkJsonObject_stringOf(jResp,"body.representation");
Content = CkJsonObject_stringOf(jResp,"body._expandable.content");
AllValue = CkJsonObject_stringOf(jResp,"body.webresource.uris.all.value");
CssValue = CkJsonObject_stringOf(jResp,"body.webresource.uris.css.value");
JsValue = CkJsonObject_stringOf(jResp,"body.webresource.uris.js.value");
AllValue = CkJsonObject_stringOf(jResp,"body.webresource.tags.all.value");
CssValue = CkJsonObject_stringOf(jResp,"body.webresource.tags.css.value");
DataValue = CkJsonObject_stringOf(jResp,"body.webresource.tags.data.value");
JsValue = CkJsonObject_stringOf(jResp,"body.webresource.tags.js.value");
SuperbatchValue = CkJsonObject_stringOf(jResp,"body.webresource.superbatch.value");
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"labels");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
prefix = CkJsonObject_stringOf(jResp,"labels[i].prefix");
name = CkJsonObject_stringOf(jResp,"labels[i].name");
id = CkJsonObject_stringOf(jResp,"labels[i].id");
label = CkJsonObject_stringOf(jResp,"labels[i].label");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"body.embeddedContent");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
entityIdValue = CkJsonObject_stringOf(jResp,"body.embeddedContent[i].entityId.value");
entityValue = CkJsonObject_stringOf(jResp,"body.embeddedContent[i].entity.value");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"body.webresource.keys");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
value = CkJsonObject_stringOf(jResp,"body.webresource.keys[i].value");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"body.webresource.contexts");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
value = CkJsonObject_stringOf(jResp,"body.webresource.contexts[i].value");
i = i + 1;
}
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}
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": ""
}
]
}