Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkJsonArray.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>
#include <C_CkHttpResponse.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkJsonArray jarr;
HCkJsonObject jsonObj_1;
HCkStringBuilder sbRequestBody;
HCkHttpResponse resp;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int respStatusCode;
const char *prefix;
const char *name;
const char *id;
const char *label;
int start;
int limit;
int size;
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.
// [
// {
// "prefix": "<string>",
// "name": "<string>"
// },
// {
// "prefix": "<string>",
// "name": "<string>"
// }
// ]
jarr = CkJsonArray_Create();
CkJsonArray_AddObjectAt(jarr,-1);
jsonObj_1 = CkJsonArray_ObjectAt(jarr,CkJsonArray_getSize(jarr) - 1);
CkJsonObject_UpdateString(jsonObj_1,"prefix","<string>");
CkJsonObject_UpdateString(jsonObj_1,"name","<string>");
CkJsonObject_Dispose(jsonObj_1);
CkJsonArray_AddObjectAt(jarr,-1);
jsonObj_1 = CkJsonArray_ObjectAt(jarr,CkJsonArray_getSize(jarr) - 1);
CkJsonObject_UpdateString(jsonObj_1,"prefix","<string>");
CkJsonObject_UpdateString(jsonObj_1,"name","<string>");
CkJsonObject_Dispose(jsonObj_1);
// Adds the "Authorization: Bearer <access_token>" header.
CkHttp_putAuthToken(http,"<access_token>");
CkHttp_SetRequestHeader(http,"Content-Type","application/json");
sbRequestBody = CkStringBuilder_Create();
CkJsonArray_EmitSb(jarr,sbRequestBody);
resp = CkHttp_PTextSb(http,"POST","https://your-domain.atlassian.net/wiki/rest/api/content/:id/label",sbRequestBody,"utf-8","application/json",FALSE,FALSE);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonArray_Dispose(jarr);
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);
CkJsonArray_Dispose(jarr);
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)
// {
// "results": [
// {
// "prefix": "Duis elit dolor officia",
// "name": "non sunt",
// "id": "nulla veniam",
// "label": "deserunt Ut Excepteur magna"
// },
// {
// "prefix": "in consequat deserun",
// "name": "officia cillum enim",
// "id": "Lorem quis esse amet",
// "label": "dolore esse"
// }
// ],
// "start": -32316568,
// "limit": -3993073,
// "size": -78086889,
// "_links": {}
// }
// 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.
start = CkJsonObject_IntOf(jResp,"start");
limit = CkJsonObject_IntOf(jResp,"limit");
size = CkJsonObject_IntOf(jResp,"size");
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"results");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
prefix = CkJsonObject_stringOf(jResp,"results[i].prefix");
name = CkJsonObject_stringOf(jResp,"results[i].name");
id = CkJsonObject_stringOf(jResp,"results[i].id");
label = CkJsonObject_stringOf(jResp,"results[i].label");
i = i + 1;
}
CkHttp_Dispose(http);
CkJsonArray_Dispose(jarr);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-H "Content-Type: application/json"
-d '[
{
"prefix": "<string>",
"name": "<string>"
},
{
"prefix": "<string>",
"name": "<string>"
}
]'
https://your-domain.atlassian.net/wiki/rest/api/content/:id/label
Postman Collection Item JSON
{
"name": "Add labels to content",
"request": {
"auth": {
"type": "oauth2"
},
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "[\n {\n \"prefix\": \"<string>\",\n \"name\": \"<string>\"\n },\n {\n \"prefix\": \"<string>\",\n \"name\": \"<string>\"\n }\n]"
},
"url": {
"raw": "{{baseUrl}}/api/content/:id/label",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"content",
":id",
"label"
],
"variable": [
{
"key": "id",
"value": "<string>",
"type": "string",
"description": "(Required) The ID of the content that will have labels added to it."
}
]
},
"description": "Adds labels to a piece of content. Does not modify the existing labels.\n\nNotes:\n\n- Labels can also be added when creating content ([Create content](#api-content-post)).\n- Labels can be updated when updating content ([Update content](#api-content-id-put)).\nThis will delete the existing labels and replace them with the labels in\nthe request.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\nPermission to update the content."
},
"response": [
{
"name": "Returned if the labels are added to the content.",
"originalRequest": {
"method": "POST",
"header": [
{
"description": {
"content": "Added as a part of security scheme: oauth2",
"type": "text/plain"
},
"key": "Authorization",
"value": "<token>"
}
],
"body": {
"mode": "raw",
"raw": "[\n {\n \"prefix\": \"<string>\",\n \"name\": \"<string>\"\n },\n {\n \"prefix\": \"<string>\",\n \"name\": \"<string>\"\n }\n]"
},
"url": {
"raw": "{{baseUrl}}/api/content/:id/label",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"content",
":id",
"label"
],
"variable": [
{
"key": "id"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"results\": [\n {\n \"prefix\": \"Duis elit dolor officia\",\n \"name\": \"non sunt\",\n \"id\": \"nulla veniam\",\n \"label\": \"deserunt Ut Excepteur magna\"\n },\n {\n \"prefix\": \"in consequat deserun\",\n \"name\": \"officia cillum enim\",\n \"id\": \"Lorem quis esse amet\",\n \"label\": \"dolore esse\"\n }\n ],\n \"start\": -32316568,\n \"limit\": -3993073,\n \"size\": -78086889,\n \"_links\": {}\n}"
},
{
"name": "Returned if;\n\n- There is no content with the given ID.\n- The calling user does not have permission to view the content.",
"originalRequest": {
"method": "POST",
"header": [
{
"description": {
"content": "Added as a part of security scheme: oauth2",
"type": "text/plain"
},
"key": "Authorization",
"value": "<token>"
}
],
"body": {
"mode": "raw",
"raw": "[\n {\n \"prefix\": \"<string>\",\n \"name\": \"<string>\"\n },\n {\n \"prefix\": \"<string>\",\n \"name\": \"<string>\"\n }\n]"
},
"url": {
"raw": "{{baseUrl}}/api/content/:id/label",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"content",
":id",
"label"
],
"variable": [
{
"key": "id"
}
]
}
},
"status": "Not Found",
"code": 404,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
}
]
}