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

API-Key doenst work

Dear Community!

After Hours of tryin to get the API to work, im DONE!! :D
I did take some Screenshots in order to explain my Problem better.
Did install the newest Version of osTicket. Did create an API-Key and did download the Sample.php. In there i did replace the Data.

In that Case im gonna get the Error Message: "Unable to create Ticket: " (space after ":" is nothing, cause the Variable $result isnt showin for some reason...)

In the Admin-Panel in osTicket i did change some Contents bout the Forms and Form-Settings. Dont think it has to do with that, isnt? (Pls loook at the Screenshot for further Info)
I did, like in the Instructions and in my Screenshot, change the Variables to match with these in my ticket_create.php File.

Not havin any kind of problem to show my API-Key. Its just a Demo-Site, so its wayne..at the other Point you can have a better look into my situation.

Here i did copy the Code of my ticket_create.php - File which remains meanwhile in the root-Folder of my Webspace. The API Folder is in the /lsticket/api.
Strange is that im not havin any File named tickets.json or somethin like that. Im havin just cron.php, http.php, ecron.php etc..

File api_ticket_create.php
#!/usr/bin/php -q
<?php
error_reporting(E_ALL);
#
# Configuration: Enter the url and key. That is it.
#  url => URL to api/task/cron e.g #  http://yourdomain.com/support/api/tickets.json
#  key => API's Key (see admin panel on how to generate a key)
#

$config = array(
        'url'=> 'http://web4590.ws.mynet.at/lsticket/api/tickets.json',
        'key'=> 'DE588FCA7B5A14340AF7AD4BFC7F1B99');

# Fill in the data for the new ticket, this will likely come from $_POST.

$data = array(
    'name'      =>      'John Doe',
    'email'     =>      'mailbox@host.com',
    'subject'   =>      'Test API message',
    'message'   =>      'This is a test of the osTicket API',
    'ip'        =>      $_SERVER['REMOTE_ADDR'],
    'attachments' => array(),
);

/*
 * Add in attachments here if necessary

$data['attachments'][] =
array('filename.pdf' =>
        'data:image/png;base64,' .
            base64_encode(file_get_contents('/path/to/filename.pdf')));
 */

#pre-checks
function_exists('curl_version') or die('CURL support required');
function_exists('json_encode') or die('JSON support required');

#set timeout
set_time_limit(30);

#curl post
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.8');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key']));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($code != 201)
    die('Unable to create ticket: '.$result);

$ticket_id = (int) $result;

# Continue onward here if necessary. $ticket_id has the ID number of the
# newly-created ticket

?>


Times in Future, the Array will be filled with $_POST Data containing some Stuff from other Forms! But this can only happen if this damn API will work.

If someone notice the Field IP-Adress in the Screenshot (osTicket german Version), did change it with the Help of phpmyadmin. We are usin a subdomain host (see Screenshot), and we cant get a right ip for it, so were usin the subdomain instead. Maybe this is the Problem, but how to resolve?


If someone is rly skilled what hes doin, i can give him the Admin-Account so he can find a way to repair this..
Im hopin you Guys get a solution! Im sittin hours and hours right bfore this Stuff and cant get it workin...

Greetings!


Comments

  • I do not see any screen shots.
    You have not told us what version of osTicket your running.
    You have not told us what version of PHP your running.


Sign In or Register to comment.