Hello everyone,

Currently working on setting up a form with API ticket creation. I would like to start off that our setup is in AWS and we have the HTTP to HTTPS redirect. I have tested the API create ticket PHP script provided by osticket on a local install and the ticket is created successfully via API on the local setup. Now when it comes to the AWS osticket we get a 302 redirection code. we have enabled the followlocation when performing the curl opt. below is a sample of the code. Your help is greatly appreciated. error code above example code.

302 Unable to create ticket:

<?php

$config = array(
'url'=>'http://mydomain.com/api/tickets.json',
'key'=>'APIKEY123'
);

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.7');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key']));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

echo $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

?>

@mario294

What errors are you getting via Admin Panel > Dashboard > System Logs? If none, enable Debug Log Level (in system settings) and retest.

My theory is the IP changes making the API deny the request, as the API keys are specific to IP addresses.

Cheers.

    KevinTheJedi

    I was finally able to create a ticket after a lot of googling and testing many different CURL commands.

    So the issue was that the call would reach the server but would only reply back with a 302 code "HTTP-HTTPS forwarding"
    after inputting these few lines of code to the api_ticket_create.php I was finally able to create the ticket now I'll work on getting some of these form ids to link with osticket custom form variables. Below are the 2 lines of code needed for the ticket creation via api for anyone else who may face this issue with AWS EBS osticket setup. Hopefully, my discovery will help others.

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($ch, CURLOPT_POSTREDIR,1);

    Write a Reply...