Translate CURL command to PHP CURL? Cloudflare API
I'm trying to use the CloudFlare API via PHP CURL, however the doc examples show up as a command line curl.
$ curl -X PUT "https://api.cloudflare.com/client/v4/zones/9a7806061c88ada191ed06f989cc3dac/dns_records/9a7806061c88ada191ed06f989cc3dac" \
-H "X-Auth-Email: user@example.com" \
-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 PUT request the same as POST? And the array at the bottom is confusing me. Don't know how this translates into PHP CURL.
+3
source to share
1 answer
You will need to make a post, but also submit your own request. Then Curl will style the post
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
Then add headers as needed
curl_setopt($ch, CURLOPT_HTTPHEADER, [array of your headers]);
Modify the array as an array of key values, where key is the header name and value is the header value
+1
source to share