Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkHttpResponse.h>
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkJsonObject json;
HCkHttpResponse resp;
HCkStringBuilder sbResponseBody;
HCkJsonObject jResp;
int respStatusCode;
const char *v_Type;
const char *Identifier;
const char *Key;
const char *Target;
const char *id;
// 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.
// {
// "subject": {
// "type": "<string>",
// "identifier": "<string>"
// },
// "operation": {
// "key": "<string>",
// "target": "<string>"
// },
// "id": "<long>",
// "_links": {}
// }
json = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"subject.type","<string>");
CkJsonObject_UpdateString(json,"subject.identifier","<string>");
CkJsonObject_UpdateString(json,"operation.key","<string>");
CkJsonObject_UpdateString(json,"operation.target","<string>");
CkJsonObject_UpdateString(json,"id","<long>");
CkJsonObject_UpdateNewObject(json,"_links");
CkHttp_SetRequestHeader(http,"Content-Type","application/json");
resp = CkHttp_PostJson3(http,"https://your-domain.atlassian.net/wiki/rest/api/space/:spaceKey/permission","application/json",json);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
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(sbResponseBody);
CkJsonObject_Dispose(jResp);
return;
}
CkHttpResponse_Dispose(resp);
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "subject": {
// "type": "<string>",
// "identifier": "<string>"
// },
// "operation": {
// "key": "<string>",
// "target": "<string>"
// },
// "id": "<long>",
// "_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.
v_Type = CkJsonObject_stringOf(jResp,"subject.type");
Identifier = CkJsonObject_stringOf(jResp,"subject.identifier");
Key = CkJsonObject_stringOf(jResp,"operation.key");
Target = CkJsonObject_stringOf(jResp,"operation.target");
id = CkJsonObject_stringOf(jResp,"id");
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}
Curl Command
curl -X POST
-H "Content-Type: application/json"
-d '{
"subject": {
"type": "<string>",
"identifier": "<string>"
},
"operation": {
"key": "<string>",
"target": "<string>"
},
"id": "<long>",
"_links": {}
}'
https://your-domain.atlassian.net/wiki/rest/api/space/:spaceKey/permission
Postman Collection Item JSON
{
"name": "Add new permission to space",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"subject\": {\n \"type\": \"<string>\",\n \"identifier\": \"<string>\"\n },\n \"operation\": {\n \"key\": \"<string>\",\n \"target\": \"<string>\"\n },\n \"id\": \"<long>\",\n \"_links\": {}\n}"
},
"url": {
"raw": "{{baseUrl}}/api/space/:spaceKey/permission",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"space",
":spaceKey",
"permission"
],
"variable": [
{
"key": "spaceKey",
"value": "<string>",
"type": "string",
"description": "(Required) The key of the space to be queried for its content."
}
]
},
"description": "Adds new permission to space.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\n'Admin' permission for the space."
},
"response": [
{
"name": "Returned if the requested content is returned.",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"subject\": {\n \"type\": \"<string>\",\n \"identifier\": \"<string>\"\n },\n \"operation\": {\n \"key\": \"<string>\",\n \"target\": \"<string>\"\n },\n \"id\": \"<long>\",\n \"_links\": {}\n}"
},
"url": {
"raw": "{{baseUrl}}/api/space/:spaceKey/permission",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"space",
":spaceKey",
"permission"
],
"variable": [
{
"key": "spaceKey"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"subject\": {\n \"type\": \"<string>\",\n \"identifier\": \"<string>\"\n },\n \"operation\": {\n \"key\": \"<string>\",\n \"target\": \"<string>\"\n },\n \"id\": \"<long>\",\n \"_links\": {}\n}"
},
{
"name": "Used for various errors. Such as:\n- Permission already exists for the given user or group.\n- 'read space' permission doesn't exist for the given user or group.\n- No group found with the given groupName",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"subject\": {\n \"type\": \"<string>\",\n \"identifier\": \"<string>\"\n },\n \"operation\": {\n \"key\": \"<string>\",\n \"target\": \"<string>\"\n },\n \"id\": \"<long>\",\n \"_links\": {}\n}"
},
"url": {
"raw": "{{baseUrl}}/api/space/:spaceKey/permission",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"space",
":spaceKey",
"permission"
],
"variable": [
{
"key": "spaceKey"
}
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
},
{
"name": "Returned if the authentication credentials are incorrect or missing\nfrom the request.",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"subject\": {\n \"type\": \"<string>\",\n \"identifier\": \"<string>\"\n },\n \"operation\": {\n \"key\": \"<string>\",\n \"target\": \"<string>\"\n },\n \"id\": \"<long>\",\n \"_links\": {}\n}"
},
"url": {
"raw": "{{baseUrl}}/api/space/:spaceKey/permission",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"space",
":spaceKey",
"permission"
],
"variable": [
{
"key": "spaceKey"
}
]
}
},
"status": "Unauthorized",
"code": 401,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
},
{
"name": "Returned if the user isn't authorized.",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"subject\": {\n \"type\": \"<string>\",\n \"identifier\": \"<string>\"\n },\n \"operation\": {\n \"key\": \"<string>\",\n \"target\": \"<string>\"\n },\n \"id\": \"<long>\",\n \"_links\": {}\n}"
},
"url": {
"raw": "{{baseUrl}}/api/space/:spaceKey/permission",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"space",
":spaceKey",
"permission"
],
"variable": [
{
"key": "spaceKey"
}
]
}
},
"status": "Forbidden",
"code": 403,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
},
{
"name": "Returned if any of the following is true:\n- There is no space with the given key.\n- The calling user does not have permission to view the space.",
"originalRequest": {
"method": "POST",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"subject\": {\n \"type\": \"<string>\",\n \"identifier\": \"<string>\"\n },\n \"operation\": {\n \"key\": \"<string>\",\n \"target\": \"<string>\"\n },\n \"id\": \"<long>\",\n \"_links\": {}\n}"
},
"url": {
"raw": "{{baseUrl}}/api/space/:spaceKey/permission",
"host": [
"{{baseUrl}}"
],
"path": [
"api",
"space",
":spaceKey",
"permission"
],
"variable": [
{
"key": "spaceKey"
}
]
}
},
"status": "Not Found",
"code": 404,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
}
]
}