Initial code example
This commit is contained in:
52
post.php
Normal file
52
post.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
// Initialize cURL session
|
||||
$ch = curl_init();
|
||||
|
||||
// Set the URL for the request
|
||||
// URL needs to be changed for production system
|
||||
$url = 'https://rt.anothermouse.com/rt/REST/2.0/ticket';
|
||||
|
||||
// Set the headers
|
||||
// Authorization token must be changed to something valid for production
|
||||
$headers = [
|
||||
'Content-Type: application/json',
|
||||
'Authorization: token 1-14-a73040d70e3ca097c863368cb6169839'
|
||||
];
|
||||
|
||||
// Set the POST data
|
||||
$data = [
|
||||
'Queue' => 'General',
|
||||
'Subject' => 'hello world3',
|
||||
'CustomFields' => ['Hub Name' => 'North America'],
|
||||
'Priority' => '1'
|
||||
];
|
||||
|
||||
//Other values are exampled: https://docs.bestpractical.com/rt/5.0.3/RT/REST2.html#Basic-Auth
|
||||
|
||||
// Convert the data array to JSON
|
||||
$json_data = json_encode($data);
|
||||
|
||||
// Set cURL options
|
||||
curl_setopt($ch, CURLOPT_URL, $url); // Set URL
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return response as a string
|
||||
curl_setopt($ch, CURLOPT_POST, true); // Use POST method
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); // Set POST data
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // Set headers
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL verification (equivalent to `-k` in curl)
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // Don't check hostname in certificate
|
||||
|
||||
|
||||
// Execute the cURL request
|
||||
$response = curl_exec($ch);
|
||||
|
||||
// Check for errors
|
||||
if ($response === false) {
|
||||
echo 'Curl error: ' . curl_error($ch);
|
||||
} else {
|
||||
echo 'Response: ' . $response;
|
||||
}
|
||||
|
||||
// Close the cURL session
|
||||
curl_close($ch);
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user