Chilkat Online Tools

PowerBuilder / Atlassian Confluence Cloud / Create content template

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Prefix
string ls_Id
string ls_Label
string ls_EntityIdValue
string ls_EntityValue
string ls_Value
string ls_TemplateId
string ls_Name
string ls_Description
string ls_TemplateType
string ls_Body
string ls_Value
string ls_Representation
string ls_Content
string ls_AllValue
string ls_CssValue
string ls_JsValue
string ls_DataValue
string ls_SuperbatchValue
integer i
integer li_Count_i

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// 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>",
//   "templateType": "<string>",
//   "body": {
//     "storage": {
//       "value": "<string>",
//       "representation": "<string>"
//     }
//   },
//   "description": "<string>",
//   "labels": [
//     {
//       "prefix": "dolore deserunt ut est anim",
//       "name": "occaecat quis culpa ad non",
//       "id": "laborum nisi ipsum",
//       "label": "labore laborum sint"
//     },
//     {
//       "prefix": "proident tempor",
//       "name": "incididunt cupidatat ea",
//       "id": "non dolore quis proident",
//       "label": "labore sint"
//     }
//   ],
//   "space": {
//     "key": "<string>"
//   }
// }

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Json.UpdateString("name","<string>")
loo_Json.UpdateString("templateType","<string>")
loo_Json.UpdateString("body.storage.value","<string>")
loo_Json.UpdateString("body.storage.representation","<string>")
loo_Json.UpdateString("description","<string>")
loo_Json.UpdateString("labels[0].prefix","dolore deserunt ut est anim")
loo_Json.UpdateString("labels[0].name","occaecat quis culpa ad non")
loo_Json.UpdateString("labels[0].id","laborum nisi ipsum")
loo_Json.UpdateString("labels[0].label","labore laborum sint")
loo_Json.UpdateString("labels[1].prefix","proident tempor")
loo_Json.UpdateString("labels[1].name","incididunt cupidatat ea")
loo_Json.UpdateString("labels[1].id","non dolore quis proident")
loo_Json.UpdateString("labels[1].label","labore sint")
loo_Json.UpdateString("space.key","<string>")

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

loo_Resp = loo_Http.PostJson3("https://your-domain.atlassian.net/wiki/rest/api/template","application/json",loo_Json)
if loo_Http.LastMethodSuccess = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    return
end if

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)

loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Resp
    destroy loo_Http
    destroy loo_Json
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

destroy loo_Resp

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

// {
//   "templateId": "aliqua",
//   "name": "officia cupidatat voluptate velit",
//   "description": "labore",
//   "labels": [
//     {
//       "prefix": "anim",
//       "name": "in cupidatat cillum veniam Duis",
//       "id": "cillum aliqua sed eiusmod enim",
//       "label": "cupidatat"
//     },
//     {
//       "prefix": "elit minim",
//       "name": "vol",
//       "id": "sit voluptate ",
//       "label": "eu sit qui"
//     }
//   ],
//   "templateType": "amet",
//   "_expandable": {
//     "body": "exercitation sunt"
//   },
//   "_links": {},
//   "body": {
//     "value": "reprehend",
//     "representation": "export_view",
//     "_expandable": {
//       "content": "ex esse enim irure amet"
//     },
//     "embeddedContent": [
//       {
//         "entityId": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         "entity": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         }
//       },
//       {
//         "entityId": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         "entity": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         }
//       }
//     ],
//     "webresource": {
//       "keys": [
//         {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         }
//       ],
//       "contexts": [
//         {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         }
//       ],
//       "uris": {
//         "all": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         "css": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         "js": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         }
//       },
//       "tags": {
//         "all": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         "css": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         "data": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         },
//         "js": {
//           "value": "<Error: Too many levels of nesting to fake this schema>"
//         }
//       },
//       "superbatch": {
//         "value": "<Error: Too many levels of nesting to fake this schema>"
//       }
//     }
//   }
// }

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

ls_TemplateId = loo_JResp.StringOf("templateId")
ls_Name = loo_JResp.StringOf("name")
ls_Description = loo_JResp.StringOf("description")
ls_TemplateType = loo_JResp.StringOf("templateType")
ls_Body = loo_JResp.StringOf("_expandable.body")
ls_Value = loo_JResp.StringOf("body.value")
ls_Representation = loo_JResp.StringOf("body.representation")
ls_Content = loo_JResp.StringOf("body._expandable.content")
ls_AllValue = loo_JResp.StringOf("body.webresource.uris.all.value")
ls_CssValue = loo_JResp.StringOf("body.webresource.uris.css.value")
ls_JsValue = loo_JResp.StringOf("body.webresource.uris.js.value")
ls_AllValue = loo_JResp.StringOf("body.webresource.tags.all.value")
ls_CssValue = loo_JResp.StringOf("body.webresource.tags.css.value")
ls_DataValue = loo_JResp.StringOf("body.webresource.tags.data.value")
ls_JsValue = loo_JResp.StringOf("body.webresource.tags.js.value")
ls_SuperbatchValue = loo_JResp.StringOf("body.webresource.superbatch.value")
i = 0
li_Count_i = loo_JResp.SizeOfArray("labels")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Prefix = loo_JResp.StringOf("labels[i].prefix")
    ls_Name = loo_JResp.StringOf("labels[i].name")
    ls_Id = loo_JResp.StringOf("labels[i].id")
    ls_Label = loo_JResp.StringOf("labels[i].label")
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("body.embeddedContent")
do while i < li_Count_i
    loo_JResp.I = i
    ls_EntityIdValue = loo_JResp.StringOf("body.embeddedContent[i].entityId.value")
    ls_EntityValue = loo_JResp.StringOf("body.embeddedContent[i].entity.value")
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("body.webresource.keys")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Value = loo_JResp.StringOf("body.webresource.keys[i].value")
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("body.webresource.contexts")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Value = loo_JResp.StringOf("body.webresource.contexts[i].value")
    i = i + 1
