Updating attachment in Confluence cloud will lead to 403

Trying to update an attachment via the REST API in Confluence cloud. The following code 'should' do the trick, but it doesn't. The result is always 'HTTP Status 403 - Request not in an authorized API scope'. The code is executed in the clients browser and not on the either server.

var formdata = new FormData();
                        var blob = new Blob([xml], { type: "text/xml"});
                        formdata.append(document.getElementById("modelname").value, xml);
                        AP.request({
                            url: '/rest/api/latest/content/'+location.context.contentId+'/child/attachment',
                            type: 'POST',
                            contentType: 'multipart/form-data',
                            data: {comment: 'Edited', minorEdit: false, file: formdata},
                            success: function(responseText){
                                console.info(responseText);
                            },
                            error: function(xhr, statusText, errorThrownText) {
                                console.error('Wrongsie!'+statusText);
                            }
                        });

My scopes as set in atlassian-connect.json

"scopes": [
        "read", "write", "delete"
    ]

What am I doing wrong?

1 answer

The REST API call was wrong - seems like there are different versions out there and mixing them up is not a good idea...

Documentation is here: https://docs.atlassian.com/confluence/REST/latest/

Dropping the "latest" part in the URL did the trick. Corrent call goes to: POST /rest/api/content/{id}/child/attachment/{attachmentId}/data

I have a question indirectly related to your answer.  Whenever  I have tried this call from the browser, it results in an XSRF check failed because the X-Atlassian-Token header is missing, and AP limits the headers you are allowed to set? Were you able to set the header or make the request through AP without it?

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

359 views 20 10
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you