Chilkat Online Tools

DataFlex / Atlassian Confluence Cloud / Update content template

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Handle hoJson
    Variant vSbRequestBody
    Handle hoSbRequestBody
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sPrefix
    String sId
    String sLabel
    String sEntityIdValue
    String sEntityValue
    String sValue
    String sTemplateId
    String sName
    String sDescription
    String sTemplateType
    String sBody
    String sValue
    String sRepresentation
    String sContent
    String sAllValue
    String sCssValue
    String sJsValue
    String sDataValue
    String sSuperbatchValue
    Integer i
    Integer iCount_i
    String sTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "templateId": "<string>",
    //   "name": "<string>",
    //   "templateType": "<string>",
    //   "body": {
    //     "value": "<string>",
    //     "representation": "<string>"
    //   },
    //   "description": "<string>",
    //   "labels": [
    //     {
    //       "prefix": "ipsum dolor Excepteur Duis",
    //       "name": "nulla et ipsum voluptate consectetur",
    //       "id": "nostrud enim proident cupidatat eu",
    //       "label": "enim Lorem veniam amet"
    //     },
    //     {
    //       "prefix": "amet",
    //       "name": "officia adipisicing ut labo",
    //       "id": "ipsum in tempor",
    //       "label": "est occaecat magna"
    //     }
    //   ],
    //   "space": {
    //     "key": "<string>"
    //   }
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "templateId" "<string>" To iSuccess
    Get ComUpdateString Of hoJson "name" "<string>" To iSuccess
    Get ComUpdateString Of hoJson "templateType" "<string>" To iSuccess
    Get ComUpdateString Of hoJson "body.value" "<string>" To iSuccess
    Get ComUpdateString Of hoJson "body.representation" "<string>" To iSuccess
    Get ComUpdateString Of hoJson "description" "<string>" To iSuccess
    Get ComUpdateString Of hoJson "labels[0].prefix" "ipsum dolor Excepteur Duis" To iSuccess
    Get ComUpdateString Of hoJson "labels[0].name" "nulla et ipsum voluptate consectetur" To iSuccess
    Get ComUpdateString Of hoJson "labels[0].id" "nostrud enim proident cupidatat eu" To iSuccess
    Get ComUpdateString Of hoJson "labels[0].label" "enim Lorem veniam amet" To iSuccess
    Get ComUpdateString Of hoJson "labels[1].prefix" "amet" To iSuccess
    Get ComUpdateString Of hoJson "labels[1].name" "officia adipisicing ut labo" To iSuccess
    Get ComUpdateString Of hoJson "labels[1].id" "ipsum in tempor" To iSuccess
    Get ComUpdateString Of hoJson "labels[1].label" "est occaecat magna" To iSuccess
    Get ComUpdateString Of hoJson "space.key" "<string>" To iSuccess

    // Adds the "Authorization: Bearer <access_token>" header.
    Set ComAuthToken Of hoHttp To "<access_token>"
    Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
    If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
        Send CreateComObject of hoSbRequestBody
    End
    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComEmitSb Of hoJson vSbRequestBody To iSuccess

    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComPTextSb Of hoHttp "PUT" "https://your-domain.atlassian.net/wiki/rest/api/template" vSbRequestBody "utf-8" "application/json" False False To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

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

    // {
    //   "templateId": "id ipsum ut",
    //   "name": "sit dolor sint dolore",
    //   "description": "magna",
    //   "labels": [
    //     {
    //       "prefix": "fugiat sit Ut in ea",
    //       "name": "dolor in",
    //       "id": "aliqua culpa veniam ea",
    //       "label": "officia tempor ea"
    //     },
    //     {
    //       "prefix": "exercitation culpa proident",
    //       "name": "nulla mollit adipis",
    //       "id": "laborum sint",
    //       "label": "fugiat"
    //     }
    //   ],
    //   "templateType": "in cillum",
    //   "_expandable": {
    //     "body": "anim aute officia in culpa"
    //   },
    //   "_links": {},
    //   "body": {
    //     "value": "aute sit pariatur consequat deserunt",
    //     "representation": "anonymous_export_view",
    //     "_expandable": {
    //       "content": "nulla cillum reprehenderit"
    //     },
    //     "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

    Get ComStringOf Of hoJResp "templateId" To sTemplateId
    Get ComStringOf Of hoJResp "name" To sName
    Get ComStringOf Of hoJResp "description" To sDescription
    Get ComStringOf Of hoJResp "templateType" To sTemplateType
    Get ComStringOf Of hoJResp "_expandable.body" To sBody
    Get ComStringOf Of hoJResp "body.value" To sValue
    Get ComStringOf Of hoJResp "body.representation" To sRepresentation
    Get ComStringOf Of hoJResp "body._expandable.content" To sContent
    Get ComStringOf Of hoJResp "body.webresource.uris.all.value" To sAllValue
    Get ComStringOf Of hoJResp "body.webresource.uris.css.value" To sCssValue
    Get ComStringOf Of hoJResp "body.webresource.uris.js.value" To sJsValue
    Get ComStringOf Of hoJResp "body.webresource.tags.all.value" To sAllValue
    Get ComStringOf Of hoJResp "body.webresource.tags.css.value" To sCssValue
    Get ComStringOf Of hoJResp "body.webresource.tags.data.value" To sDataValue
    Get ComStringOf Of hoJResp "body.webresource.tags.js.value" To sJsValue
    Get ComStringOf Of hoJResp "body.webresource.superbatch.value" To sSuperbatchValue
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "labels" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "labels[i].prefix" To sPrefix
        Get ComStringOf Of hoJResp "labels[i].name" To sName
        Get ComStringOf Of hoJResp "labels[i].id" To sId
        Get ComStringOf Of hoJResp "labels[i].label" To sLabel
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "body.embeddedContent" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "body.embeddedContent[i].entityId.value" To sEntityIdValue
        Get ComStringOf Of hoJResp "body.embeddedContent[i].entity.value" To sEntityValue
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "body.webresource.keys" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "body.webresource.keys[i].value" To sValue
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "body.webresource.contexts" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Get ComStringOf Of hoJResp "body.webresource.contexts[i].value" To sValue
        Move (i + 1) To i
    Loop



End_Procedure

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
    "templateId": "<string>",
    "name": "<string>",
    "templateType": "<string>",
    "body": {
        "value": "<string>",
        "representation": "<string>"
    },
    "description": "<string>",
    "labels": [
        {
            "prefix": "ipsum dolor Excepteur Duis",
            "name": "nulla et ipsum voluptate consectetur",
            "id": "nostrud enim proident cupidatat eu",
            "label": "enim Lorem veniam amet"
        },
        {
            "prefix": "amet",
            "name": "officia adipisicing ut labo",
            "id": "ipsum in tempor",
            "label": "est occaecat magna"
        }
    ],
    "space": {
        "key": "<string>"
    }
}'
https://your-domain.atlassian.net/wiki/rest/api/template

Postman Collection Item JSON

{
  "name": "Update content template",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"templateId\": \"<string>\",\n    \"name\": \"<string>\",\n    \"templateType\": \"<string>\",\n    \"body\": {\n        \"value\": \"<string>\",\n        \"representation\": \"<string>\"\n    },\n    \"description\": \"<string>\",\n    \"labels\": [\n        {\n            \"prefix\": \"ipsum dolor Excepteur Duis\",\n            \"name\": \"nulla et ipsum voluptate consectetur\",\n            \"id\": \"nostrud enim proident cupidatat eu\",\n            \"label\": \"enim Lorem veniam amet\"\n        },\n        {\n            \"prefix\": \"amet\",\n            \"name\": \"officia adipisicing ut labo\",\n            \"id\": \"ipsum in tempor\",\n            \"label\": \"est occaecat magna\"\n        }\n    ],\n    \"space\": {\n        \"key\": \"<string>\"\n    }\n}"
    },
    "url": {
      "raw": "{{baseUrl}}/api/template",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "template"
      ]
    },
    "description": "Updates a content template. Note, blueprint templates cannot be updated\nvia 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 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    \"templateId\": \"<string>\",\n    \"name\": \"<string>\",\n    \"templateType\": \"<string>\",\n    \"body\": {\n        \"value\": \"<string>\",\n        \"representation\": \"<string>\"\n    },\n    \"description\": \"<string>\",\n    \"labels\": [\n        {\n            \"prefix\": \"officia ea in eu\",\n            \"name\": \"commodo mollit\",\n            \"id\": \"veniam minim nisi quis officia\",\n            \"label\": \"commodo\"\n        },\n        {\n            \"prefix\": \"cupidatat dolor aliqua laboris\",\n            \"name\": \"officia amet\",\n            \"id\": \"voluptate ad quis p\",\n            \"label\": \"eu sit adipisicing ea Ut\"\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\": \"id ipsum ut\",\n \"name\": \"sit dolor sint dolore\",\n \"description\": \"magna\",\n \"labels\": [\n  {\n   \"prefix\": \"fugiat sit Ut in ea\",\n   \"name\": \"dolor in\",\n   \"id\": \"aliqua culpa veniam ea\",\n   \"label\": \"officia tempor ea\"\n  },\n  {\n   \"prefix\": \"exercitation culpa proident\",\n   \"name\": \"nulla mollit adipis\",\n   \"id\": \"laborum sint\",\n   \"label\": \"fugiat\"\n  }\n ],\n \"templateType\": \"in cillum\",\n \"_expandable\": {\n  \"body\": \"anim aute officia in culpa\"\n },\n \"_links\": {},\n \"body\": {\n  \"value\": \"aute sit pariatur consequat deserunt\",\n  \"representation\": \"anonymous_export_view\",\n  \"_expandable\": {\n   \"content\": \"nulla cillum reprehenderit\"\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 update the\ntemplate.",
      "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    \"templateId\": \"<string>\",\n    \"name\": \"<string>\",\n    \"templateType\": \"<string>\",\n    \"body\": {\n        \"value\": \"<string>\",\n        \"representation\": \"<string>\"\n    },\n    \"description\": \"<string>\",\n    \"labels\": [\n        {\n            \"prefix\": \"officia ea in eu\",\n            \"name\": \"commodo mollit\",\n            \"id\": \"veniam minim nisi quis officia\",\n            \"label\": \"commodo\"\n        },\n        {\n            \"prefix\": \"cupidatat dolor aliqua laboris\",\n            \"name\": \"officia amet\",\n            \"id\": \"voluptate ad quis p\",\n            \"label\": \"eu sit adipisicing ea Ut\"\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": ""
    }
  ]
}