-2

I'm trying to convert this curl command into php:

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer API_TOKEN" \
-d '{"image": "ubuntu-16.04"}' \
https://api.hetzner.cloud/v1/servers/42/actions/rebuild

Can anyone help please?

  • Really? There is even one site doing this for you. And it's the first hit on Google for convert curl to php... https://incarnate.github.io/curl-to-php/ – maio290 Apr 11 '19 at 09:38
  • Yes I searching and test code and view other topic but return error from hetzner { "error": { "message": "404 Not Found", "code": "not_found", "details": null } } – alex spraggins Apr 11 '19 at 09:53

1 Answers1

-1

You can use this tool to generate PHP-CURL using curl command parameters.

// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.hetzner.cloud/v1/servers/42/actions/rebuild');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"image\": \"ubuntu-16.04\"}");
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: _ENV["Bearer API_TOKEN"];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
Payam Khaninejad
  • 7,692
  • 6
  • 45
  • 55