Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

JSON API Documents and AWS intergration

I assume it is not possible to update a Ticket from the API ? I would love to integrate with AMAZON SQS .  Currently I have all help desk requests sent in via e-mail end up on a AWS Queue.  I want to use node to process them and put them into osTicket.  It works for new Tickets but there is no method to provide an update that I'm aware of. 

To bad the API can't detect that a ticket already exists and just update it. 

Sample Code Node.JS JSON Ticket creation from e-mail message.
Tagged:

Comments

  • var MailParser = require("mailparser").MailParser;
    var mailparser = new MailParser({
        streamAttachments: false
    });
    var request = require('request');
    var fs = require('fs');

  • fs.readFile('./test.txt', 'utf8', function (err, data) {
        if (err) {
            return console.log(err);
        }
        // setup an event listener when the parsing finishes 
        mailparser.on("end", function (mail_object) {
            console.log("From:", mail_object.from); //[{address:'sender@example.com',name:'Sender Name'}] 
            console.log("Subject:", mail_object.subject); // Hello world! 
            //  console.log("Text body:", mail_object.text); // How are you today?
            var osTicketAttachments = [];
            if (mail_object.attachments) {
                var tmpAttach =  "";
                var tmpFileName = "";
                var tmpFileType ="";
                for (i = 0; i < mail_object.attachments.length; i++) {
                   var tmpAttach = mail_object.attachments[i]
                   //var tmpFileName = '"'+ tmpAttach.fileName +  '"';  //Name with Quotes
                   var tmpFileName =  tmpAttach.fileName //+  ''; 
                   tmpFileName.replace('"',"")
                   var tmpFileType = "data:" + tmpAttach.contentType +";"+tmpAttach.transferEncoding +","

                 osTicketAttachments.push( {[tmpFileName]  : tmpFileType + tmpAttach.content.toString("base64") })
                  // osTicketAttachments.push( JSON.parse ("'{tmpFileName  :'"+ tmpFileType + tmpAttach.content.toString("base64") +"}"))
                   tmpAttach = {};
                   tmpFileNameee = "";
                   tmpFileType="";
                } 
            }
            request({
                url: 'http://helpdesk.test.com/osticket/upload/api/http.php/tickets.json', //URL to hit       
                method: 'POST',
                headers: {
                    'X-API-Key': '7BFC4B9103930DD4B'
                },
                //Lets post the following key/values as form
                json: {
                    "name": mail_object.from[0].name,
                    "email": mail_object.from[0].address,
                    "subject": mail_object.subject,
                    "message": "data:text/html;charset=utf-8;" + mail_object.html,
                    "topicId": "1",
                    "attachments": osTicketAttachments        
                }
            }, function (error, response, body) {
                if (error) {
                    console.log(error);
                } else {
                    console.log(response.statusCode, body);
                }
            });
        });
        // send the email source to the parser 
        mailparser.write(data);
        mailparser.end();});
  • You have three posts in this thread, the first post explains what your issue is, somewhat. But what are the last two posts referring to?
Sign In or Register to comment.