It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Upload table via the API using powershell

I want to use confluence to automate some auditing of our enviroments but am running into errors when I try and upload data via the API. 

Honestly i think i may be approaching this the wrong way so please feel free to correct me.

I am collecting data from AD then using the built in Convertto-html command. After a litle clean up my data looks like bellow

<head>
<title>HTML TABLE</title>
</head><body>
<table>
<colgroup><col/><col/><col/></colgroup>
<tr><th>SamAccountName</th><th>LastLogonDate</th><th>Description</th></tr>
<tr><td>Usern.nme1</td><td>13/10/2019 10:05:05</td><td>Fleet</td></tr>
<tr><td>Usern.nme2</td><td>18/09/2018 15:40:12</td><td>CSR Team 
</table>
</body>

I then add this with some other data to a variable calle $body, which looks like the following: 

{"type":"page","title":"90 day inactivity report", "version":{"number":7},"body":{"storage":{"value":"<head>
<title>HTML TABLE</title>
</head><body>
<table>
<colgroup><col/><col/><col/></colgroup>
<tr><th>SamAccountName</th><th>LastLogonDate</th><th>Description</th></tr>
<tr><td>Usern.nme1</td><td>13/10/2019 10:05:05</td><td>Fleet</td></tr>
<tr><td>Usern.nme2</td><td>18/09/2018 15:40:12</td><td>CSR Team 
<tr><td>Usern.nme1</td><td>16/06/2018 17:54:21</td><td>CSR</td></tr>
</table>
</body>","representation":"storage"}}}

And then issue the following to upload the data

Invoke-RestMethod https://jira.domain.co.uk/confluence/rest/api/content/45056041?expand=body.storage -Method Put -Headers $Headers -Body $body

 

and get this error

Invoke-RestMethod : The remote server returned an error: (500) Internal Server Error.
At line:1 char:1

 

My feeling is it doesnt like a character in the data, as i tried this with just "test" as the payload and it works without issue. but the error is so vague.

 

Can anyone tell me how could i:

 

  • Get more informaiton from the API as to why a quiery falled
  • Upload special characters via the API
  • Just help in general

 

Thanks in advance

1 answer

Some further investigation suggests that this is caused by my table being a array.. 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
Community showcase
Posted in Confluence

Lessons and Learnings: Six Months of Working Remote [Discussion]

Hey there, folks! For most of us, the past six months- yes, you read that right- have been a journey. More people than ever before have pivoted to working remotely, and navigating being on-scre...

8,560 views 6 7
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you