Community discussions

 
Redmor
Member Candidate
Member Candidate
Topic Author
Posts: 248
Joined: Wed May 31, 2017 7:40 pm
Location: Italy

API getall routing-mark main

Wed Feb 06, 2019 11:12 am

Hello,

I'm trying to get the default route with routing mark main using API, but returned array is empty

Code with routing mark main.
$gateway=$API->comm('/ip/route/getall', array('?dst-address'=>'0.0.0.0/0', '?distance'=>'1', '?routing-mark'=>'main'));
I see that, if I don't specify routing mark, the array of the default gateway returned hasn't got the routing-mark key

Code without routing mark
$gateway=$API->comm('/ip/route/getall', array('?dst-address'=>'0.0.0.0/0', '?distance'=>'1'));
Print of $gateway
Array ( [.id] => *30000006 [dst-address] => 0.0.0.0/0 [gateway] => pppoe-client [gateway-status] => pppoe-client reachable [distance] => 1 [scope] => 30 [target-scope] => 10 [active] => true [dynamic] => true [static] => true [disabled] => false ) )
The problem is that I have other routes with dst-address 0.0.0.0/0 but with a different routing mark than main.
Can I exclude them with something similar like the first code, or I have to take them all, save arrays in another array and then take the one without routing mark?
ImageImage
 
nescafe2002
Long time Member
Long time Member
Posts: 615
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: API getall routing-mark main  [SOLVED]

Wed Feb 06, 2019 11:24 am

Routing mark is not main, but empty (missing) for default route.

https://wiki.mikrotik.com/wiki/Manual:API#Queries

?name pushes 'true' if item has value of property name, 'false' if it does not.
?-name pushes 'true' if item does not have value of property name, 'false' otherwise.

You might try something like this:

$gateway=$API->comm('/ip/route/print', array('?dst-address'=>'0.0.0.0/0', '?distance'=>'1', '?-routing-mark'=>null));
 
Redmor
Member Candidate
Member Candidate
Topic Author
Posts: 248
Joined: Wed May 31, 2017 7:40 pm
Location: Italy

Re: API getall routing-mark main

Wed Feb 06, 2019 11:34 am

Thank you, it works.
ImageImage

Who is online

Users browsing this forum: Google [Bot] and 8 guests