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

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


1 badge earned


Participate in fun challenges

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


Gift kudos to your peers

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


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!


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
Community Members
Community Events
Community Groups

Can't use "Create Attachment POST" API: failing to read body. I get "file must be included" error


According to the API documentation all I need to supply is a value for "minorEdit" and "file" with a filepath, but even if I provide no body at all I get the same error "...BadRequestException: At least one attachment file must be included". I wondered if maybe it needs the ACTUAL file not just the path so I tried including content type and base64 encoded text of my image. Also wondered why the documentation says "relative file path"... relative to what? But I'm thinking it's failing before that point altogether: I don't think I'm constructing the body content correctly: does this LOOK correct?

Content-Disposition: form-data; name="minorEdit"
Content-Disposition: form-data; name="file"


Or I found this post Solved: Uploading attachment into Confluence ( which seems to include the actual file content in the post (although it doesn't mention that on the API documentation, that seems more logical?) but that doesn't work either? Should I try different characters for carriage return new line perhaps?

1 answer

1 accepted

OK got it working in the end.

Top tips:

  • Use Postman so you can work out how its mean to work and inspect the HTTP code :D
  • I think they should document this but I guess it's common knowledge: you need to embed the full file data, not just the path... which makes sense. So you should have:
    Content-Disposition: form-data; name="file" ; filename="hmmmm.jpg"
    Content-Type: image/jpg

  • Note you also need the "filename" parameter (also not documented)
  • The hard part is encoding: after you get the API to work, I struggled with this with VBA. Basically the answer is "use ADODB stream to create both the text and binary parts and join them together"
  • Make sure you have TWO CR/LF characters in key places: after the "content-type" and after the second "content-disposition" line (the one with the minorEdit directive). I placed that at the end but i don't think the order matters.
  • If you're getting "stream ended unexpected" errors or "header is too large" or "needs at least one file" error like above, it will likely be either the CRLF thing or like me you missed a "--" from a boundary on one line
  • Dont worry about the content length header that Postman adds: works without it (maybe a good reason to use it some times?)

Was using VBA (one off migration task) hence the need for manually constructing the body (using MSXML2.XMLHTTP60). This is why postman is nice: it's a lot easier to use these days I found too. Just setup auth = "API Key" and put Key = "Authorization" and Value = "Basic [and your base64 encoded username:api-key you got from your Atlassian profile]". Click the little </> icon on the right to view the code snippets: select the "HTTP" one to kinda see the raw info that you can mimic for VBA. Took me 10 minutes to get working in postman and a full day to get working in VBA lol. Hope this helps someone!

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events