Hi everyone,
I’m trying to add a static DNS record using the MikroTik API, but I’m encountering an error message “Bad Request” with the add command.
Here’s the command I’m using:
curl -X POST -H "Content-Type: application/json" -u "dns:verysecurepass" -d '{"name": "pve01.netspeedy.io", "address": "10.29.10.11", "ttl": "1d", "disabled": "false", "dynamic": "false"}' http://10.xx.xx.1/rest/ip/dns/static
This consistently returns:
{"detail":"no such command","error":400,"message":"Bad Request"}
While retrieving data with a GET request works fine:
curl -X GET -H "Content-Type: application/json" -u "dns:verysecurepass" http://10.xx.xx.1/rest/ip/dns/static
I’ve double-checked my API credentials and ensured they’re correct.
Can anyone advise on the proper method for adding static DNS records using the MikroTik API?
Figured how
❯ curl -X PUT -H "Content-Type: application/json" -u "dns:verysecurepass" -d '{"address": "1.1.1.1", "name": "test.com", "ttl": "1d"}' http://10.xx.xx.1/rest/ip/dns/static
{".id":"*203","address":"1.1.1.1","disabled":"false","dynamic":"false","name":"test.com","ttl":"1d"}%
The main issue was also that the record already existed.
You can not set one object dytamic or not: is one readoly attribute, not one field can you set or create.
Obviously you must check before submit the new entry that do not already exist…
You can not set one object dytamic or not: is one readoly attribute, not one field can you set or create.
Obviously you must check before submit the new entry that do not already exist...
Thank you, yeah figured that out now, thanks for replying.
The main reson was you using POST instead of PUT.
Thank you
I guess I needed more coffee.
In case someone was wondering why I wanted to have this ability and needed to know the basics first, its so I could create this Mikrotik Static DNS Synchronizer wirtten in Python.
https://github.com/netspeedy/MikroTik-Static-DNS-Synchronizer
I’ve just uploaded to github, first ever public one, so knock yourself out as I hope its useful to some of you. Any suggestestions/comments, welcomed, or better still create a PR
At least now, theres away to have a source of truth (zone records) which can update several routers via API