Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

500 internal Server Error when trying to update an attachment using Powershell

Julien Henning
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 7, 2023

I want to update an json file in confluence using the Api and Powershell 


$pageId = "2226721108"  # Replace with the actual page ID
$attachmentId = "2238705975"  # Replace with the actual attachment ID
$apiUrl = "https://HereIsOurServer/confluence/rest/api/content/$pageId/child/attachment/$attachmentId/data"
$proxy = "ourProxy :)"

$headers = @{
    "Authorization" = "Bearer $authToken"
    "X-Atlassian-Token" = "nocheck"
    "Content-Type"="multipart/form-data"
}
$body =@{
    "file" ="StatusTestclients\JiraUpdateTestClients\result.json"
    "minorEdit"=$true
    "comment"="new"
}

# Send the POST request to update the attachment file
Invoke-RestMethod -Uri $apiUrl -Headers $headers -Method Post -Body $body -Proxy $proxy

And here the error i get 
Invoke-RestMethod : Der Remoteserver hat einen Fehler zurückgegeben: (500) Interner Serverfehler.
In C:\Users\WAETEI1\Desktop\toolsetprelive\StatusTestclients\JiraUpdateTestClients\UpLoadDataToConfluence.ps1:19 Zeichen:1
+ Invoke-RestMethod -Uri $apiUrl -Headers $headers -Method Post -Body $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Now is the question what im doing wrong 

1 answer

0 votes
Brant Schroeder
Community Champion
March 26, 2024

@Julien Henning Welcome to the Atlassian community

From the error you are seeing, it would tend to indicate that either the parameters are incorrect or that the json package is incorrect.  Are you able to successfully make any other API calls?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events