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

Create Ticket API and Attachments

I have a WordPress site where I am using a plugin called Formidable Forms. I have created this form and used an action hook to post to the osTicket API, which works with the exception of attachments. The attachments are uploaded to a Amazon S3 bucket before the form is submitted. Every time a ticket is created, there is no attachment. I did error checking and haven't come up with anything. When you've been looking at code for hours, you need an extra pair of eyes to see what you are doing wrong. Any help is greatly appreciated. Below is the attachment portion of my code.

    if ($form_id == 11) {
        $debug = "0";
        $config = array(
            'url' => 'https://example.com/api/tickets.json', // URL to site.tld/api/tickets.json
            'key' => 'secretykeypslsiw'  // API Key goes here
        );

        $attachArray = array();
        for ($i = 0; $i < count($_FILES['file141']['name']); $i++) {
            $name[] = $_FILES['file141']['name'][$i];
            $type[] = mime_content_type($_FILES['file141']['name'][$i]);
        }        
        $month = date('m');
        $day = date('d');        
        for($x=0;$x<count($name);$x++) {
            $attachArray = array( $name[$x] => "data:$type[$x];base64;" . base64_encode(file_get_contents("https://s3.amazonaws.com/my-assets/wp-content/uploads/$month/$day/$name[$x]")) );
        }

        $data = array(
            'attachments' => $attachArray
        );
    }
Tagged:

Comments

  • I honestly have no idea if the ticket api works with the s3 plugin... I've never tried.  Maybe someone else can assist you on this, I'm afraid I wont be much assistance.
  • Not a problem. But does the rest of the code look pretty legit for multiple attachments? I think it will definitely work with s3; I think the problem is $_FILES['file141']['name']. Which has nothing to do with osTicket. On my end, I just need to figure out why it is return null.
  • The rest of it looks pretty good to me.
Sign In or Register to comment.