I’ve tried the example on the documents (Bulk User Imports), which does not work (as pointed out in May 2021!) and the related community post suggests an alternative solution, which still does not work (Bulk User Imports, Node js example does not work).
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”;export const importUsers = async (filename: string, jobId: string, config: { domain: string, managementApiToken: string, connectionId: string }) => {
const formData = new FormData()
formData.append(“connection_id”, config.connectionId)
formData.append(“users”, fs.createReadStream(filename))try {
const res = await axios.post(https://${config.domain}/api/v2/jobs/users-imports
, formData, {
headers: Object.assign({}, formData.getHeaders(), {
authorization:Bearer ${config.managementApiToken}
})
})
console.log(res.data)
}
catch (err) {
console.log(err)
}
};