Encapsulating Confluence Storage Format Content when Modifying an Existing Page with PUT API Calls
Asked by Faith Ntundi:

Hello everyone,

I am working on publishing reports that I generate through a pipeline using ansible.

I'm using jinja2 to filter specific parameters that are the output of the pipeline into a json file. I'm using the lookup function of ansible to pull the json file in as the body of my uri call (-d if we're using curl). The issue I'm running into is that the content within the "value" parameter of the body keeps breaking. '

I've verified that the api call works with a basic "value" parameter like "Test Page".

I've also verified that I'm setting the version parameter to the current+1 version.

My jinja2 template looks like this:

```
{"id":"{{ confluence_pageid }}","type":"page","title":"Title","space":{"key":"KEY"},"body":{"storage":{"value":"<p><strong>Deployment Summary</strong></p><table class=\"wrapped\"><tbody><tr><th class=\"highlight-#79e2f2\" data-highlight-colour=\"#79e2f2\" scope=\"col\" title=\"Background color : Medium teal 45%\"><p title=\"\"><strong>Deployment Parameter</strong></p></th><th class=\"highlight-#79e2f2\" data-highlight-colour=\"#79e2f2\" scope=\"col\" title=\"Background color : Medium teal 45%\"><p title=\"\"><strong>Content</strong></p></th></tr><tr><td><p>Deployment Environment</p></td><td><p>{{ deploy_env }}</p></td></tr><tr><td><p>Deployed Release</p></td><td><p>{{ deploy_release }}</p></td></tr><tr><td><p>Previosly Deployed Release</p></td><td><p>{{ deploy_release_prev }}</p></td></tr><tr><td><p>Incoming Branch</p></td><td><p>{{ merged_branch.stdout }}</p></td></tr><tr><td><p>Author</p></td><td><p>{{ author.stdout }}</p></td></tr><tr><td><p>Approved By</p></td><td><p>{{ approver.stdout }}</p></td></tr><tr><td><p>Triggerring Commit</p></td><td><p>{{ trigger_commit }}</p></td></tr><tr><td><p>Previous Commit</p></td><td><p>{{ prev_commit }}</p></td></tr><tr><td><p>Bamboo Build Number</p></td><td><p>{{ bamboo_bld_num }}</p></td></tr><tr><td><p>Time of Job Initiation</p></td><td><p>{{ time_init }}</p></td></tr><tr><td><p>Bamboo Deploy Job Results URL</p></td><td><p>{{ job_result_url }}</p></td></tr><tr><td><p>Bamboo Build Job Results URL</p></td><td><p>{{ bamboo_bld_job_results }}</p></td></tr></tbody></table><p><strong>Pre-Deployment Status of Changed Files:</strong></p><p>Hostname: {{ target_hostname }}</p><p>{{ predeploy_out.stdout }}</p><p><strong>Deployed Files on Target Server:</strong></p><p>Hostname: {{ target_hostname }}</p><p>{{ postdeploy_out.stdout }}</p><p><strong>Git Diff of Deployed Files:</strong></p><p>{{ content_diff.stdout }}</p>","representation":"storage"}},"version":{"number":{{ new_page_version }} }}'"
```

My ansible task looks like this:  
>
> ```
>     - name: Update Confluence page
>
>       uri:
>
>         url: "{{ confluence_api }}/{{ confluence_pageid }}"
>
>         method: PUT
>
>         headers:
>
>           Authorization: "Bearer {{ confluence_token }}"
>
>           Content-Type: "application/json"
>
>           X-Atlassian-Token: "no-check"
>
>         body_format: json
>
>         body: "{{ lookup('file','{{ deploy_home }}/{{ deploy_job }}/{{ bamboo_bld_num }}/deployment_report-{{ trigger_commit }}.json') }}"
>
>       register: confluence_response
> ```

Is anyone aware of a way to get around this issue? Are there other approaches that you've used to post markdown code to confluence programmatically?

I would appreciate any tips or resources you can point me to.

Thanks for taking the time.


Answers:
author: Faith Ntundi
body: [@Atlassian](/t5/user/viewprofilepage/user-id/5360237) Is there an answer to this? Any insight into what can be done here?


Tags: confluence-server

server