Chilkat Online Tools

Objective-C / Atlassian Confluence Cloud / Create new user group

Back to Collection Items

#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoHttpResponse.h>
#import <CkoStringBuilder.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.

// {
//   "name": "<string>"
// }

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"name" value: @"<string>"];

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

CkoHttpResponse *resp = [http PostJson3: @"https://your-domain.atlassian.net/wiki/rest/api/group" contentType: @"application/json" json: json];
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)

// {
//   "type": "group",
//   "name": "et exercitation",
//   "id": "ut Duis dolore consectetur",
//   "_links": {}
// }

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

NSString *v_type = [jResp StringOf: @"type"];
NSString *name = [jResp StringOf: @"name"];
NSString *id = [jResp StringOf: @"id"];

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
    "name": "<string>"
}'
https://your-domain.atlassian.net/wiki/rest/api/group

Postman Collection Item JSON

{
  "name": "Create new user group",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"name\": \"<string>\"\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/api/group",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "group"
      ]
    },
    "description": "Creates a new user group.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\nUser must be a site admin."
  },
  "response": [
    {
      "name": "Returned if the group was created successfully.",
      "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    \"name\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/group",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "group"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"type\": \"group\",\n \"name\": \"et exercitation\",\n \"id\": \"ut Duis dolore consectetur\",\n \"_links\": {}\n}"
    },
    {
      "name": "Returned if the name is missing or invalid.",
      "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    \"name\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/group",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "group"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Returned if the calling user is not logged in to Confluence.",
      "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    \"name\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/group",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "group"
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Returned if the user is not a site admin.",
      "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    \"name\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/group",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "group"
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}