I have a custom PowerShell API that allows us to perform some Hyper-v functions via an API.
The call to create a VM looks like this:
http://wk-api-001.hypermice.net:8888/?command=Create-VPS%20-VmHost%20%22wk-devhyp-001.hypermice.net%22%20-Memsize%204GB%20-VMname%20%22test100%22%20-cpucount%204%20-Imagecode%201
I now need to call this from PHP, which is a pretty alien language to me and am really struggling. So far I have this:
$headers = array();
$headers[] = "Content-Type: application/json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://wk-api-001.hypermice.net:8888/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "?command=create-vps%20-vmhost%20%22wkdevhyp-001.hypermice.net%22%20-vmname%20%22WHMCSTest01%22%20-Memsize%204gb%20-cpucount%204%20-Imagecode%201" );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($ch, CURLOPT_USERPWD, "frank:M0nk3ydust!!!");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
print $result;
When I execute this code, I am hitting the end point, but it is not passing the actual commands, which I have defined here on CURLOPT_POSTFIELDS.
My feeling is this is not the correct place to define this, or they are not defined correctly but I don't know enough about CURL to work it out.
Any help would be much appreciated.
?in your POST data does not belong there. Do you really need POST data? Isn't the API using GET??.