Error creating SRV DNS record

I’ve written a script to set up a number of email settings for Fastmail, setting MX, A, CNAME, TXT and SRV records. They all work, except the SRV record.

I’ve checked how I can create a DNS record via the Cloudflare API (which works for the other types). I’ve copied the values from the Fastmail setup.

This is what I send to the Cloudflare API to create an SRV record:

  • imap record
{
  "Type":"SRV",
  "Name":"_imap._tcp.kenbonny.net",
  "Content":"0 0 0 .",
  "Ttl":1,
  "Priority":null,
  "Proxied":false
}
  • imap secure record
{
  "Type":"SRV",
  "Name":"_imaps._tcp.kenbonny.net",
  "Content":"0 1 993 imap.fastmail.com",
  "Ttl":1,"Priority":null,
  "Proxied":false
}

And this is what I get back (identical in both cases):

{ Result = null
  Success = false
  Errors = [{ Code = 1004
              Message = "DNS Validation Error"
              Error_Chain = [{ Code = 9101
                               Message = "service is a required data field."
                               Error_Chain = null }] }] }

The result is deserialized json, while I pasted the actual json I send over the wire so you can see what I’m actually sending and not the pre-serialized printout.

It complains that the service is a required data field, but according to this Cloudflare explanation the service is encapsulated in the domain (_imap._tcp.kenbonny.net). I have tried sending it with and without a . (dot) at the end of the domain.

So I’m confused why this does not work.

Referring to the API documentation, priority is “Required for MX, SRV and URI records” and must be a number (not null).

However, I’m not seeing this in the documentation and my memory could be wrong, but I remember banging my head against this when I first started using Cloudflare and I have a recollection that you need to send the service and proto as separate parameters too and that Cloudflare builds the record for you.

This community thread shows how it was done in PHP:

Note that that thread is a few years old now, but it matches my recollection.

I went looking online and found similar at Can't add SRV records anymore · Issue #46 · danielpigott/cloudflare-cli · GitHub which shows a working fix in 2019:

{
  "type": "SRV",
  "data": {
    "service": "_test",
    "proto": "_tcp",
    "name": "example.org",
    "priority": 0,
    "weight": 0,
    "port": 1234,
    "target": "server.example.org"
  }
}

I can test this out myself a bit later if you aren’t able to get it going, but give this a shot?

Thank you, this solved my problem. I did not know the SRV record needed another json structure to be passed to the api. I updated the structure and it now works like a charm!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.