Fetch - How to access data variable?

How to access data variable when I use output=user?
[admin@mtTest] > /tool fetch output=

Output ::= file | none | user
none – do not store downloaded data
user – return up to 63k bytes directly in ‘data’ variable without storing on disk
file – store to file

You can check /System Scripts Environment after a run how the name of the variable is, at-least if it is a global variable.

Hi,

Unfortunately it doesn't work (real IP hidden). I dknow that I can write it to file but that is not what I like and this new option (output=user) will be great if
only I can get it to work. There is no explanation for it on Wiki at this time.

[admin@mtTest] > /tool fetch mode=http url="http://api.ipify.org/" http-method=get output=user
status: finished
downloaded: 0KiBC-z pause]
total: 0KiB
duration: 1s
data: 1.2.3.4

result from variable print:

[admin@mtTest] /system script environment> print

NAME VALUE

If I try to write to variable:

[admin@mtTest] > :global WANip [/tool fetch mode=http url="http://api.ipify.org/" http-method=get output=user]
status: finished
downloaded: 0KiBC-z pause]
total: 0KiB
duration: 1s
data: 1.2.3.4

Still no result:

[admin@mtTest] /system script environment> print

NAME VALUE

0 WANip

Answer to myself. It isn’t working at this time. Must wait for next release of fetch.

I assume this is what you are looking for:

:local strData [ /tool fetch mode=https output=user url="https://ipinfo.io/ip" as-value ]; :local arrData [ :toarray $strData ]; :local varData ( $arrData->"data" ); :put [ $varData ];

i broke out the type changes into separate variables, but obviously this can all be simplified.

if you want the status of the download:

:local strData [ /tool fetch mode=https output=user url="https://ipinfo.io/ip" as-value ]; :local arrData [ :toarray $strData ]; :local varData ( $arrData->"status" ); :put [ $varData ] ;
1 Like

Since you already have it in one line using many commands separated by ; you can do all in one go.

data

:put ([/tool fetch mode=https output=user url="https://ipinfo.io/ip" as-value ]->"data")

status

:put ([/tool fetch mode=https output=user url="https://ipinfo.io/ip" as-value ]->"status")

For the IP, you get an enter extra using this array method. Not sure how to get rid of it.

How about this ?

:put ([/tool fetch url=“https://api.ipify.org/” mode=http dst-path=ipcheck output=user as-value]->“data”)

Can even be shorten more.
This site is some better since it does not give an extra empty line.

:put ([/tool fetch url="https://api.ipify.org/" output=user as-value]->"data")

any idea how to do this when you have multiple isps to get address of all providers ?

mine are set with different distance in routes and mangle input/output to specific routing tables. so all traffic goes out the main isp, but the router can be reached over all isps.
i tried with src-address but i always get the reply of the main isp. I also tried setting a specific route for ipify but it didn’t work.

just asking myself … why is a unicorn exeption like
.

:put ([/tool fetch url="https://api.ipify.org/" output=user as-value]->"data")

.
possible …
… ( … you may try this with https://www.your-xxxx-site.com … )

while the following below is NOT possible to define as a variable:
.

/tool snmp-get security=private authentication-protocol=SHA1 authentication-password=*** encryption-protocol=AES encryption-password=*** version=3 community=**user** address=**IP** oid=1.3.6.1.2.1.33.1.1.1.0

.
is it a security concern that I’ve missed in the bigger picture ? … or is it just forgotten to be implemented ?
.
a SNMP-OID gives back (most of the time) one decisive piece of information from a tree …
a html-request gives (normally) back … a … … a tur*
.
please walk me through

.

[admin@***] > /tool snmp-get security=private authentication-protocol=SHA1 authentication-password=* encryption-protocol=AES encryption-password=* version=3 community=* address=* oid=1.3.6.1.2.1.33.1.1.1.0
OID                                                                                         TYPE             VALUE                                                                                        
1.3.6.1.2.1.33.1.1.1.0                                                                      octet-string     Alpha                                                                                        

[admin@***] >

.
maybe “as-value” just needed to clip on the end of a (code-)line … cause “VALUE” … is already there ?!

(It’s just not implemented)

Why hijack another topic?
Already answered in other topic, just search…
http://forum.mikrotik.com/t/routeros-snmp-get/121369/1

(obviously !)
.
the post was about: why is it implemented for a comparable method (fetch) and the possible reasons ( … why not for snmp)
… so please read more diligent
.
I’ve searched the forum … found your post … and have not implemented it
halfway the reason I’ve posted this question

together with «a unicorn»?

: )
figure of speech for a “website” which gives a reasonable response

The “as-value” with /tool/snmp-get is available in v7.8: http://forum.mikrotik.com/t/saving-snmp-to-variable/144455/1

magnificent

:put ([/tool fetch url=https://ifconfig.me/ip mode=https output=user as-value]->"data")


works well too