loop


destroy loo_Http
destroy loo_Json
destroy loo_SbResponseBody
destroy loo_JResp

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
    "name": "<string>",
    "templateType": "<string>",
    "body": {
        "storage": {
            "value": "<string>",
            "representation": "<string>"
        }
    },
    "description": "<string>",
    "labels": [
        {
            "prefix": "dolore deserunt ut est anim",
            "name": "occaecat quis culpa ad non",
            "id": "laborum nisi ipsum",
            "label": "labore laborum sint"
        },
        {
            "prefix": "proident tempor",
            "name": "incididunt cupidatat ea",
            "id": "non dolore quis proident",
            "label": "labore sint"
        }
    ],
    "space": {
        "key": "<string>"
    }
}'
https://your-domain.atlassian.net/wiki/rest/api/template

Postman Collection Item JSON

{
  "name": "Create content template",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"name\": \"<string>\",\n    \"templateType\": \"<string>\",\n    \"body\": {\n        \"storage\": {\n            \"value\": \"<string>\",\n            \"representation\": \"<string>\"\n        }\n    },\n    \"description\": \"<string>\",\n    \"labels\": [\n        {\n            \"prefix\": \"dolore deserunt ut est anim\",\n            \"name\": \"occaecat quis culpa ad non\",\n            \"id\": \"laborum nisi ipsum\",\n            \"label\": \"labore laborum sint\"\n        },\n        {\n            \"prefix\": \"proident tempor\",\n            \"name\": \"incididunt cupidatat ea\",\n            \"id\": \"non dolore quis proident\",\n            \"label\": \"labore sint\"\n        }\n    ],\n    \"space\": {\n        \"key\": \"<string>\"\n    }\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/api/template",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "template"
      ]
    },
    "description": "Creates a new content template. Note, blueprint templates cannot be created via the REST API.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\n'Admin' permission for the space to create a space template or 'Confluence Administrator'\nglobal permission to create a global template."
  },
  "response": [
    {
      "name": "Returned if the template is created.",
      "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    \"templateType\": \"<string>\",\n    \"body\": {\n        \"storage\": {\n            \"value\": \"<string>\",\n            \"representation\": \"<string>\"\n        }\n    },\n    \"description\": \"<string>\",\n    \"labels\": [\n        {\n            \"prefix\": \"occaecat commodo\",\n            \"name\": \"exercitation veniam\",\n            \"id\": \"deserunt ea Duis dolor\",\n            \"label\": \"aliquip sunt proi\"\n        },\n        {\n            \"prefix\": \"ex adipisicing elit sit\",\n            \"name\": \"reprehenderit consequat s\",\n            \"id\": \"irure consectetur\",\n            \"label\": \"amet occaecat exercitation\"\n        }\n    ],\n    \"space\": {\n        \"key\": \"<string>\"\n    }\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/template",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "template"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"templateId\": \"aliqua\",\n \"name\": \"officia cupidatat voluptate velit\",\n \"description\": \"labore\",\n \"labels\": [\n  {\n   \"prefix\": \"anim\",\n   \"name\": \"in cupidatat cillum veniam Duis\",\n   \"id\": \"cillum aliqua sed eiusmod enim\",\n   \"label\": \"cupidatat\"\n  },\n  {\n   \"prefix\": \"elit minim\",\n   \"name\": \"vol\",\n   \"id\": \"sit voluptate \",\n   \"label\": \"eu sit qui\"\n  }\n ],\n \"templateType\": \"amet\",\n \"_expandable\": {\n  \"body\": \"exercitation sunt\"\n },\n \"_links\": {},\n \"body\": {\n  \"value\": \"reprehend\",\n  \"representation\": \"export_view\",\n  \"_expandable\": {\n   \"content\": \"ex esse enim irure amet\"\n  },\n  \"embeddedContent\": [\n   {\n    \"entityId\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    \"entity\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    }\n   },\n   {\n    \"entityId\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    \"entity\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    }\n   }\n  ],\n  \"webresource\": {\n   \"keys\": [\n    {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    }\n   ],\n   \"contexts\": [\n    {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    }\n   ],\n   \"uris\": {\n    \"all\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    \"css\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    \"js\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    }\n   },\n   \"tags\": {\n    \"all\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    \"css\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    \"data\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    },\n    \"js\": {\n     \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n    }\n   },\n   \"superbatch\": {\n    \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n   }\n  }\n }\n}"
    },
    {
      "name": "Returned if the calling user does not have permission to create the\ntemplate.",
      "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    \"templateType\": \"<string>\",\n    \"body\": {\n        \"storage\": {\n            \"value\": \"<string>\",\n            \"representation\": \"<string>\"\n        }\n    },\n    \"description\": \"<string>\",\n    \"labels\": [\n        {\n            \"prefix\": \"occaecat commodo\",\n            \"name\": \"exercitation veniam\",\n            \"id\": \"deserunt ea Duis dolor\",\n            \"label\": \"aliquip sunt proi\"\n        },\n        {\n            \"prefix\": \"ex adipisicing elit sit\",\n            \"name\": \"reprehenderit consequat s\",\n            \"id\": \"irure consectetur\",\n            \"label\": \"amet occaecat exercitation\"\n        }\n    ],\n    \"space\": {\n        \"key\": \"<string>\"\n    }\n}"
        },
        "url": {
          "raw": "{{baseUrl}}/api/template",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "template"
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}