I always getting the same error (Create domain 'example.com' failed) (or any domain) when trying to create new DNS zone with Powerdns API call.
My request:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'http://127.0.0.1:953/api/v1/servers/localhost/zones');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"name\":\"example.com.\", \"kind\":\"Native\", \"masters\": [], \"nameservers\":[\"ns1.example.com.\", \"ns2.example.com.\"]}");
$headers = array();
$headers[] = 'X-Api-Key: MY-KEY';
$headers[] = 'Accept: application/json';
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
Similar api call to get a list of DNS zones is working. GET request work properly but not POST. Can anyone help, please?
My pdns.conf file is:
api=yes
api-key=MY-KEY
Maybe i have to change something in settings of my powerdns, idk really. I would be very grateful for any help!
Server response after POST request is 422 error (Unprocessable Entity)
HTTP/1.1 422 Unprocessable Entity Access-Control-Allow-Origin: * Connection: close Content-Length: 52 Content-Security-Policy: default-src 'self'; style-src 'self' 'unsafe-inline' Content-Type: application/json Server: PowerDNS/4.4.1 X-Content-Type-Options: nosniff X-Frame-Options: deny X-Permitted-Cross-Domain-Policies: none X-Xss-Protection: 1; mode=block
This is my pdns.conf file
cat /etc/pdns/pdns.conf
bind-ignore-broken-records=yes
setuid=named
setgid=named
launch=bind
log-dns-queries=yes
loglevel=5
bind-config=/etc/named.conf
bind-dnssec-db=/var/cpanel/pdns/dnssec.db
local-address-nonexist-fail=no
distributor-threads=1
disable-axfr=yes
webserver=yes
api=yes
webserver-address=127.0.0.1
webserver-allow-from=0.0.0.0/0
webserver-password=SERVER-KEY
#gmysql-dnssec=no
webserver-port=953
api-key=MY-KEY
upgrade-unknown-types=1