# Working Bulk Import Node JS example

**URL:** <https://community.auth0.com/t/working-bulk-import-node-js-example/99991>\
**Category:** Get Help\
**Tags:** user-import-export, user-management\
**Created:** [February 8, 2023, 1:30pm UTC](https://community.auth0.com/t/working-bulk-import-node-js-example/99991 "2023-02-08T13:30:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevin.richards1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kevin.richards1/32/44012_2.png) [@kevin.richards1](https://community.auth0.com/u/kevin.richards1)\
**Post date:** [February 8, 2023, 1:30pm UTC](https://community.auth0.com/t/working-bulk-import-node-js-example/99991/1 "2023-02-08T13:30:59Z")

</div>

I’ve tried the example on the documents ([Bulk User Imports](https://auth0.com/docs/manage-users/user-migration/bulk-user-imports#request-bulk-user-import)), 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](https://community.auth0.com/t/bulk-user-imports-node-js-example-does-not-work/62482)).

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)  
> }  
> };

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [February 8, 2023, 7:19pm UTC](https://community.auth0.com/t/working-bulk-import-node-js-example/99991/3 "2023-02-08T19:19:05Z")

</div>

Hi @kevin.richards1,

Thanks for reaching out to the Auth0 Community!

I have tested the [Bulk User Import endpoint](https://auth0.com/docs/api/management/v2#!/Jobs/post_users_imports) using Node.js on my end and got a working sample. Could you please try the following code and see how it goes?

```auto
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);
});

```

I look forward to your update.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![kevin.richards1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kevin.richards1/32/44012_2.png) [@kevin.richards1](https://community.auth0.com/u/kevin.richards1)\
**Post date:** [February 24, 2023, 9:14am UTC](https://community.auth0.com/t/working-bulk-import-node-js-example/99991/4 "2023-02-24T09:14:25Z")

</div>

Yeah, that seems to work. Perhaps you could update the help docs with that example.

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [December 13, 2024, 6:34am UTC](https://community.auth0.com/t/working-bulk-import-node-js-example/99991/5 "2024-12-13T06:34:16Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
