Confluence REST API v2 — Create page with atlas_doc_format representation

I’m trying to use the Confluence REST API v2 API to create a new wiki page whose body is in the atlas_doc_format. I can’t seem to get anything except a 400 Bad Request response with a body of Invalid message. Does anyone have any suggestions on what I’m doing wrong with the request?

The POST request is being made to https://(my org).atlassian.net/wiki/api/v2/pages, with the following request body (formatted here for readability):

{
  "spaceId": 9867790169,
  "status": "draft",
  "title": "Equipment Sales",
  "body": {
    "representation": "atlas_doc_format",
    "value": {
      "body": {
        "type": "doc",
        "content": [
          {
            "type": "paragraph",
            "content": [
              {
                "type": "text",
                "text": "foo 3"
              }
            ]
          },
          {
            "type": "heading",
            "attrs": {
              "level": 2
            },
            "content": [
              {
                "type": "text",
                "text": "Background"
              }
            ]
          },
          {
            "type": "paragraph",
            "content": [
              {
                "type": "text",
                "text": "bar 3"
              }
            ]
          }
        ],
        "version": 1
      }
    }
  }
}

The ADF content was generated using the Python pyadf module.

What part is causing the invalid message?

Figured out yesterday that the body value needs to be JSON encoded, not passed as the underlying object. The correct form is like the following (value has been abbreviated).

{
  "spaceId": 9867790169,
  "status": "draft",
  "title": "Equipment Sales",
  "body": {
    "representation": "atlas_doc_format",
    "value": "{\"type\": \"doc\", \"content\": [{\"type\": \"paragraph\", \"content\": [{\"type\": \"text\", \"text\": \"foo 3\"}]}]}"
  }
}
1 Like

what kind of encoding is this?