Uploading and updating an Image to Confluence using the REST API


If you have automated systems sometimes it is useful to have them interact with your documentation from time to time.  Using the Confluence REST API you can upload an image as an attachment to the page and later update it if required.  If you follow the Atlassian documentation you end up getting a denied request for the update as it wishes for the new file to have a different filename. Below are the curl lines to post and then update the image.  Change your page ID and attachment ID as required:``` curl -D- -k -u $user:$pass -p -H “X-Atlassian-Token: nocheck” -X POST \ -F [email protected] https://confluence.domain.tld/confluence/rest/api/content/$page_id/child/attachment

curl -D- -k -u $user:$pass -p -H "X-Atlassian-Token: nocheck" -X POST \\
 -F [email protected] https://confluence.domain.tld/confluence/rest/api/content/$page\_id/child/attachment/$attach\_id/data
```In the first request you should have a JSON response with Results->ID->att123456 - the attach\_id to be used above is just the numeric part of this string, i.e. 123456.