When I try and import the same file using curl, it works, but when I use node I get a 500 error with no useful information, just “internal server error”
import axios from “axios”;
import fs from “fs”;
import FormData from “form-data”;
I have tested the Bulk User Import endpoint using Node.js on my end and got a working sample. Could you please try the following code and see how it goes?
var axios = require('axios');
var FormData = require('form-data');
var fs = require('fs');
var data = new FormData();
data.append('users', fs.createReadStream('YOUR_FILE_PATH_NAME'));
data.append('connection_id', 'YOUR_CONNECTION_ID');
var config = {
method: 'post',
url: 'https://YOUR_DOMAIN/api/v2/jobs/users-imports',
headers: {
'Authorization': 'Bearer YOUR_MANAGEMENT_API_TOKEN',
'Content-Type': 'application/json',
...data.getHeaders()
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});