Initial code example
This commit is contained in:
parent
41ead55768
commit
03595a6d73
13
README.md
13
README.md
@ -1,3 +1,14 @@
|
|||||||
# RT_REST
|
# RT_REST
|
||||||
|
|
||||||
RT5 REST interface code example
|
RT5 REST interface code example
|
||||||
|
|
||||||
|
## About
|
||||||
|
This is a php implementation of the curl command to provide an example interface to an RT5 system that has been configured for allowing token authentication to the REST 2.0 interface, and this has been provided in order to allow forms to interface with the instance in a simplified fashion.
|
||||||
|
|
||||||
|
## Issues and configuration
|
||||||
|
- The json structure needs to match up correctly with the particular ticket involved, otherwise the information provided is ignored.
|
||||||
|
- Some fields in the ticket are actually numerical rather than text. This applies to the Priority field, where attempting top provide 'Low', rather than the numerical values 1,2,3 will create an error.
|
||||||
|
- The key provided in this example needs to be changed for a valid key for the system concerned. This key merely provides an example of the format.
|
||||||
|
- Authentication of the system being connected to by curl can be ignored using CURLOPT_SSL_VERIFYPEER. This is equivalent of the curl -k switch. This should not be done on a production system.
|
||||||
|
- A second switch CURLOPT_SSL_VERIFYHOST, is included to allow test systems to use 'snake oil' certificates. Again this should be commented out in a production system.
|
||||||
|
|
||||||
|
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);
|
||||||
|
?>
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user