osticket_url = $url; } if ( $api_key != '' ) { $this->osticket_api_key = $api_key; } } /** * @param $data * @return bool|int */ function addTicket( $data ) { //$data = array( // 'subject' => '', //Ticket subject // 'message' => '', //Ticket body, customer sees. // 'internal_note' => '', //Ticket internal note. // 'note' => '', //From user note. // 'name' => '', //From Name // 'email' => '', //From Email // 'alert' => false, //Alert to staff // 'autorespond' => false, //Auto-respond to creator of ticket // 'staffId' => null, //Assign to specific staff // 'deptId' => null, //Assign to specific department // 'attachments' => [], //Attachments array. //); /* * Add in attachments here $data['attachments'][] = array('filename.pdf' => 'data:image/png;base64,' . base64_encode(file_get_contents('/path/to/filename.pdf'))); */ //$data['attachments'][] = array( basename( $attachment_file ) => 'data:'. mime_content_type( $attachment_file ).';base64,'. base64_encode( file_get_contents( $attachment_file ) ) ); $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $this->osticket_url . '/api/tickets.json' ); curl_setopt( $ch, CURLOPT_POST, 1 ); curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $data ) ); curl_setopt( $ch, CURLOPT_USERAGENT, 'osTicket API Client v1.7' ); curl_setopt( $ch, CURLOPT_HEADER, false ); curl_setopt( $ch, CURLOPT_HTTPHEADER, [ 'Expect:', 'X-API-Key: ' . $this->osticket_api_key ] ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); $result = curl_exec( $ch ); $code = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); curl_close( $ch ); if ( $code != 201 ) { Debug::Text( ' ERROR: osTicket addTicket failed! Code: ' . $code, __FILE__, __LINE__, __METHOD__, 10 ); return false; } $ticket_id = (int)$result; Debug::Text( ' osTicket addTicket success! Ticket ID: ' . $ticket_id, __FILE__, __LINE__, __METHOD__, 10 ); return $ticket_id; } } ?>