sailthru / sailthru-node-client

Sailthru Node.js client
http://docs.sailthru.com
MIT License
17 stars 15 forks source link

problems with bulk user update #31

Closed jsiragusa closed 5 years ago

jsiragusa commented 5 years ago

I'm having issues making a bulk user update. I'm following the docs here https://getstarted.sailthru.com/developers/api/job/#update-json-example, but when I make the call to apiPost it throws an error:

17 Jan 09:11:29 - sailthru-client - https://api.sailthru.com/job
17 Jan 09:11:29 - sailthru-client - MultiPart Request
17 Jan 09:11:29 - sailthru-client - JSON Payload: {"api_key":"XXXXXX","format":"json","json":"{\"job\":\"update\"}","sig":"XXXXXXX","file":{"path":"./userdata.txt","filename":"userdata.txt","fileSize":0,"encoding":"binary","contentType":"application/octet-stream"}}
internal/fs/utils.js:288
    throw err;
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "buffer" argument must be one of type Buffer or Uint8Array. Received type number
    at Object.read (fs.js:440:3)
    at reader (/Users/jon/dev/patch/sailthru/node_modules/restler/lib/multipartform.js:118:13)
    at /Users/jon/dev/patch/sailthru/node_modules/restler/lib/multipartform.js:129:10
    at FSReqWrap.oncomplete (fs.js:139:20)

Here is my relevant code:

const filename = './userdata.txt';
sailthru.enableLogging();
sailthru.apiPostAsync = util.promisify(sailthru.apiPost);
await sailthru.apiPostAsync('job', {'job': 'update', 'file': `${filename}`}, ['file']);

And the contents of userdata.txt (which is in the current directory and readable):

{"id":"user1@example.com","keys":{"extid":"11111"},"fields":{"keys":1},"vars":{"somevar":"abc"}}
{"id":"user2@example.com","keys":{"extid":"22222"},"fields":{"keys":1},"vars":{"somevar":"def"}}
{"id":"user3@example.com","keys":{"extid":"33333"},"fields":{"keys":1},"vars":{"somevar":"ghi"}}

Any ideas? I'm about to dig into the apiPost code, but thought I'd post here first.

marcelhamel commented 5 years ago

This issue was being caused by a dependency that was not updated alongside Node's fs module. This has been updated and should be fixed with the latest update, v3.0.4

jsiragusa commented 5 years ago

Updated to v3.0.4 and can confirm that this is fixed. Thanks!!