I am working on updating my DNS via a PHP script. I've looked at the API documentation relating to cURL so I am trying to convert the cURL post to be PHP.
I have the following code:
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.cloudflare.com/client/v4/zones/<MY_ZONE>/dns_records/<MY_ID>"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); $fields = array(); $fields["X-Auth-Email"] = "[email protected]"; $fields["X-Auth-Key"] = "MY_KEY"; $fields["Content-Type"] = "application/json"; curl_setopt($ch, CURLOPT_HTTPHEADER, $fields); $dnsData = array(); $dnsData["id"] = "MY_ID"; $dnsData["type"] = "A"; $dnsData["name"] = "home"; $dnsData["content"] = $newIPAddress; curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($dnsData)); echo "posting to API<br />"; $result = curl_exec($ch); echo "Result: " . $result; With the above code I am getting the following response back from Cloudflare.
{"success":false,"errors":[{"code":6003,"message":"Invalid request headers","error_chain":[{"code":6100,"message":"Missing X-Auth-Email header"},{"code":6101,"message":"Missing X-Auth-Key header"},{"code":6105,"message":"Invalid Content-Type header, valid values are application/json,multipart/form-data"}]}],"messages":[],"result":null}
I've tried changing the json_encode to http_build_query instead but both return the same error.