Can't send script json request

I’m very new to mikrotik script
I want to write a script that runs :
“/interface/wireguard/peers/disable [find public-key="QV9+Dl9j4pt43S+tCVYelBkVM11MQMTb7FsEOBImlFk="]”
after 30 day and when I want to run multiple lines in my request it gives me error and doesn’t do what I want
i write it like this :
{
“script”:[
“/interface/wireguard/peers/enable [find public-key="public-key"];”,
“:delay 5s;”,
“/interface/wireguard/peers/disable [find public-key="public-key"];”]
}

@ MT STAFF – >what MT ROS should do is parse JSON. The cheap hack of parsing text is a fragile approach.

Search all forums for JSON and see what you find!!

Well, hot of the press, in 7.13beta… they do parse JSON now. e.g. “:serialize <RouterOS_array> to=json” to get JSON from array, or “:deserialize <JSON_as_string> from=json”.
And /tool/fetch has a couple options to cleanup the headers too.

But the better question is why not use the /system/schduler and just the needed commands

/interface/wireguard/peers/enable [find public-key="public-key"]
:delay 5s
/interface/wireguard/peers/disable [find public-key="public-key"]

No JSON is required. If using REST API, you do need JSON, but the OS using it already should have JSON (but the REST API does NOT allow compound commands, so that be couple of REST calls)

@AMMO → They dont want to feel the wrath of the llama and thus are doing everything to appease… I guess next up is cloudflare zero trust tunnel in an options package LOL

@anav → if they had a package, you might have been effect by a huge Cloudflare a few weeks ago :slight_smile: : https://blog.cloudflare.com/cloudflare-incident-on-october-30-2023

Cloud flare Teething problems and pale in comparison (pun intended) to devastating solar flares. :wink:
https://www.dw.com/en/can-solar-flares-harm-earths-technology/video-64663358

Thank you , I will consider your suggestion about using /system/scheduler instead of delay but I didn’t get how to send my request , should I send my requests in separate requests or …

Assuming you using REST API, you can’t combine commands like that. You need to use a HTTP GET to get the “.id” of the WireGuard peer FIRST. And then take the “.id” you got and use that in a HTTP PUT to set { “enable”: “true” }.

I’m just not sure where you got the idea to use an array of script commands…if it ChatGPT, it hallucinates non-exist syntax pretty badly with RouterOS. Maybe explain what your trying to do and where this code need to run… If it the ON the router itself… using /system/script and /system/scheduler (or even /tool/netwatch) are what you’d need to use.