Community discussions

MikroTik App
 
fivestar
newbie
Topic Author
Posts: 29
Joined: Wed Jul 05, 2017 7:46 pm

Help script with rest api

Wed Nov 15, 2023 2:18 am

{
:global result \
[/tool fetch http-method=get http-header-field="content-type: application/json" \
url="https://192.168.55.1/rest/interface/ipip/vm01" \
user=4dm1n password=aBcDeeFg. \
as-value output=user ];


}
Need help, i only want to get the value of remote-address, how can get it?

it put me all this:

data={".id":"*4F","actual-mtu":"1480","allow-fast-path":"true","clamp-tcp-mss":"true","disabled":"false","dont-fragment":"no","dscp":"inherit","keepalive":"10s,10","local-address":"192.168.55.1","mtu":"auto","name":"ipip-master","remote-address":"8.8.8.8","running":"true"};downloaded=0;status=finished
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3509
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Help script with rest api

Wed Nov 15, 2023 3:26 am

If you change the URL to use a ".proplist=remote-address" in the query string that get you a lot close, so the URL should be
https://192.168.55.1/rest/interface/ipip/vm01?.proplist=remote-address
From that you may need a :find and :pick, but should less than the full output.

In 7.13beta1, there is JSON support, so you can do something like:
:deserialize from=json [/tool/fetch ... output=user as-value]
 
fivestar
newbie
Topic Author
Posts: 29
Joined: Wed Jul 05, 2017 7:46 pm

Re: Help script with rest api

Wed Nov 15, 2023 5:17 am

yes thanks, it reduces me the output to this:

data={"remote-address":"8.8.8.8"};downloaded=0;status=finished

now let find info to how :pick the value of that 8.8.8.8 in another variable

Who is online

Users browsing this forum: Bing [Bot] and 4 guests