how to update data from csv file to confluence tables using rest api in python
Asked by Ratnala Preethi:

I wrote the code to put data into existing confluence page. My code is like below.I'm using Python here

```
import requests
import json


url = 'https://domain.atlassian.net/wiki/rest/api/content/pageid'

headers ={
'Accept':'application/json',
'Authorization': 'basic <access token>',
'content_type':'application/json'}

payload = json.dumps({
'version':{
number:version number},
'title':'title of existing page',
'type':'page',
'status':'current',
'body':{
'storage':{
'value':'''
```

```
<tbody><tr><th><p><strong>header1</strong></p></th><th><p><strong>header2</strong></p></th>

<th><p><strong>header3</strong></p></th><th><p><strong>header4</strong></p></th>

<th><p><strong>Remarks</strong></p></th></tr><tr><td><p>DRLT</p></td><td><p>Drogas Lithuania</p></td>

<td><p>i want to update data here from csv file</p></td>

<td><p>csv data</p></td>

<td><p></p></td></tr><tr><td><p>branch</p></td><td><p>csv data</p></td>

<td><p>csv data</p></td>
<td><p>csv data</p></td>

```

```
html code of confluence page. It has 5 tables.'''
'representation':'storage'}}})

response = requests.request(
"put"
url,
data = payload
headers = headers)

print(json.dumps(json.loads(response.text),sort_keys= True, indent = 4,separoters=(",",":")


```

I'm new to this confluence I have no idea how to update data into confluence tables using rest apis. I every time changing data in html code and put into confluence page.

I want to update data into 3 tables in html code from csv file automatically

like every time run script it'll read csv data and change html table contents itself.

How can i achieve that?

Please help me through this..........


Answers:
author: Alexey Mikhaylov _Stiltsoft_
body: Hello [@Ratnala Preethi](/t5/user/viewprofilepage/user-id/4994955),

If your company uses our [Table Filter and Charts for Confluence](https://marketplace.atlassian.com/apps/27447/table-filter-and-charts-for-confluence?tab=overview&hosting=cloud&utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources&utm_vendorID=1216111) app, you may use its [Table from CSV](https://docs.stiltsoft.com/display/public/TFAC/How+to+use+Table+from+CSV+macro?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources%20&utm_vendorID=1216111) macro.

It may not be exactly your case, but it is possible to output data from a URL, and you won't need to manually refresh a CSV file (you will just need to refresh your Confluence page for the data from CSV to be actual).

Best regards,

Alexey

comments: author: Ratnala Preethi
body: Thank you [@Alexey Mikhaylov _Stiltsoft_](/t5/user/viewprofilepage/user-id/4967674) for your response

My page have some text and tables, But I need some clarification on that we need to put whole page layout in python script to add this csv data into tables. do we?

what I'm actually doing now is I convert csv data into lists then add it to string value of my page layout like below

```
csv_data=['data1','data2']

'value' = 'This is the confluence page...........
<table><td>{csv_data}</td></table>'.format(csv_data=csv_data[0])

```

Do you have an idea to put directly that csv data to particular table without mention whole page layout in script.


author: Alexey Mikhaylov _Stiltsoft_
body: Hello [@Ratnala Preethi](/t5/user/viewprofilepage/user-id/4994955),

our [Table from CSV](https://docs.stiltsoft.com/display/public/TFAC/How+to+use+Table+from+CSV+macro?utm_source=atl_community&utm_medium=answer&utm_campaign=table-filter-traffic-sources%20&utm_vendorID=1216111) macro is for the cases when you need to build a specific table based on a CSV file from a URL or an attached file. Restoring the whole page with layouts and additional data is not covered by this macro.


Tags: cloud

confluence-cloud