Chilkat Online Tools

delphiDll / Atlassian Confluence Cloud / Update space settings

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
sbRequestBody: HCkStringBuilder;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
routeOverrideEnabled: Boolean;

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

// {
//   "routeOverrideEnabled": "<boolean>"
// }

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'routeOverrideEnabled','<boolean>');

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

sbRequestBody := CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);

resp := CkHttp_PTextSb(http,'PUT','https://your-domain.atlassian.net/wiki/rest/api/space/:spaceKey/settings',sbRequestBody,'utf-8','application/json',False,False);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

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

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

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "routeOverrideEnabled": false,
//   "_links": {}
// }

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

routeOverrideEnabled := CkJsonObject_BoolOf(jResp,'routeOverrideEnabled');

CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
    "routeOverrideEnabled": "<boolean>"
}'
https://your-domain.atlassian.net/wiki/rest/api/space/:spaceKey/settings

Postman Collection Item JSON

{
  "name": "Update space settings",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"routeOverrideEnabled\": \"<boolean>\"\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/api/space/:spaceKey/settings",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "space",
        ":spaceKey",
        "settings"
      ],
      "variable": [
        {
          "key": "spaceKey",
          "value": "<string>",
          "type": "string",
          "description": "(Required) The key of the space whose settings will be updated."
        }
      ]
    },
    "description": "Updates the settings for a space. Currently only the\n`routeOverrideEnabled` setting can be updated.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\n'Admin' permission for the space."
  },
  "response": [
    {
      "name": "Returned if space settings are updated.",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"routeOverrideEnabled\": \"<boolean>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/space/:spaceKey/settings",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "space",
            ":spaceKey",
            "settings"
          ],
          "variable": [
            {
              "key": "spaceKey"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"routeOverrideEnabled\": false,\n \"_links\": {}\n}"
    },
    {
      "name": "Returned if the authentication credentials are incorrect or missing\nfrom the request.",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"routeOverrideEnabled\": \"<boolean>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/space/:spaceKey/settings",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "space",
            ":spaceKey",
            "settings"
          ],
          "variable": [
            {
              "key": "spaceKey"
            }
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Returned if;\n\n- There is no space with the given key.\n- The calling user does not have permission to update the space.",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"routeOverrideEnabled\": \"<boolean>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/space/:spaceKey/settings",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "space",
            ":spaceKey",
            "settings"
          ],
          "variable": [
            {
              "key": "spaceKey"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}