Search code examples
dnspowerdns

Multiple TXT records with PowerDNS API


I'm trying to add SPF, DMARC and DKIM record for my domain through the PowerDNS HTTP API. This is the sample of the code I found:

curl -X PATCH --data '{"rrsets": [ {"name": "example.org.", "type": "TXT", "ttl": 86400, "changetype": "REPLACE", "records": [ {"content": "Example text", "disabled": false } ] } ] }' -H 'X-API-Key: changeme' http://127.0.0.1:8081/api/v1/servers/localhost/zones/example.org. | jq .

This works, but when I try to insert another txt record, changing only the content, PowerDNS delete the old record and insert the new. This is caused by the "changetype": "REPLACE" argument in curl, but according to docs, I can use two changetype: REPLACE (with this effect) and DELETE (which will simply delete the record).

Does anyone have a solution?


Solution

  • Remember that in DNS we speak about RRset that is Resource Records set, which means possibly more than one result for a given resource type.

    As you can see in https://doc.powerdns.com/md/httpapi/api_spec/#url-apiv1serversserver95idzones ellipsis is shown to mean that you can put multiple items in your "records" element, so you should put all your TXT records at once there.

    So something like (formatted for clarity)

      "records":
        [
          {
            "content": "Example text 1",
            "disabled": false,
          },
          {
            "content": "Example text 2",
            "disabled": false,
          },
          {
            "content": "Example text 3",
            "disabled": false,
          },
        ],
    

    etc.

    The documentation text after it clearly says:

    records: List of new records (replacing the old ones).