80 lines
2.1 KiB
PHP
80 lines
2.1 KiB
PHP
<?php
|
|
// Test script to debug create_ticket_api.php
|
|
echo "=== Testing create_ticket_api.php ===\n\n";
|
|
|
|
// Get API key from command line argument
|
|
if (!isset($argv[1])) {
|
|
echo "Usage: php test_api.php <api_key>\n";
|
|
echo "Example: php test_api.php d8f356a06bd5612eca9c5ff948b592a56020cc61937764461458372c9ef30932\n";
|
|
exit(1);
|
|
}
|
|
|
|
$apiKey = $argv[1];
|
|
echo "API Key: " . substr($apiKey, 0, 10) . "...\n\n";
|
|
|
|
// Test data
|
|
$testTicket = [
|
|
'title' => 'Test Ticket from PHP Script',
|
|
'description' => 'This is a test ticket to debug the API',
|
|
'priority' => '3',
|
|
'category' => 'Test',
|
|
'type' => 'Issue',
|
|
'status' => 'Open'
|
|
];
|
|
|
|
echo "Sending test ticket...\n";
|
|
echo "URL: http://10.10.10.45/create_ticket_api.php\n\n";
|
|
|
|
// Make the API call
|
|
$ch = curl_init('http://10.10.10.45/create_ticket_api.php');
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
'Content-Type: application/json',
|
|
'Authorization: Bearer ' . $apiKey
|
|
]);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($testTicket));
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
|
|
|
// Capture verbose output
|
|
$verbose = fopen('php://temp', 'w+');
|
|
curl_setopt($ch, CURLOPT_STDERR, $verbose);
|
|
|
|
$response = curl_exec($ch);
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
$curlError = curl_error($ch);
|
|
|
|
// Get verbose output
|
|
rewind($verbose);
|
|
$verboseLog = stream_get_contents($verbose);
|
|
fclose($verbose);
|
|
|
|
curl_close($ch);
|
|
|
|
echo "HTTP Code: $httpCode\n";
|
|
echo "cURL Error: " . ($curlError ?: 'None') . "\n\n";
|
|
|
|
echo "=== Raw Response ===\n";
|
|
echo "Length: " . strlen($response) . " bytes\n";
|
|
echo "Content:\n";
|
|
var_dump($response);
|
|
echo "\n";
|
|
|
|
if ($response) {
|
|
echo "=== Decoded JSON ===\n";
|
|
$decoded = json_decode($response, true);
|
|
if ($decoded === null) {
|
|
echo "ERROR: Failed to decode JSON\n";
|
|
echo "JSON Error: " . json_last_error_msg() . "\n";
|
|
} else {
|
|
print_r($decoded);
|
|
}
|
|
} else {
|
|
echo "ERROR: Empty response received\n";
|
|
}
|
|
|
|
echo "\n=== cURL Verbose Log ===\n";
|
|
echo $verboseLog;
|
|
echo "\n";
|