Community discussions

MikroTik App
 
txfz
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 66
Joined: Tue Mar 10, 2020 9:02 am

Are IDs returned from REST API stable?

Wed May 29, 2024 1:24 pm

Hi,

I am looking to use the REST API in order to delete items, and understand I need to use the .id field previously returned from a GET request in order to do so. My question is is this ID guaranteed to be the same for as long as the item exists? As far as I understand, when using regular RouterOS scripting, the IDs you get are only valid during the execution of that command or something.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7186
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Are IDs returned from REST API stable?

Wed May 29, 2024 4:51 pm

Internal ID stays the same as long as object exists. It doesn't matter if it is api, rest api or console ID, is the same.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 4324
Joined: Sun May 01, 2016 7:12 pm
Location: California
Contact:

Re: Are IDs returned from REST API stable?

Wed May 29, 2024 5:22 pm

As far as I understand, when using regular RouterOS scripting, the IDs you get are only valid during the execution of that command or something.
@mrz is right about REST. And you're right about the CLI's "print" command - but those are "numbers=", not ".id=". To see the "*XX" form in .id in CLI, just add "show-ids" to any print to see same as REST.
/ip address print show-ids
The .id's can be also be used in CLI with "*" any place the 1... based numbers would work.
 
txfz
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 66
Joined: Tue Mar 10, 2020 9:02 am

Re: Are IDs returned from REST API stable?

Wed May 29, 2024 5:45 pm

Alright. That explains it. Thanks!
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 4324
Joined: Sun May 01, 2016 7:12 pm
Location: California
Contact:

Re: Are IDs returned from REST API stable?

Wed May 29, 2024 8:52 pm

Alright. That explains it. Thanks!
FWIW, the .id in REST are also the output of a "find" in CLI:
:put [/ip/address/find]
*2;*2b;*2c;*81;*93;*9d;*a2;*ab;*b1;*b2;*b3;*b4;*b5;*b6
as REST:
curl -k -s -u $USER -X POST https://$ROUTER/rest/ip/address/find --json '' | jq '.ret'
"*2;*2b;*2c;*81;*93;*9d;*a2;*ab;*b1;*b2;*b3;*b4;*b5;*b6"

Basically it's print that has a "helper" to use relative numbers at CLI. I think since using *2b stuff for interactive use would get annoying.

Who is online

Users browsing this forum: No registered users and 13 guests