Community discussions

 
silderan
just joined
Topic Author
Posts: 19
Joined: Mon Sep 21, 2015 12:21 pm

removing data from API

Sat Jan 05, 2019 5:25 pm

Hello.

For sure it's a simply and stupid question, but I cannot find solution.

My Qt5 C++ API works great... except it cannot delete remote parameters/variables :?

I tried some ways, but I'm unable to do so:

=comment=<nothing>
=comment=""
=comment=''
=!comment=<nothing>
=!comment=""
=!comment=''

There is no "trap" messages from ROS when use the ! prepending attribute name, but ROS doesn't do anything either xD
It was no important to me until now, as I allways fill all attributes but "comment", clearing it by replacing text with a single space: " ". But cannot use this trick on other attributes.

Can someone give me some clues?
 
nescafe2002
Long time Member
Long time Member
Posts: 623
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: removing data from API

Sat Jan 05, 2019 6:09 pm

=comment=<nothing> is the way to go, as documented:

https://wiki.mikrotik.com/wiki/Manual:A ... ibute_word
Atribute word structure consists of 5 parts in this order:
  • encoded length
  • content prefix equals sigh - =
  • attribute name
  • separating equals sign - =
  • value of attribute if there is one. It is possible that attribute does not have a value

Note: Value can be empty

Example (note that 0x07 is not end of value, but encoded length of next word)

0000017C  2f 69 6e 74 65 72 66 61  63 65 2f 65 74 68 65 72   /interfa ce/ether
0000018C  6e 65 74 2f 73 65 74 09  3d 63 6f 6d 6d 65 6e 74   net/set. =comment
0000019C  3d 07 3d 2e 69 64 3d 2a  32 00                     =.=.id=* 2.
 
silderan
just joined
Topic Author
Posts: 19
Joined: Mon Sep 21, 2015 12:21 pm

Re: removing data from API

Sat Jan 05, 2019 7:16 pm

Thanks for your interest.

Yes, now is working... don't know why it was'nt as it was the first attempt I did. I will search why my tests fail at first.

Thanks again.
 
silderan
just joined
Topic Author
Posts: 19
Joined: Mon Sep 21, 2015 12:21 pm

Re: removing data from API

Sun Jan 06, 2019 11:47 pm

Hi again

Found it!!

I'll do my best to explain. It's hard to me doing it in english :P

When I face this problem I tried some code changes... and break things in my own API base code. (blame me for not trusting my 5 years younger version of me XD )

The deletion method works fine in attributes like comment.

But I saw some weird issue when deleting via API this way attributes like rate-limit in /ppp/profile/ because this kind of attribute, in winbox, can be "actived" or "inactived" and when "actived" can have data or be empty. Deleting via API it remains active but empty. ROS doesn't says it's wrong and I moved on.

BUT!
bridge in /ppp/profile/ is quite similar, but it cannot be active and empty at the same time.
So, when I clear /ppp/profile -> bridge, ROS keeps it activated, and, as this cannot be activated and empty, ROS "auto fills" with the first bridge in their list.

ROS API documentation never talks about deleting AFAK. The =attribute= word means "use this attribute" for API:
Image

Then... what should I do to clear this kind of attributes?
 
nescafe2002
Long time Member
Long time Member
Posts: 623
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: removing data from API

Mon Jan 07, 2019 12:33 am

Granted, this one isn't documented. But when in doubt, try to recreate console command first and convert that command with parameters to API words.

This example was used to remove bridge1 from ppp profile:

0000004A  2f 70 70 70 2f 70 72 6f  66 69 6c 65 2f 73 65 74   /ppp/pro file/set
0000005A  07 3d 2e 69 64 3d 2a 31  09 3d 21 62 72 69 64 67   .=.id=*1 .=!bridg
0000006A  65 3d 00                                           e=.

So, =!value=<nothing> seems to do the trick.
 
silderan
just joined
Topic Author
Posts: 19
Joined: Mon Sep 21, 2015 12:21 pm

Re: removing data from API  [SOLVED]

Mon Jan 07, 2019 11:21 am

Yes! It does the trick!

Indeed it's not documented and shall be.

So, to resume, to remove an attribute value from API you must know if attribute must be disabled or it's just a fillable field.
If it's just a fillable attribute, just send and empty value: =<attribute-name>=
It it's a enable/disable attribute, just negate the attribute: =!<attribute-name>=<value-that-will-be-ignored-so-can-be-empty-also>

Thankyou for your help.

You know this times where someone is blind to quite obvious things and is unable to solve it without help...?:P
 
nescafe2002
Long time Member
Long time Member
Posts: 623
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: removing data from API

Mon Jan 07, 2019 12:44 pm

No problem. Note that API is behaving exactly like CLI in these cases:

To unset a comment, use: /interface ethernet set 0 comment=""
The command contains a parameter (comment) with a value ("")

To unset a bridge in ppp, use: /ppp profile set 0 !bridge
The commands contains a parameter (!bridge) without a value

Who is online

Users browsing this forum: No registered users and 7 guests