Output styles & RouterOS notes
/tool/fetch (simple)
- Bare
/tool/fetch command — run directly in terminal or script.
:put to terminal
- Wraps in
:put to print the response body to the terminal.
- Save to variable
- Stores the response in a global variable
$resp for further scripting.
- Variable + headers
- Like “Save to variable” but also captures response headers.
- Output to file
- Writes the response body to a file on the RouterOS filesystem.
JSON responses & :deserialize
When the request targets a JSON API, RouterOS can parse the response natively:
:global resp [/tool/fetch url=… as-value output=user]
:global json [:deserialize ($resp->"data") from=json]
:put $json
:deserialize is available in all current RouterOS releases (long-term and newer).
What curl2rsc cannot convert
-L / --location — /tool/fetch does not follow redirects.
--compressed — no automatic decompression support.
- Local file uploads (
-F @file) — /tool/fetch has no native file-upload support. The generated script uses $[/file get … contents] to read a plain-text file that must already exist on the RouterOS device. Binary files and complex payloads require manually constructing the multipart body using [:convert] and /file commands.
- HTTP methods beyond GET, HEAD, POST, PUT, DELETE, PATCH.