Export configuration via API

I have read-only access to a remote router, “read” user group with default access.
I am trying to dump current router configuration to a local text file (Not on the router, but to the computer I access it from). What I need is the output of “/export” command.

The approach I chose is to connect to the router via API, and run the “export” command, just like from console, and file.write(output) to a file. However unlike other commands from the API interface, “/export” returns “!done” output and nothing else. Using Python3 API, this is the scenario:

$ ./api.py 192.168.56.1 username ""
<<< /login
<<< 
>>> !done
>>> =ret=57e1810377ebca3a2a41bf699be2ad
>>> 
<<< /login
<<< =name=username
<<< =response=00c4a38fe3e36b8f2fc16d7795f7e92e
<<< 
>>> !done
>>> 
/export

<<< /export
<<< 
>>> !done
>>>

The “/export” command works as expected when connecting via SSH/telnet.

Using latest Routeros v6.17, x86 iso installed on VirtualBox.

Unfortunately, read permissions are not enough for export over the API protocol.

You need write permissions too, in order to write the configuration to a file (using the “file” argument), and then read the file.

Sorry I wasn’t very clear - by “local” I meant I want to place the config file on the computer I am connecting from, not the router itself.

I can easily view that config via SSH. I just need a way to automate that, since config dump should be done multiple times a day.

And the API seems the best solution to me for that, since I can plug it into Python together with all the good stuff that language provides.

EDIT:
Also this is not an issue with read-only user, since “/export” gives the same output when connecting via admin user as well (full permissions).

Right… my point was that your API user will need “read,write” permissions.

You can’t get the output directly via the API, regardless of permissions.

You need to use a workaround (and the workaround requires write permissions).

The workaround is to use “/export” with “file” argument to save the export to a temporary file, and then read the file via the API, and remove via the file using the API afterwards.

Reading the file contents via the API has been difficult in previous versions, though I haven’t tested it recently. You could try using “/file get” first. If it doesn’t work with the contents, one sure way to do it (even in older versions) is to create a temporary script in “/system script”, and run it. What the script should do is set its own contents to be the contents of the file. You then read the contents of the script, and delete the script afterwards, and finally the file.

In my PHP client, I’ve already abstracted away this procedure into a dedicated method, but I don’t know of an already written, generic, Python equivalent.

Thanks for clarification that “/export” command does not work via API. But is there any statement from MikroTik about this decision? Is that documented anywhere?