It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Postman POST call works, but the same AJAX code does not work in JavaScript

I am using "/rest/api/content/22157686/child/attachment" call to upload an attachment to a Confluence space. When I try this in Postman, the file gets uploaded with no problem. I then tried to write JavaScript code to mimic that call. I used REST request. I could not get that to work even though several other of the Confluence API calls do work, including update a page. So I know the JavaScript is working and set up properly for the other API calls. For the create attachment call though, it seemed like the multipart/form-data was not being properly parsed and sent to the server. To simplify, I tried using AJAX instead of REST and copying the exact code from Postman. After some small modifications with headers, the call seems to be hitting the server, but the response is always null. Here is, more or less, the entire code. It is not long or complicated:

var FormData = require('form-data');
var form = new FormData();
form.append('file', 'C:/Users/<userid>/barnum-2.0/swagger.json');

settings = {
  'async': true,
  'crossDomain': true,
  'url': `https://share-staging.<company>.com/rest/api/content/22157686/child/attachment`,
  'method': 'POST',
  'dataType': 'json',
  'headers': {
  'X-Atlassian-Token': 'nocheck',
  'Cache-Control': 'no-cache',
  'Authorization': authorizationData,
  'X-Content-Type-Options': 'nosniff',
  'Accept': 'application/json; charset=utf-8'
  'processData': false,
  'contentType': false,
  'mimeType': 'multipart/form-data',
  'multipart': true,
  'formData': form

   ajax(settings, function (response) {
      console.log('response :', response)

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Confluence

Lessons and Learnings: Six Months of Working Remote [Discussion]

Hey there, folks! For most of us, the past six months- yes, you read that right- have been a journey. More people than ever before have pivoted to working remotely, and navigating being on-scre...

5,966 views 4 6
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you