Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,414,337
Community Members
 
Community Events
170
Community Groups

Getting 500 Internal Server error while trying to upload attachment to Confluence using Powershell

Hi,

 

I am trying to upload attachments to Confluence page using Powershell. This is part of a script I am working to generate some reports and upload those to Confluence page. 

Here is my script block where I am getting the error:

$cred = Get-Credential
$filePath = ".\incident.txt"

$ConfluenceURL = "https://<confluence url>/rest/api/content/"
$ConfluencePageID = "<pageid>"
$Headers = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(($cred.UserName+":"+[System.Runtime.InteropServices.marshal]::PtrToStringAuto([System.Runtime.InteropServices.marshal]::SecureStringToBSTR($cred.Password)) )))}
$attchment = "/child/attachment"

$body = @{
file = ".\incident.txt"
comment = "Test File"
} | ConvertTo-Json


$uri = "$($ConfluenceURL)$($ConfluencePageID)$($attchment)"
Invoke-RestMethod -Uri $uri -Method Post -ContentType "multipart/form-data" -Headers $Headers -Body $body

 

ERROR:

Invoke-RestMethod : The remote server returned an error: (500) Internal Server Error.
At line:1 char:1
+ Invoke-RestMethod -Uri $uri -Method Post -Conten ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Please help me to fix this issue. Am I doing anything wrong in the REST call. I tried Invoke-WebRequest with same result. However, GET operation works fine.

2 answers

0 votes

Did you get a resolution to this issue? I am having the same issue same issue and could do with pointers on resolving this

It's long time since I had this issue. I think I documented the process here :

https://arindamhazra.com/managing-attachments-in-confluence-using-powershell/

 

Thanks

Arindam

Hi @Arindam Hazra it would be helpful to check your server log file. Can you provide it?

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events