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:
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?