Forums

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

Error 415 when uploading attachment to Confluence via REST API?

Jeremiah Watkins
Contributor
March 22, 2023 edited

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
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events