Hello,
I have successfully created a Confluence page that includes a “code block” macro via REST API. In the body of the API call I use “representation” = “wiki”, then, the code block starts with “{code:linenumbers=truefirstline=0001|collapse=true}”.
I read that the “code block” macro (and others) will be DA on Feb 2026. Recommendation is to use the “code snippet” element.
This document shows how to use the new “code snippet” from GUI. I am unable to find information about doing this programmatically via REST API… Any leads/ideas? Thank you in advance
Hello Marc,
This is it: Learn which macros are being removed | Confluence Cloud | Atlassian Support
BR
You should be able to update the page using the REST API. To insert a code snippet, just include a codeBlock ADF node like so:
{
"id": "...",
"status": "current",
"title": "...",
"spaceId": ...,
"body": {
"representation": "atlas_doc_format",
"value": "{\"type\":\"doc\",\"content\":[{\"type\":\"codeBlock\",\"attrs\":{\"language\":\"javascript\"},\"marks\":[{\"type\":\"breakout\"}],\"content\":[{\"text\":\"console.log('Hello, World!')\",\"type\":\"text\"}]},{\"type\":\"paragraph\"}],\"version\":1}"
},
"version": {
"number": ...
}
}
Hello Richard,
Thanks for your response. The problem is not about creating a page that includes a “code block” via REST API. If my interpretation of this article is correct, the mechanism you described will be deprecated as it uses the “code block macro”. On the new editor, the feature that replaces that macro is the so-called “code snippet element” described here. The question thus becomes: how to achieve a similar result, via REST API, when the “code block macro” will no longer be available.
BR
Yes the code block macro will be deprecated but that will only affect the legacy editor.. All new Confluence pages you create will be using the new editor in which case you can use my example above. P.S. I was quoting the docs when I referred to it as a “code block”, but it seems the terms “code block” and “code snippet” are interchangeable.
Anyway, this is what the code snippet looks like which is what I believe you are looking for.
OK! Thanks for the clarification. This should solve the question.
BR
