-
-
Notifications
You must be signed in to change notification settings - Fork 51
Description
Current behavior
I´m trying to attach file to a new ticket creation using the below sintax:
freshdesk.createTicket(
{
description: "test description",
attachments: [
fs.createReadStream("/path/to/file1.ext"),
fs.createReadStream("/path/to/file2.ext"),
],
},
function (err, data) {
console.log(err || data);
}
);
And I´m getting the following error message:
(node:15224) UnhandledPromiseRejectionWarning: TypeError: source.on is not a function
at Function.DelayedStream.create (/path/to\node_modules\delayed-stream\lib\delayed_stream.js:33:10)
at FormData.CombinedStream.append (/path/to\node_modules\combined-stream\lib\combined_stream.js:45:37)
at FormData.append (/path/to\node_modules\form-data\lib\form_data.js:75:3)
at makeRequest (/path/to\node_modules\freshdesk-api\lib\utils.js:155:11)
at Freshdesk.createTicket (/path/to\node_modules\freshdesk-api\lib\client.js:147:3)
at createProviderTicket (/path/to\routes\provider.js:8701:13)
at Layer.handle [as handle_request] (/path/to\node_modules\express\lib\router\layer.js:95:5)
at next (/path/to\node_modules\express\lib\router\route.js:137:13)
at Immediate. (/path/to\node_modules\multer\lib\make-middleware.js:53:37)
at processImmediate (internal/timers.js:458:21)
(node:15224) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:15224) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Expected behavior
It should include de file as attachment as per documentation.
More details
File is being uploaded.
This is how my code is: (ticket creation without attachment is workinh fine)
var TicketObj = {}
TicketObj.type = "Question";
TicketObj.name = name.replace(/[|&;$#%"<>()+,]/g, "");
TicketObj.email = email.replace(/[|&;$#%"<>()+,]/g, "");
TicketObj.subject = subject.replace(/[|&;$#%"<>()+,]/g, "");
TicketObj.description = description.replace(/[|&;$#%"<>()+,]/g, "");
TicketObj.status = 2; //(open)
TicketObj.source = 2; //(portal)
TicketObj.priority = parseInt(priority ? priority : 1); //(low)
TicketObj.custom_fields = {
cf_origin:"provider",
cf_instance:ProviderUserId
}
var src = req.files.attachedFile[0].destination+"/"+req.files.attachedFile[0].filename;
var attachment = fs.createReadStream(src);
TicketObj.attachments = [attachment]
// Create Ticket
freshdesk.createTicket(
TicketObj,
function (err, data) {
// if error
if (err) {
res.status(200);
return res.json({
error: err,
success:false,
failedCreation:true,
message: 'Ticket NOT created'
});
} // end if
// Store Requester ID and Id of the created ticket for late consult
// ...
res.status(200);
return res.json({
error: false,
data: data,
success:true,
message: 'Ticket created'
});
}
);
Anyone?
{ 'freshdesk-api': '2.4.0',
npm: '5.5.1',
http_parser: '2.7.0',
icu: '58.2',
modules: '48',
node: '6.12.0',
zlib: '1.2.11' }
provide stacktrace (if available)