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 new ticket with API interface-Unable to create the ticket- response 200

Hi team,

I am trying to create new ticket with api interface as documented in the example.  I tried all teh three possible combination along with local ip, hosted server ip and with my isp internet connected ip.  I also tried with two hosting servers.

If Any body successfully integrated with the APi kindly help me. 

I created the API Keys in the admin control panel

PHP Version 5.4.35
MySQL Version 5.5.42-cll
Architecture x86_64
Operating System linux
Shared IP Address 116.251.223.182


Path to Perl /usr/bin/perl
Perl Version 5.10.1


public_html/support/api/apitest.php
-----------------------------------------
#!/usr/bin/php -q
<?php
#
# 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(
        'key'=>'CC1766F755CC9452D77985102AA914B6'
        );

# 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, 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($_SERVER['REMOTE_ADDR'].'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

?>


public_html/support/api/tickets.json
---------------------------------------------------
{
    "alert": true,
    "autorespond": true,
    "source": "API",
    "name": "Angry User",
    "email": "api@osticket.com",
    "phone": "3185558634X123",
    "subject": "Testing API",
    "ip": "117.221.225.67",
    "message": "MESSAGE HERE"
 
}


--------------------------------------------------------------

  -----The output screen looks like this----------

117.221.225.67Unable to create ticket: { "alert": true, "autorespond": true, "source": "API", "name": "Angry User", "email": "api@osticket.com", "phone": "3185558634X123", "subject": "Testing API", "ip": "117.221.225.67", "message": "MESSAGE HERE" }

Comments

  • a HTTP result code of 200 indicates success.
    I'm not really seeing any errors here.
    Have you checked your PHP error log?
    What version of osTicket are you running?
    Are you sure that your agent has access to the department that the tickets would be added to?
    Do you have any "required" fields that you are are not populating?

    Please help us to help you by reading and following the posting guidelines located in this thread: Please read before requesting assistance.  The more information you give us the better we will be able to assist you. Thank you.
  • edited May 2015
    Dear ntozier,
    This is the basic installation done from the osticket site download.  No changes made in to the code or no custom fields, pages,etc. added.
    using /api/apitest.php  (http.php as per the example)  it is giving the error unable to create the ticket. 
    I am not able to figure out from where the error is coming.  I don't know where to dig.  The links provided are still active.  You can check the links. and The code is exactly given in the post.  The API key is still active.
    Os ticket settings
    -------------------
    osTicket Version :v1.9.8 (9c6acce)
    Web Server Software :Apache
    MySQL Version:5.5.42
    PHP Version:5.4.35
    xml: XML API
    xml-dom:Used for HTML email processing
    json: Improves performance creating and processing JSON

  • Please pm me an admin login to your ticket system and I will take a look. (but it might be after the long weekend)
  • The script is written to detect a 201 status not a 200. 
    the difference is 201 means something was created , and the script is instructed to die if its not 201.

    if ($code != 201)
        die('Unable to create ticket: '.$result);
    are your permissions set properly to allow for writeability 
  • I tried permission to 777 for all folders inside osticket.  This gives error - file not found while executing http://www.srfurnituregroup.com/support/api/apitest.php.  I checked the error log and found group permission  error for api folder inside osticket folder.  I changed all folders to 755 and the php is executing but giving unable to create ticket error.
  • Hi @byju
    i worked 2 days without get results. but in the 3rd.day i tried with this direction and work fine

    $config = array(
    'url'=>'http://192.168.0.1:81/ost/upload/api/tickets.json',
    'key'=>'fake-API-number-12312323'
    );
    if i traslate in your direction can be:
    http://www.srfurnituregroup.com/ost/upload/api/tickets.json
    please try it.
    Regards.
Sign In or Register to comment.