Chilkat Online Tools

DataFlex / Atlassian Confluence Cloud / Get macro body by macro ID

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sName
    String sBody
    String sTemp1

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

    // Adds the "Authorization: Bearer <access_token>" header.
    Set ComAuthToken Of hoHttp To "<access_token>"

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComQuickGetSb Of hoHttp "https://your-domain.atlassian.net/wiki/rest/api/content/:id/history/:version/macro/id/:macroId" vSbResponseBody To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    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 ComLastStatus Of hoHttp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComLastHeader Of hoHttp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Procedure_Return
    End

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

    // {
    //   "name": "nulla reprehenderit qui",
    //   "body": "adipisicing fugiat magna eu ullamco",
    //   "parameters": {},
    //   "_links": {}
    // }

    // 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 "name" To sName
    Get ComStringOf Of hoJResp "body" To sBody


End_Procedure

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
https://your-domain.atlassian.net/wiki/rest/api/content/:id/history/:version/macro/id/:macroId

Postman Collection Item JSON

{
  "name": "Get macro body by macro ID",
  "request": {
    "auth": {
      "type": "oauth2"
    },
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "{{baseUrl}}/api/content/:id/history/:version/macro/id/:macroId",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "content",
        ":id",
        "history",
        ":version",
        "macro",
        "id",
        ":macroId"
      ],
      "variable": [
        {
          "key": "id",
          "value": "<string>",
          "type": "string",
          "description": "(Required) The ID for the content that contains the macro."
        },
        {
          "key": "version",
          "value": "<integer>",
          "type": "string",
          "description": "(Required) The version of the content that contains the macro."
        },
        {
          "key": "macroId",
          "value": "<string>",
          "type": "string",
          "description": "(Required) The ID of the macro. This is usually passed by the app that the\nmacro is in. Otherwise, find the macro ID by querying the desired\ncontent and version, then expanding the body in storage format.\nFor example, '/content/196611/version/7?expand=content.body.storage'."
        }
      ]
    },
    "description": "Returns the body of a macro in storage format, for the given macro ID.\nThis includes information like the name of the macro, the body of the macro,\nand any macro parameters. This method is mainly used by Cloud apps.\n\nAbout the macro ID: When a macro is created in a new version of content,\nConfluence will generate a random ID for it, unless an ID is specified\n(by an app). The macro ID will look similar to this: '50884bd9-0cb8-41d5-98be-f80943c14f96'.\nThe ID is then persisted as new versions of content are created, and is\nonly modified by Confluence if there are conflicting IDs.\n\nNote, to preserve backwards compatibility this resource will also match on\nthe hash of the macro body, even if a macro ID is found. This check will\neventually become redundant, as macro IDs are generated for pages and\ntransparently propagate out to all instances.\n\n**[Permissions](https://confluence.atlassian.com/x/_AozKw) required**:\nPermission to view the content that the macro is in."
  },
  "response": [
    {
      "name": "Returned if the requested macro body is returned.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/history/:version/macro/id/:macroId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "history",
            ":version",
            "macro",
            "id",
            ":macroId"
          ],
          "variable": [
            {
              "key": "id"
            },
            {
              "key": "version"
            },
            {
              "key": "macroId"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n \"name\": \"nulla reprehenderit qui\",\n \"body\": \"adipisicing fugiat magna eu ullamco\",\n \"parameters\": {},\n \"_links\": {}\n}"
    },
    {
      "name": "Returned if the authentication credentials are incorrect or missing\nfrom the request.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/history/:version/macro/id/:macroId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "history",
            ":version",
            "macro",
            "id",
            ":macroId"
          ],
          "variable": [
            {
              "key": "id"
            },
            {
              "key": "version"
            },
            {
              "key": "macroId"
            }
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    },
    {
      "name": "Returned if;\n\n- There is no content with the given ID.\n- The calling user does not have permission to view the content.\n- The macro does not exist in the specified version.\n- There is no macro matching the given macro ID or hash.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": {
              "content": "Added as a part of security scheme: oauth2",
              "type": "text/plain"
            },
            "key": "Authorization",
            "value": "<token>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/content/:id/history/:version/macro/id/:macroId",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "content",
            ":id",
            "history",
            ":version",
            "macro",
            "id",
            ":macroId"
          ],
          "variable": [
            {
              "key": "id"
            },
            {
              "key": "version"
            },
            {
              "key": "macroId"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "text",
      "header": [
        {
          "key": "Content-Type",
          "value": "text/plain"
        }
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}