Help with foreach script

I have a command that I can run from the terminal that can post an IP assignment and A MAC address to a specific site.
/tool fetch url=“https://mysite.com/api/dhcp_assignments?ip_address=192.168.4.253&leased_mac_address=00:50:79:66:68:19&expired=1&api_key=ce97d94f-dc25-468b-8d85-dab20cf26f97” mode=https keep-result=no

However I would like to make it a automated so it grabs all the IP and mac addresses from the DHCP server and posts them to the above site. Can someone tell me how I would use a foreach loop in here? I am a newb in programming and I could not find a way to use the foreach loop.
Thanks

Try something like this, adjust for yourself as needed:


/ip dhcp-server lease
:foreach i in=[find] do={
  :local add [get $i address]
  :local mac [get $i mac-address]

  /tool fetch url=("https://mysite.com/api/dhcp_assignments%5C?ip_address=" . $add . "&leased_mac_address=" . $mac . "&expired=1&api_key=some_api_key_here") mode=https keep-result=no
}

Wow. Thank you. After messing around with it a bit I figured it out. I wanted to thank you so much for your help on this one.
Is there a course(paid or free) that would walk us noobs on programming languages on how to do these stuff. This is very cool.

Thanks again for your help!

The Mikrotik Wiki article for scripting has very good information:
https://wiki.mikrotik.com/wiki/Manual:Scripting

I would suggest giving that a read, and playing around the CLI.
It fairly easy to understand and start scripting for yourself :slight_smile: