Chilkat Online Tools

C# / Atlassian Confluence Cloud / Create new user group

Back to Collection Items

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

Chilkat.Http http = new Chilkat.Http();
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>"
// }

Chilkat.JsonObject json = new Chilkat.JsonObject();
json.UpdateString("name","<string>");

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

Chilkat.HttpResponse resp = http.PostJson3("https://your-domain.atlassian.net/wiki/rest/api/group","application/json",json);
if (http.LastMethodSuccess == false) {
    Debug.WriteLine(http.LastErrorText);
    return;
}

Chilkat.StringBuilder sbResponseBody = new Chilkat.StringBuilder();
resp.GetBodySb(sbResponseBody);

Chilkat.JsonObject jResp = new Chilkat.JsonObject();
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact = false;

Debug.WriteLine("Response Body:");
Debug.WriteLine(jResp.Emit());

int respStatusCode = resp.StatusCode;
Debug.WriteLine("Response Status Code = " + Convert.ToString(respStatusCode));
if (respStatusCode >= 400) {
    Debug.WriteLine("Response Header:");
    Debug.WriteLine(resp.Header);
    Debug.WriteLine("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

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