- Edited
Hi,
I want to generate a ticket using the api from an external system in php, but it throws error 200 since I am using the key according to the ip. What can be wrong?
My PHP:
`<?php
$config = array(
'url'=>'mesaayudaimg.mideplan.cl/api/tickets.json', // URL to site.tld/api/tickets.json
'key'=>'04EE8066743552714317C389943CC6DD' // API Key goes here
);
$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']
);
function_exists('curl_version') or die('CURL support required');
function_exists('json_encode') or die('JSON support required');
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('code: '.$code.' Unable to create ticket: '.$result);
$ticket_id = (int) $result;
if(isset($ticket_id) && $ticket_id!='')
{
echo "Ticket Created Sucessfully";
}else{
echo "Ticket not created. Try again later.";
}
?>`
My JSON File in "mesaayudaimg.mideplan.cl/api/tickets.json":
{
"alert": true,
"autorespond": true,
"source": "API",
"name": "Angry User",
"email": "api@osticket.com",
"subject": "Testing API",
"message": "",
"ip": "192.168.0.18"
}
And API created in administrator:
And Result: