Chilkat Online Tools

delphiAx / Atlassian Confluence Cloud / Create new user group

Back to Collection Items

var
http: TChilkatHttp;
success: Integer;
json: TChilkatJsonObject;
resp: IChilkatHttpResponse;
sbResponseBody: TChilkatStringBuilder;
jResp: TChilkatJsonObject;
respStatusCode: Integer;
v_type: WideString;
name: WideString;
id: WideString;

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

http := TChilkatHttp.Create(Self);

// 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>"
// }

json := TChilkatJsonObject.Create(Self);
json.UpdateString('name','<string>');

// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken := '<access_token>';
http.SetRequestHeader('Content-Type','application/json');

resp := http.PostJson3('https://your-domain.atlassian.net/wiki/rest/api/group','application/json',json.ControlInterface);
if (http.LastMethodSuccess = 0) then
  begin
    Memo1.Lines.Add(http.LastErrorText);
    Exit;
  end;

sbResponseBody := TChilkatStringBuilder.Create(Self);
resp.GetBodySb(sbResponseBody.ControlInterface);

jResp := TChilkatJsonObject.Create(Self);
jResp.LoadSb(sbResponseBody.ControlInterface);
jResp.EmitCompact := 0;

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(jResp.Emit());

respStatusCode := resp.StatusCode;
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(resp.Header);
    Memo1.Lines.Add('Failed.');

    Exit;
  end;

// 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

v_type := jResp.StringOf('type');
name := jResp.StringOf('name');
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": ""
    }
  ]
}