Hi Good days sirs,
I am currently working on crerating ticket via rest api and my codes are below
const NAME_DIR = "/NAME/:NAME";
const EMAIL_DIR = "/EMAIL/:EMAIL";
const MOBILE_DIR = "/MOBILE/:MOBILE";
const SUBJECT_1_DIR = "/SUBJECT_1/:SUBJECT_1";
const SUBJECT_2_DIR = "/SUBJECT_2/:SUBJECT_2";
const MESSAGE_DIR = "/MESSAGE/:MESSAGE";
//const LAST_UPDATE_DIR = "/LAST_UPDATE/:LAST_UPDATE";

app.post("/push_ticket_DATA/:SYSTEM_KEY"
+ NAME_DIR
+ EMAIL_DIR
+ MOBILE_DIR
+ SUBJECT_1_DIR
+ SUBJECT_2_DIR
+ MESSAGE_DIR
// + LAST_UPDATE_DIR
, (req, res) => {
console.log("Accessing Patient Data with System Key: " + req.params.SYSTEM_KEY);

    const SYSTEM_KEY_REQ = req.params.SYSTEM_KEY

    const NAME_REQ = req.params.NAME
    if (NAME_REQ == null || NAME_REQ.toUpperCase() == 'NULL') { var NAME_VALUE = '' }
    else { var NAME_VALUE = req.params.NAME }

    const EMAIL_REQ = req.params.EMAIL
    if (EMAIL_REQ == null || EMAIL_REQ.toUpperCase() == 'NULL') { var EMAIL_VALUE = '' }
    else { var EMAIL_VALUE = req.params.EMAIL }

    const MOBILE_REQ = req.params.MOBILE
    if (MOBILE_REQ == null || MOBILE_REQ.toUpperCase() == 'NULL') { var MOBILE_VALUE = '' }
    else { var MOBILE_VALUE = req.params.MOBILE }

    const SUBJECT_1_REQ = req.params.SUBJECT_1
    if (SUBJECT_1_REQ == null || SUBJECT_1_REQ.toUpperCase() == 'NULL') { var SUBJECT_1_VALUE = '' }
    else { var SUBJECT_1_VALUE = req.params.SUBJECT_1 }

    const SUBJECT_2_REQ = req.params.SUBJECT_2
    if (SUBJECT_2_REQ == null || SUBJECT_2_REQ.toUpperCase() == 'NULL') { var SUBJECT_2_VALUE = '' }
    else { var SUBJECT_2_VALUE = req.params.SUBJECT_2 }

    const MESSAGE_REQ = req.params.MESSAGE
    if (MESSAGE_REQ == null || MESSAGE_REQ.toUpperCase() == 'NULL') { var MESSAGE_VALUE = '' }
    else { var MESSAGE_VALUE = req.params.MESSAGE }

    //const LAST_UPDATE_VALUE = new Date(new Date().toString().split('GMT')[0] + ' UTC').toISOString().split('.')[0].replace('T', ' ');

        const queryString = "SELECT * FROM tables WHERE ID = ?"
        connection_to_db.query(queryString, [SYSTEM_KEY_REQ], (err, rows, fields) => {

            if (err) {
                console.log(err)
                res.sendStatus(500)
                throw err
                return
            }

            const system_key_num = rows.length
            const SENDER_VALUE = rows[0].id


            if (system_key_num == 1) {

                var request = require('request'),
                requestData = {
                    name :   NAME_VALUE, //'API User', 
                    email  : EMAIL_VALUE, // 'api_user@gmail.com',
                    phone  : MOBILE_VALUE, //'3185558634123',
                    source : 'API', 
                    subject : SUBJECT_1_VALUE, // Subject Line E.g: test
                    subjects: SUBJECT_2_VALUE, // Sub Topic E.b: test - test
                    message: MESSAGE_VALUE,
                    //ip   :'192.168.1.1',
                    topicId :'18',
                    attachments: [
                        {"file.txt": "data:text/plain;charset=utf-8,content"},
                        {"image.png": "data:image/png;base64,R0lGODdhMAA..."},
                    ]
                };
                request.post({
                    url: 'http://myhelpdesk.support.comh/api/http.php/tickets.json',
                    json: true,
                    headers: {
                        "X-API-Key": 'CUSTOM_API_KEY',
                    },
                    body: requestData
                }, function(error, response, osTicketId) {
                        if(!error){
                            //callback(null, osTicket_supportTicketID);
                            //console.log("Your osTicket Support Ticket ID #", osTicketId);
                            const message = 'Your osTicket Support Ticket ID #' + osTicketId
                            res.json(message);
                        }
                        else
                            // callback(error, null);
                            //console.log("Error creating support ticket! ", err);
                            var message2 = 'Error creating support ticket!'
                            res.json(message2);
                    });


            } else {

                const message = 102  // 102 - Invalid System Key
                res.json(message);

            }




        })


})

but upon sending the data i get an error when i input other email extesion like yahoo.com, company_email.com but when i use gmail i can create ticket successfully.

Is there a way that can make osticket api accept other mail extensions?

by the way the current version of ostickets i am using is osTicket (v1.14.1)

any help will be much appreciated.

Thank you and God Bless

For starters 1.14.1 is ancient and you should update.

Do you have registration disabled?
Do the emails that you use have accounts in osTicket?

    ntozier Do you have registration disabled? -Yes Sir
    Do the emails that you use have accounts in osTicket? - Yes Sir
    my problem is when i use for example test@gmail.com i can successfully create a ticket but if i use somthing like test@yahoo.com or test@company.com i cannot create a new ticket.

    What error are you getting when you try?
    Do you have those emails or domains blocked on the ban list?

      ntozier

      ntozier What error are you getting when you try?
      Do you have those emails or domains blocked on the ban list? None, we does not have any email banned on the list

      Go to: Admin panel -> Manage -> Forms -> Contact Information
      Please post a screen shot of this.

        @vindicon

        I see that your POST data does not match the Field Variable Names. You have name, email, mobile when it should be name, email, phone. Also, try doing lowercase as I believe they are case sensitive (I could be mistaken).

        Cheers.

        Write a Reply...