How to export macros correctly?
Asked by O?uz:

Hi everyone. I use confluence API to fetch page content (HTML tags) using page id with a Wordpress Shortcode. Most of the elements just being viewed fine in the Wordpress page. But the elements made with macros (Table of Contents or Tabs) are not shown in the Wordpress page (I assume this is because of macros don't create elements with natural HTML). Is there any way to show Table of Contents or Tabs in my Wordpress page? or is there a way to create Table of Contents or Tabs so that confluence api fetches the content without problem?


Answers:
author: Kishan Sharma
body: Hi [@O?uz](/t5/user/viewprofilepage/user-id/4543463) Welcome to the Atlassian Community!

To start with, can you try clicking on the ellipses ... and then View Storage format of the confluence page to get the HTML tags of it and then try adding them in your Wordpress page to see if those are appearing fine ? I think since confluence uses its own stylesheet you might want to apply your custom stylesheet in your wordpress page so that the table of contents are shown correctly.


author: Hana Ku?erov?
body: Hi [@O?uz](/t5/user/viewprofilepage/user-id/4543463) ,

welcome to the Atlassian Community!

If I understand it correctly, what could help in your case is to add query parameter expand with value body.view to your API request.

This way you should be able to get view format of the page (= macros transformed to HTML)

See [here](https://developer.atlassian.com/cloud/confluence/rest/api-group-content/#api-wiki-rest-api-content-id-get) for more info.

comments: author: O?uz
body: Hi [@Hana Ku?erov?](/t5/user/viewprofilepage/user-id/1226304) ,

Thanks for the reply. I tried the thing you said before. But in 'view' format, the macros are fetched as blackboxes.  

```
<p>General description about login, Log out.</p>
<div class=\"toc-macro client-side-toc-macro  conf-macro output-block\" 
data-headerelements=\"H1,H2\" data-hasbody=\"false\" data-macro-name=\"toc\" 
data-macro-id=\"36b423a4e660152a1cc5b3b1f1605726\" 
data-layout=\"default\" data-local-id=\"6d921f5b-e029-4891-8da9-75dd3c8f4cc2\"> </div>
<h2 id=\"LogIn/LogOut-LoginwithEmailandPassword\">Login with Email and Password</h2>
<p>Login with email and password</p>
```

I fetched this particular example with Postman (This is a part of the view format of a page)

As you can see, the table of contents macro is fetched as a \<div\> and its content is empty. It has only metadata in its tag. I used macro's id (**data-macro-id** property) to fetch its content via confluence API's **GET /wiki/rest/api/content/{id}/history/{version}/macro/id/{macroId}** route (Click [here](https://developer.atlassian.com/cloud/confluence/rest/api-group-content---macro-body/#api-wiki-rest-api-content-id-history-version-macro-id-macroid-get) for the page).

And I got a response:  

```
{

    "name": "toc",
    "body": "",
    "parameters": {

        "minLevel": {
            "value": "1"
        },
        "maxLevel": {
            "value": "2"
        }
    },
    "_links": {

        "base": "https://medianova.atlassian.net/wiki",
        "context": "/wiki"
    }
}
```

But still no HTML tags for the table of contents. Let's say I somehow analyzed the headers of the content and added the tags of table of contents by myself. But still, tabs feature is missing. But luckily, I managed to fetch the content of the tabs macro in storage view (using the route **GET /wiki/rest/api/content/{id}/history/{version}/macro/id/{macroId}**)  

```
{

    "name": "tabs-macro",
    "body": "[{\"label\":\"JSON\",\"id\":\"1\",\"content\":{\"version\":1,\"type\":\"doc\",\"content\":[{\"type\":\"codeBlock\",\"attrs\":{},\"content\":[{\"type\":\"text\",\"text\":\"{\\n\\\"email\\\": \\\"example@medianova.com\\\",\\n\\\"password\\\": \\\"cdfsxcdfdnv38849.\\\"\\n}\"}]},{\"type\":\"paragraph\",\"content\":[]}]}},{\"label\":\"Curl\",\"id\":\"2\",\"content\":{\"version\":1,\"type\":\"doc\",\"content\":[{\"type\":\"codeBlock\",\"attrs\":{},\"content\":[{\"type\":\"text\",\"text\":\"curl -X 'POST' \\\\\\n  'https://cloudproductapi-dev.medianova.com/api/login' \\\\\\n  -H 'accept: application/json' \\\\\\n  -H 'Content-Type: application/json' \\\\\\n  -H 'X-CSRF-TOKEN: ' \\\\\\n  -d '{\\n  \\\"email\\\": \\\"example@medianova.com\\\",\\n\\\"password\\\": \\\"cdfsxcdfdnv38849.\\\"\\n}'\"}]},{\"type\":\"paragraph\",\"content\":[]}]}}]",
    "parameters": {

        "alignment": {
            "value": "\"left\""
        }
    },
    "_links": {

        "base": "https://medianova.atlassian.net/wiki",
        "context": "/wiki"
    }
}
```

But still, no HTML tags.


author: Hana Ku?erov?
body: Hi [@O?uz](/t5/user/viewprofilepage/user-id/4543463) ,

I've found [this discussion](https://community.developer.atlassian.com/t/dynamic-content-macro-how-to-retrieve-rendered-macro-body/24515), maybe it would help.

[This endpoint](https://developer.atlassian.com/cloud/confluence/rest/api-group-content-body/#api-wiki-rest-api-contentbody-convert-to-post) is promising, but according to the discussion there are some problems.


Tags: cloud

confluence-cloud