Error 415 when uploading attachment to Confluence via REST API?

Jeremiah Watkins March 22, 2023

I'm trying to upload a file as an attachment to a Confluence page via the REST API, but I keep getting error 415, which according to this page means "Unsupported Media Type".

I have Confluence Server so I'm going off of this example in Confluence Server's REST API documentation. I've also looked at this from the Confluence Cloud documentation, but it looks basically the same.

I'm using PowerShell; here's my code ('<confluence server>', '<pageID>', and '<basicAuth>' are obviously substitutions):

Invoke-RestMethod `
    -Method POST `
    -Uri https://<confluence server>/confluence/rest/api/content/<pageID>/child/attachment `
    -InFile file.txt `
    -Headers @{
      Authorization = "Basic <basicAuth>"
    }

I've found many of the same/similar questions and most of the answers are to set the correct Content Type. Many of the answers point to this page, which says the same.

I've tried all variations of content types and none of them work:

  • application/json
  • application/text
  • text/plain
  • application/xml
  • multipart/form-data

Nothing is working. The only change happens if I set the content type to simply 'text', then I get a different error:

HTTP Status 400 – Bad Requestbody

It's a plain text file, but ultimately I'll be uploading different file types like docx, etc. so hopefully the content type isn't filetype-specific.

Is there a content type I'd use for any general purpose file upload?

Any help is appreciated.

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events