Chilkat Online Tools

unicodeCpp / Atlassian Confluence Cloud / Set space theme

Back to Collection Items

#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
#include <CkHttpResponseW.h>

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

    CkHttpW 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.

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

    CkJsonObjectW json;
    json.UpdateString(L"themeKey",L"<string>");

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

    CkStringBuilderW sbRequestBody;
    json.EmitSb(sbRequestBody);

    CkHttpResponseW *resp = http.PTextSb(L"PUT",L"https://your-domain.atlassian.net/wiki/rest/api/space/:spaceKey/theme",sbRequestBody,L"utf-8",L"application/json",false,false);
    if (http.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkStringBuilderW sbResponseBody;
    resp->GetBodySb(sbResponseBody);

    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",jResp.emit());

    int respStatusCode = resp->get_StatusCode();
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",resp->header());
        wprintf(L"Failed.\n");
        delete resp;
        return;
    }

    delete resp;
    }

Curl Command

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

Postman Collection Item JSON

{
  "name": "Set space theme",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"themeKey\": \"<string>\"\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/api/space/:spaceKey/theme",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "space",
        ":spaceKey",
        "theme"
      ],
      "variable": [
        {
          "key": "spaceKey",
          "value": "<string>",
          "type": "string",
          "description": "(Required) The key of the space to set the theme for."
        }
      ]
    },
    "description": "Sets the theme for a space. Note, if you want to reset the space theme to\nthe default Confluence theme, use the 'Reset space theme' method instead\nof this method.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\n'Admin' permission for the space."
  },
  "response": [
    {
      "name": "Returned if the theme was set for 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    \"themeKey\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/space/:spaceKey/theme",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "space",
            ":spaceKey",
            "theme"
          ],
          "variable": [
            {
              "key": "spaceKey"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{}"
    },
    {
      "name": "Returned if the theme key is invalid.",
      "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    \"themeKey\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/space/:spaceKey/theme",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "space",
            ":spaceKey",
            "theme"
          ],
          "variable": [
            {
              "key": "spaceKey"
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Returned if there is no space with the given key.",
      "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    \"themeKey\": \"<string>\"\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/space/:spaceKey/theme",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "space",
            ":spaceKey",
            "theme"
          ],
          "variable": [
            {
              "key": "spaceKey"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}