auth0 / node-auth0

Node.js client library for the Auth0 platform.
MIT License
628 stars 307 forks source link

management.jobs.importUsers job not working as expected #958

Closed avinash9shelke closed 10 months ago

avinash9shelke commented 10 months ago

Checklist

Description

const importUsers = async (management, connectionId) => {
return await management.jobs.importUsers({
connection_id: connectionId,
users: await readUsersStream(),
upsert: true
});
};

const readUsersStream = async () => {
const readableStream = fs.createReadStream(${getDirectoryPath()}/import_users.json, 'utf8');
let passThrough = new Stream.PassThrough();
readableStream.pipe(passThrough);
readableStream.on('finish', () => {
console.log(Human user restore multi-part file is ready !);
});
//console.log(passThrough);
return passThrough

const job = await importUsers(management, connectionId);
[
{
"user_id": "64f46c5d2f6f2e94869d890e",
"email": "test@gmail.com",
"name": "SaasRoot",
"nickname": "messy",
"created_at": "2023-09-03T11:22:05.906Z",
"updated_at": "2023-10-11T09:26:17.756Z",
"email_verified": false,
"app_metadata": {
"org": "org_czjYbolTZWEaydVg"
}
},
{
"user_id": "64f46c5d2f6f2e94869d890m",
"email": "test@gmail.com",
"name": "test@gmail.com",
"nickname": "test",
"last_ip": "202.91.134.75",
"logins_count": 1,
"created_at": "2023-09-18T14:00:38.345Z",
"updated_at": "2023-09-18T14:01:16.167Z",
"last_login": "2023-09-18T14:00:38.337Z",
"email_verified": true,
"app_metadata": {
"org": "org_czjYbolTZWEaydVg"
}
},
{
"user_id": "64f46c5d2f6f2e94869d890d",
"email": "test@gmail.com",
"name": "test@gmail.com",
"nickname": "test_user",
"last_ip": "185.139.140.82",
"logins_count": 1,
"created_at": "2023-09-27T13:29:02.533Z",
"updated_at": "2023-09-27T13:29:33.177Z",
"last_login": "2023-09-27T13:29:02.530Z",
"email_verified": true,
"app_metadata": {
"org": "org_czjYbolTZWEaydVg"
}
},
{
"user_id": "64f46c5d2f6f2e94869d890h",
"email": "test@gmail.com",
"name": "test@gmail.com",
"nickname": "test_user",
"last_ip": "202.91.135.88",
"logins_count": 3,
"created_at": "2023-10-11T09:05:31.740Z",
"updated_at": "2023-10-11T09:19:56.360Z",
"last_login": "2023-10-11T09:19:56.359Z",
"email_verified": true,
"app_metadata": {
"org": "org_czjYbolTZWEaydVg"
}
}
]

Reproduction

1 . call const job = await importUsers(management, connectionId);

Additional context

No response

node-auth0 version

4.0.1

Node.js version

18

avinash9shelke commented 10 months ago

Getting the below issue - 2023-10-25T07:48:00.285Z 3e74e6f8-3e5f-4dcf-99fe-50d8782b7e61 INFO ManagementApiError: Payload validation error: 'Invalid multipart payload format'. at JobsManager.parseError (/opt/nodejs/node_modules/auth0/dist/cjs/management/management-client.js:33:16) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async JobsManager.request (/opt/nodejs/node_modules/auth0/dist/cjs/lib/runtime.js:119:23) at async JobsManager.importUsers (/opt/nodejs/node_modules/auth0/dist/cjs/management/__generated/managers/jobs-manager.js:103:26) at async importUsers (/var/task/backup_restore/auth0-utils.js:64:12) at async importUserData (/var/task/backup_restore/restore/RestoreHumanService.js:132:21) at async restore (/var/task/backup_restore/restore/RestoreHumanService.js:50:5) at async exports.handler (/var/task/backup_restore/restore/handler.js:16:24) { errorCode: 'invalid_body', error: 'Bad Request', statusCode: 400, body: {"statusCode":400,"error":"Bad Request","message":"Payload validation error: 'Invalid multipart payload format'.","errorCode":"invalid_body"}, headers: HeadersList { cookies: null, [Symbol(headers map)]: Map(19) { 'date' => [Object], 'content-type' => [Object], 'content-length' => [Object], 'connection' => [Object], 'cf-ray' => [Object], 'cf-cache-status' => [Object], 'cache-control' => [Object], 'strict-transport-security' => [Object], 'vary' => [Object], 'access-control-expose-headers' => [Object], 'ot-baggage-auth0-request-id' => [Object], 'ot-tracer-sampled' => [Object], 'ot-tracer-spanid' => [Object], 'ot-tracer-traceid' => [Object], 'traceparent' => [Object], 'tracestate' => [Object], 'x-content-type-options' => [Object], 'server' => [Object], 'alt-svc' => [Object] },

}, msg: "Payload validation error: 'Invalid multipart payload format'." }

adamjmcgrath commented 10 months ago

Hi @avinash9shelke - thanks for raising this

importUsers takes a Blob (not a ReadStream) - more information, including an example, here https://github.com/auth0/node-auth0/blob/master/v4_MIGRATION_GUIDE.md#import-users-now-takes-a-blob

frederikprijck commented 10 months ago

Closing, as I think this was answered. Can always reopen if needed.