Converting to ADF(Atlassian Document Format)

Is there any API endpoint or npm library that converts markdown or html to Atlassian document format as shown here

This API endpoint is what you are looking for: https://developer.atlassian.com/cloud/confluence/rest/v1/api-group-content-body/#api-wiki-rest-api-contentbody-convert-to-post

I use it that way:

    const convertResponse = await api.asUser().requestConfluence(route`/wiki/rest/api/contentbody/convert/storage`, {
        method: "POST",
        headers: {
            Accept: "application/json",
            "Content-Type": "application/json",
        },
        body: JSON.stringify({
            value: payload.content,
            representation: "editor",
        }),
    });
  // TODO handle errors
  const confluenceContent = await convertResponse.json();
  const adfDoc = confluenceContent.value

with payload.content a string of HTML, in my case, just a <div> ...</div> without the <html>, <body>

Otherwise, they are multiple packages on NPM, but I didn’t test them.

2 Likes

Thanks for the reply @SilvreLestang

I tried the below code but I am getting the response without any conversion , Am I doing something wrong here.

I tried a lot of npm packages too , but none of them worked well

    let bodyData = `<p>This is paragraph tag</p>`;

    const convertResponse = await requestConfluence(`/wiki/rest/api/contentbody/convert/storage`, {
        method: "POST",
        headers: {
            Accept: "application/json",
            "Content-Type": "application/json",
        },
        body: JSON.stringify({
            value: bodyData,
            representation: "editor",  // Start with "editor"
        }),
    });
    
const confluenceContent = await convertResponse.json();
console.log(confluenceContent)

return
{
    "value": "<p>This is paragraph tag</p>",
    "representation": "storage",
    "_expandable": {
        "webresource": "",
        "embeddedContent": "",
        "mediaToken": ""
    },
    "_links": {
        "base": "https://end2enddemo.atlassian.net/wiki",
        "context": "/wiki"
    }
}

See also https://jira.atlassian.com/browse/JRACLOUD-77436 and in the comments there is conversion by JavaScript code using atlaskit library.

1 Like

Oh my bad, I had in mind that this piece of code was returning ADF, but after checking, it seems to return an HTML that Confluence accept as input for page creation, aka it sort of sanitize the HTML in input, for all the things that Confluence doens’t support.

1 Like

Thanks for trying though

Thanks for the link , it helped a lot

I am planning on offering an API as a service for this. It is very early stage right now but you can try it out if you’d like and let me know if it works for you:
curl -X 'POST' 'https://api.adfapi.dev/api/Html' -H 'accept: text/plain' -H 'Content-Type: text/html' -d '<p>hello world</p>'

1 Like

Thanks for the API endpoint ,

But we’ve decided to use Atlassian libraries to convert HTML to ADF, despite the challenges we’ve faced. Given that we’re handling sensitive information, we want to minimize third-party API calls as much as possible. This approach helps us maintain better control over our data and security.