Problem doing bulk updates to my domain

I am creating a script that includes a function to update several rrsets:

domain='krokinole.de'
curl_opts='-GsS -m 5 --retry 5 --retry-max-time 60'
auth_opts='Authorization: Token [redacted]'

function dns_update ()
{
  curl -X PATCH ${curl_opts}  \
    "https://desec.io/api/v1/domains/${domain}/rrsets/" \
    --header "Content-Type: application/json" --header "${auth_opts}" \
    -d @- <<EOF
    [
      {"subname": "sarkovy, "type": "CNAME", "ttl": 3600, "records": ["${1}"]},
      {"subname": "mail", "type": "CNAME", "ttl": 3600, "records": ["${1}"]},
      {"subname": "", "type": "MX", "records": ["10 ${1}"]}
    ]
EOF
}

The function argument is a valid domain string. I copied the code from here, slightly modified. Executing the function always produces an error from curl:

curl: (3) URL rejected: Malformed input to a URL function

I just can’t figure out the reason.

The reason is that, in contrast to the example code, your code uses -G to make curl append all the data you send to the server, the part between <<EOF and EOF, to the URL as the query string. Because the data becomes part of the URL, curl expects some characters to be encoded and throws that error when they occur unencoded. Spaces for example cannot occur unencoded in a URL.

Now that you know what causes the error, note that the API does not specify GET as a valid method.

1 Like

Thanks! So ‘-G’ takes precedence over ‘-X’? I didn’t expect that.

What’s the point of -G then if you didn’t expect it to do anything anyway? An AI told you to put that there, didn’t it?

1 Like

No. That was a leftover from an earlier stage in the development of the script I’m writing.