Sure, no problem. I have created a small function execCLAPICmd which executes an http request. As you can see, it always uses http POST. It’s exceedingly simple.
<?php
$authhash = base64_encode(“user:password”);
$headers = array(“Authorization: Basic $authhash”);
$site = “sitename”;
$process = “processname”;
$thread = “threadname”;
$server = “ourserver.ourdomain.com”;
$cmd = “clapi/api/site/$site/command/process/$process/thread/$thread/start”;
$result = execCLAPICmd($server, 15037, $headers, $cmd);
$result = json_decode($result);
$result = $result->$thread;
echo “status thread: $thread: {$result->state}<br/>”;
var_dump($result); //dump rest of the result object
function execCLAPICmd($hostname, $port, $headers, $cmd) {
//first get xcsrf token
$xcsrf_token_url = “https://$hostname:$port/clapi/api/security/csrf”;
$ch = curl_init($xcsrf_token_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$cookiefile = ‘/tmp/curl-session’; //must be valid directory!
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
$xcsrf_response = curl_exec($ch);
$xcsrf_response_err = curl_error($ch);
if(! empty($xcsrf_response_err)) {
$xcsrf_response = $xcsrf_response_err;
}
$xcsrf_token_obj = json_decode($xcsrf_response);
$xcsrf_token = $xcsrf_token_obj->csrf;
$headers[] = “X-CSRF-TOKEN: $xcsrf_token”;
$url = “https://$hostname:$port/$cmd”;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0); //set to 1 to also output headers
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$return = curl_exec($ch);
$cerr = curl_error($ch);
if(! empty($cerr)) {
$return = $cerr;
}
curl_close($ch);
return $return;
}
?>
-
This reply was modified 5 years, 2 months ago by Arie Klop.