2016-05-17 7 views
0

Ich versuche Ticket mit osticket api_create_ticket.php erstellen, aber ich bekomme Antwort Code 200. Alles ist gleich wie in vielen Dokumentationen und Beispiel beschrieben. Ich habe Server-IP für API-Schlüssel auch versucht, meine System-IP. Habe Schreibrechte für den Ordner bekommen. Aber es funktioniert immer noch nicht.Fehler beim Erstellen von Ticket mit Hilfe von osticket api_create_ticket.php

#!/usr/bin/php -q 
<?php 


$config = array(
    'url'=>'http://myweb.in/project1/support/api/tickets.json', 
    'key'=>'3B2BADDBF72D30DBEBD6378A1DF2E6FB' 
    ); 


    $data = array(
'name'  =>  'John Doe', 
'email'  =>  '[email protected]', 
'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); 

    $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); 

    print_r($code); 

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

    $ticket_id = (int) $result; 

    ?> 
+0

Code Response-200 bedeutet, dass die Anforderung erfolgreich war. –

+0

Ich brauche Antwortcode 201 –

+0

Ich kann es auf meinem Server versuchen. Woher hast du die API? –

Antwort

0

diesen Code versuche ich es https://github.com/osTicket/osTicket-1.7/blob/develop/setup/scripts/rcron.php von hier bekam

<?php 


$config = array(
    'url'=>'http://myweb.in/project1/support/api/tickets.json', 
    'key'=>'3B2BADDBF72D30DBEBD6378A1DF2E6FB' 
    ); 
#check if curl is enabled 
function_exists('curl_version') or die('CURL support required'); 

#set execution time. Make it 0 if there is no time limit 
set_time_limit(60); 

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

    function_exists('curl_version') or die('CURL NOT SUPORTED'); 

    set_time_limit(30); 

    $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, TRUE); 
    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); 

    if(preg_match('/HTTP\/.* ([0-9]+) .*/', $result, $status) && $status[1] == 200) 
exit(0); 
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 

    curl_close($ch); 

    print_r($code); 

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

    $ticket_id = (int) $result; 

    ?> 
+0

Mein Code hat diese Zeile nicht, wenn (preg_match ('/ HTTP \ /.* ([0-9] +). * /', $ Ergebnis, $ Status) && $ Status [1] == 200) exit (0); Denkst du, dass sich etwas ändern wird? –

+0

Überprüfen Sie sorgfältig diese Zeile curl_setopt ($ ch, CURLOPT_HEADER, TRUE); –

+0

Habe diese Variationen schon ausprobiert. –

Verwandte Themen