1. Go to this page and download the library: Download rajangdavis/osvc_php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rajangdavis / osvc_php example snippets
// Configuration is as simple as requiring the library
// and passing in an associative array
nterface credentials
"password" => getenv("OSVC_PASSWORD"), # => store these in environmental
"interface" => getenv("OSVC_SITE"), # => variables in your .bash_profile
// Custom Domain for custom vhost
// "custom_domain" => getenv("OSVC_VHOST"),
// Session Authentication
// "session" => <session ID>,
// OAuth Token Authentication
// "oauth" => <oauth token>,
### optional configuration
# Use 'rightnowdemo' namespace instead of 'custhelp'
"demo_site" => true # => Defaults to false.
# Sets the version of the REST API to use
"version" => 'v1.4', # => Defaults to 'v1.3'.
# Turns off SSL verification; don't use in production
"no_ssl_verify" => true, # => Defaults to false.
# Lets you supress business rules
"suppress_rules" => true, # => Defaults to false.
# Lets you supress external events
"suppress_events" => true, # => Defaults to false.
# Lets you supress external events and business rules
"suppress_all" => true, # => Defaults to false.
# Adds an access token to ensure quality of service
"access_token" => "My access token"
));
$rn_client = new OSvCPHP\Client(array(
"username" => getenv("OSVC_ADMIN"),
"password" => getenv("OSVC_PASSWORD"),
"interface" => getenv("OSVC_SITE"),
"suppress_rules" => true
));
$options = array(
// set the client for the request
"client" => $rn_client,
// Adds a custom header that adds an annotation (CCOM version must be set to "v1.4" or "latest"); limited to 40 characters
"annotation" => "Custom annotation",
// Prints request headers for debugging
"debug" => true,
// Adds a custom header to excludes null from results; for use with GET requests only
"exclude_null" => true,
// Number of milliseconds before another HTTP request can be made; this is an anti-DDoS measure
"next_request" => 500,
// Sets 'Accept' header to 'application/schema+json'
"schema" => true,
// Adds a custom header to return results using Coordinated Universal Time (UTC) format for time (Supported on November 2016+
"utc_time" => true
);
//// OSvCPHP\Connect::post(options)
//// returns an object
// Here's how you could create a new ServiceProduct object
// using PHP variables and associative arrays (sort of like JSON)
ng data
// for creating
// a new product
$new_product = array(
'names' => array(
array(
'labelText' => 'NEW_PRODUCT',
'language' => array('id' => 1)
)
),
'displayOrder' => 4,
'adminVisibleInterfaces' => array(
array(
'id' => 1
)
),
'endUserVisibleInterfaces' => array(
array(
'id' => 1
)
),
);
$options = array(
"client" => $rn_client,
"url" => "serviceProducts",
"json" => $new_product,
"debug" => true
);
$post_response = OSvCPHP\Connect::post($options);
//// OSvCPHP\Connect::get(options)
//// returns an object
// Here's how you could get an instance of ServiceProducts
"interface" => getenv("OSVC_SITE"),
));
$options = array(
"client" => $rn_client,
"url" => "serviceProducts/56",
);
$post_response = OSvCPHP\Connect::get($options);
//// OSvCPHP\Connect::patch(options)
//// returns an object
// Here's how you could update a Service Product object
// using JSON objects
// to set field information
ed_product = array(
'names' => array(
array(
'labelText' => 'UPDATED_PRODUCT',
'language' => array('id' => 1)
)
),
'displayOrder' => 4,
'adminVisibleInterfaces' => array(
array(
'id' => 1
)
),
'endUserVisibleInterfaces' => array(
array(
'id' => 1
)
),
);
$options = array(
"client" => $rn_client,
"url" => "serviceProducts/268",
"json" => $updated_product,
);
$patch_response = OSvCPHP\Connect::patch($options);
//// OSvCPHP\Connect::delete(options)
//// returns an object
// Here's how you could delete a serviceProduct object
,
"interface" => getenv("OSVC_SITE"),
));
$options = array(
"client" => $rn_client,
"url" => "serviceProducts/56",
);
$delete_response = OSvCPHP\Connect::delete($options);
//// OSvCPHP\Connect::options(options)
//// returns headers object or a raw Response object on error
// Here's how you can fetch options for incidents
"),
));
$options = array(
"client" => $rn_client,
"url" => "incidents",
);
$options_response = OSvCPHP\Connect::options($options);
// Find our position in the file tree
if (!defined('DOCROOT')) {
$docroot = get_cfg_var('doc_root');
define('DOCROOT', $docroot);
}
/************* Agent Authentication ***************/
// Set up and call the AgentAuthenticator
enticator::authenticateCredentials($username,$password));
// initialize a curl request
$ch = curl_init();
// set the base of the url
$url = "https://". getenv('OSVC_SITE') .".custhelp.com/cgi-bin/"
// add the location of the above file
$url .= getenv('OSVC_CONFIG') .".cfg/php/custom/login_test.php"
// add the credentials for getting a session ID
$url .= "?username=". getenv('OSVC_ADMIN') ."&password=". getenv('OSVC_PASSWORD');
// set the URL
curl_setopt($ch, CURLOPT_URL, "$url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// execute
$output = curl_exec($ch);
// close curl
curl_close($ch);
$session_id = json_decode($output)->session_id;
$rn_client = new OSvCPHP\Client(array(
"session" => $session_id,
"interface" => getenv("OSVC_SITE"),
));
$options = array(
"client" => $rn_client,
"query" => "SELECT * FROM INCIDENTS LIMIT 10"
);
$mq = new OSvCPHP\QueryResults();
$results = $mq->query($options);
echo json_encode($results, JSON_PRETTY_PRINT);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.