Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translate command CURL to PHP CURL? Cloudflare API

I am trying to use the CloudFlare API via PHP CURL however the doc examples show as command line curl.

$ curl -X PUT "https://api.cloudflare.com/client/v4/zones/9a7806061c88ada191ed06f989cc3dac/dns_records/9a7806061c88ada191ed06f989cc3dac" \
-H "X-Auth-Email: [email protected]" \
-H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
-H "Content-Type: application/json" \
--data '{"id":"9a7806061c88ada191ed06f989cc3dac","type":"A","name":"example.com","content":"1.2.3.4","proxiable":true,"proxied":false,"ttl":120,"locked":false,"zone_id":"9a7806061c88ada191ed06f989cc3dac","zone_name":"example.com","created_on":"2014-01-01T05:20:00.12345Z","modified_on":"2014-01-01T05:20:00.12345Z","data":{}}'

Is the PUT request the same as POST? And the array at the bottom is confusing me. No idea how that translates to PHP CURL.

like image 299
ThatGuy343 Avatar asked Aug 23 '26 10:08

ThatGuy343


1 Answers

You will need to do a post but also send a custom request. Curl will then do a post style put

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");  
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); 

Then add the headers if needed

curl_setopt($ch, CURLOPT_HTTPHEADER, [array of your headers]);

Change the array to be a key value array where the key is the header name and value is the header value

like image 178
exussum Avatar answered Aug 25 '26 23:08

exussum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!