/tool fetch mode=https url="https://yoursite.com/link/5eu1a1kkypnypbyseqzsq1ao4w" http-method=post http-data="payload={\"text\": \"Test\"}"
fetch - added "http-data" and "http-method" parameters to allow delete, get, post, put methods (content-type=application/x-www-form-urlencoded by default);
Wow, this is awesome. Back before this, I always use email to send encoded status in json.You can do it this way:
This was added in the latest RouterOS 6.39 RC versionsCode: Select all/tool fetch mode=https url="https://yoursite.com/link/5eu1a1kkypnypbyseqzsq1ao4w" http-method=post http-data="payload={\"text\": \"Test\"}"
fetch - added "http-data" and "http-method" parameters to allow delete, get, post, put methods (content-type=application/x-www-form-urlencoded by default);
Is there any way to change "content-type=application/x-www-form-urlencoded" to "content-type=application/json"??You can do it this way:
This was added in the latest RouterOS 6.39 RC versionsCode: Select all/tool fetch mode=https url="https://yoursite.com/link/5eu1a1kkypnypbyseqzsq1ao4w" http-method=post http-data="payload={\"text\": \"Test\"}"
fetch - added "http-data" and "http-method" parameters to allow delete, get, post, put methods (content-type=application/x-www-form-urlencoded by default);
How can I upload file with new fetch feature?You can do it this way:
This was added in the latest RouterOS 6.39 RC versionsCode: Select all/tool fetch mode=https url="https://yoursite.com/link/5eu1a1kkypnypbyseqzsq1ao4w" http-method=post http-data="payload={\"text\": \"Test\"}"
fetch - added "http-data" and "http-method" parameters to allow delete, get, post, put methods (content-type=application/x-www-form-urlencoded by default);
curl -X PUT "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59" \
-H "X-Auth-Email: user@example.com" \
-H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \
-H "Content-Type: application/json" \
--data '{"type":"A","name":"example.com","content":"127.0.0.1","ttl":120,"proxied":false}'
You can already do that. Please read the second message in this thread carefully.adding a content-type for fetch is important and also needed on my end
Not sure if i am thinking wrong, yes i can put json data in the http payload as shown in post #2 but the http header still contains "application/x-www-form-urlencoded". In my case the application server evaluates the http header and therefore throws an error.You can already do that. Please read the second message in this thread carefully.adding a content-type for fetch is important and also needed on my end
curl -H 'PddToken: 123456789ABCDEF0000000000000000000000000000000000000' 'https://pddimp.yandex.ru/api2/admin/dns/list?domain=domain.com'
# gather basic router info -----------------------------------------------
:local uptime [/system resource get uptime];
:local macadd [/interface wireless get [ find default-name=wlan1 ] mac-address]
:local ver [/system resource get version]
:local name [/system identity get name]
# gather wireless info ---------------------------------------------------
:local wifi [/interface wireless get [ find default-name=wlan1 ] ssid]
:local pw [/interface wireless security-profiles get [ find name=default ] wpa2-pre-shared-key]
# put it all together ----------------------------------------------------
:set $str "rtrName=$name&rtrMac=$macadd&rtrUptime=$uptime&rtrVersion=$ver&ssidName=$wifi&ssidKey=$pw";
# send to server ---------------------------------------------------------
:do {
:put "Checking in";
/tool fetch mode=https url="https://domain.com/checkin.php" keep-result=yes dst-path="result.txt" \
user="routerdevice" password="garbledpassword" http-method="post" http-data=$str ;
} on-error={ log warning "Greeter: Send to server Failed!" }
//display the received data
print_r($_POST);
// or
foreach ($_POST as $key => $value) {
echo $key . ": " . $value . "<p>\r\n";
}
// Note incoming IP address and timestamp
$checkin_ip = $_SERVER['REMOTE_ADDR'];
$checkin_time = time();
// give a reply
echo "good " . $_SERVER['REMOTE_ADDR'] . "\r\n";
// Now save to a database
https://domin.com/checkin.php?rtrName=GrandmasHouse&rtrMac=00:11:22:33:44:55&rtrUptime=01:02:03&ssidName=BigBertha&ssidKey=puppies
Hi, can I upload a text file using fetchYou can do it this way:
This was added in the latest RouterOS 6.39 RC versionsCode: Select all/tool fetch mode=https url="https://yoursite.com/link/5eu1a1kkypnypbyseqzsq1ao4w" http-method=post http-data="payload={\"text\": \"Test\"}"
fetch - added "http-data" and "http-method" parameters to allow delete, get, post, put methods (content-type=application/x-www-form-urlencoded by default);
Any news on this max-lenght?Can you please raise the 65535 character limit (double it or remove it completely), so that the error case "max line length 65535 exceeded!" is resolved?
It happens both with GET and POST (I understand that could occur with GET, but it shouldn't with POST)
As routerOS is more and more involved in the big data domain, it is imperative that such limitations are removed.
Just a note here, the fact that a variable doesn’t have such length limitation, makes the fetch data limitation much more awkward. The data can be collected locally in routeros, but they can’t be transmitted! (Well, there can be multiple fetches, but this is a nasty hack, both client and server wise)Any news on this max-lenght?Can you please raise the 65535 character limit (double it or remove it completely), so that the error case "max line length 65535 exceeded!" is resolved?
It happens both with GET and POST (I understand that could occur with GET, but it shouldn't with POST)
As routerOS is more and more involved in the big data domain, it is imperative that such limitations are removed.
They had the limitation for sure because the GET and forgot to remove it when they implemented the POST, I believe that in a future release this will be fixedJust a note here, the fact that a variable doesn’t have such length limitation, makes the fetch data limitation much more awkward. The data can be collected locally in routeros, but they can’t be transmitted! (Well, there can be multiple fetches, but this is a nasty hack, both client and server wise)Any news on this max-lenght?Can you please raise the 65535 character limit (double it or remove it completely), so that the error case "max line length 65535 exceeded!" is resolved?
It happens both with GET and POST (I understand that could occur with GET, but it shouldn't with POST)
As routerOS is more and more involved in the big data domain, it is imperative that such limitations are removed.
Please raise or remove that limitation completely.
Encouraging an idea of fetching with custom headers. pdd.yandex.ru (name server api) requires using fields in the headerHow to send header in the method post or get? Option "-H" in curl. For exampleCode: Select allcurl -H 'PddToken: 123456789ABCDEF0000000000000000000000000000000000000' 'https://pddimp.yandex.ru/api2/admin/dns/list?domain=domain.com'
-H
Is it possible to PUT Content-Type: application/json ? I would want to perform the following but i couldn't.Code: Select allcurl -X PUT "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59" \ -H "X-Auth-Email: user@example.com" \ -H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \ -H "Content-Type: application/json" \ --data '{"type":"A","name":"example.com","content":"127.0.0.1","ttl":120,"proxied":false}'
:local chann dude-1
:local notification "Time: [Time]\nAddress: [Device.CustomField2]\nIP: [Device.FirstAddress]\nPing: [Service.Status]"
:local iconurl https://wiki.mikrotik.com/images/5/54/Dude-icon3.png
:local pload "payload={\"channel\": \"#$chann\", \"username\": \"DUDE-server\", \"text\": \"$notification\", \"icon_url\": \"$iconurl\"}"
/tool fetch http-method=post http-content-type="application/json" http-data=$pload url="https://hooks.slack.com/services/TXXXXXXXX/YYYYYYYYY/ZZZZZZZZZZZZZZZZZ" keep-result=no;
Does rc already support "-H"? How to convert curl to fetch? Any example?Can I get an idea when will "header" support be added to fetch tool?
This is quite useful for accessing API data which requires headers for authorization. Example by Xenhat already demonstrates this with DNS updates through Cloudflare which requires passing header details relating to Authorization in order to use their API.
I am not sure if svda is correct, in that header support is already available in release candidate already. I don't see mentions of it in the Changelog for 6.42rc52.
Yes! Need this!Is it possible to PUT Content-Type: application/json ? I would want to perform the following but i couldn't.Code: Select allcurl -X PUT "https://api.cloudflare.com/client/v4/zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59" \ -H "X-Auth-Email: user@example.com" \ -H "X-Auth-Key: c2547eb745079dac9320b638f5e225cf483cc5cfdda41" \ -H "Content-Type: application/json" \ --data '{"type":"A","name":"example.com","content":"127.0.0.1","ttl":120,"proxied":false}'
<?php
$zones = isset($_GET['zones']) ? trim($_GET['zones']) : exit;
$dns_records = isset($_GET['dns_records']) ? trim($_GET['dns_records']) : exit;
$zones = $_GET['zones'];
$dns_records = $_GET['dns_records'];
$name = $_GET['name'];
$content = $_GET['content'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.cloudflare.com/client/v4/zones/" . $zones . "/dns_records/" . $dns_records);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"type\":\"A\",\"name\":\"" . $name . "\",\"content\":\"" . $content . "\",\"ttl\":120,\"proxied\":false}");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
$headers = array();
$headers[] = "X-Auth-Email: max@hd.zp.ua";
$headers[] = "X-Auth-Key: 1c2c585915534145fecded4526e8668177a33";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
var_dump($result);
curl_close ($ch);
?>
Yes, currently only one. We will make multiple possible, check one of the new betas after New Year.http-header-field= - allows you to specify only once.
How to specify 3 headers?
-H "X-Auth-Email: max@hd.zp.ua" \
-H "X-Auth-Key: 1c2c585915534145fecded4526e8668177a33" \
-H "Content-Type: application/json" \
Yes, currently only one. We will make multiple possible, check one of the new betas after New Year.http-header-field= - allows you to specify only once.
How to specify 3 headers?
-H "X-Auth-Email: max@hd.zp.ua" \
-H "X-Auth-Key: 1c2c585915534145fecded4526e8668177a33" \
-H "Content-Type: application/json" \
I put the intermediate script on php higher on the forum. You can download it to any server viewtopic.php?f=9&t=120860&e=1&view=unread#p70339018/01/2019 and still no multiple fetch header fields
[admin@MikroTik-RB3011] > /tool fetch http-method=get url="https://api.cloudflare.com/client/v4/zones/__ZONEID__/dns_records/__ID__" http-header-field=X-Auth-Email:__EMAIL__,X-Auth-Key:__AUTH_KEY__,http-content-type:application/json output=none
status: finished
downloaded: 0KiBC-z pause]
duration: 1s
[admin@MikroTik-RB3011] > /tool fetch http-method=post url="https://api.cloudflare.com/client/v4/zones/__ZONEID__/dns_records/__ID__" http-header-field=X-Auth-Email:__EMAIL__,X-Auth-Key:__AUTH_KEY__,http-content-type:application/json output=none http-data="{\"type\":\"A\",\"name\":\"__A_RECORD__\",\"content\":\"192.168.1.1\"}"
status: failed
failure: closing connection: <400 Bad Request> 104.19.198.151:443 (4)
In the meantime this feature has been added.
Has anyone tried to use it with the Cloudflare v4 API ?
I am having difficulties with post to update a DNS zone.
It gives me error 400 bad request.
Code: Select all[admin@MikroTik-RB3011] > /tool fetch http-method=get url="https://api.cloudflare.com/client/v4/zones/__ZONEID__/dns_records/__ID__" http-header-field=X-Auth-Email:__EMAIL__,X-Auth-Key:__AUTH_KEY__,http-content-type:application/json output=none status: finished downloaded: 0KiBC-z pause] duration: 1s [admin@MikroTik-RB3011] > /tool fetch http-method=post url="https://api.cloudflare.com/client/v4/zones/__ZONEID__/dns_records/__ID__" http-header-field=X-Auth-Email:__EMAIL__,X-Auth-Key:__AUTH_KEY__,http-content-type:application/json output=none http-data="{\"type\":\"A\",\"name\":\"__A_RECORD__\",\"content\":\"192.168.1.1\"}" status: failed failure: closing connection: <400 Bad Request> 104.19.198.151:443 (4)
Thanks for the reply!!In the meantime this feature has been added.
Has anyone tried to use it with the Cloudflare v4 API ?
I am having difficulties with post to update a DNS zone.
It gives me error 400 bad request.
Code: Select all[admin@MikroTik-RB3011] > /tool fetch http-method=get url="https://api.cloudflare.com/client/v4/zones/__ZONEID__/dns_records/__ID__" http-header-field=X-Auth-Email:__EMAIL__,X-Auth-Key:__AUTH_KEY__,http-content-type:application/json output=none status: finished downloaded: 0KiBC-z pause] duration: 1s [admin@MikroTik-RB3011] > /tool fetch http-method=post url="https://api.cloudflare.com/client/v4/zones/__ZONEID__/dns_records/__ID__" http-header-field=X-Auth-Email:__EMAIL__,X-Auth-Key:__AUTH_KEY__,http-content-type:application/json output=none http-data="{\"type\":\"A\",\"name\":\"__A_RECORD__\",\"content\":\"192.168.1.1\"}" status: failed failure: closing connection: <400 Bad Request> 104.19.198.151:443 (4)
To update DNS zone, you must use PUT method. Replace http-method=post with http-method=put and add mode=https
[admin@MikroTik-RB3011] > /tool fetch http-method=put mode=https url="https://api.cloudflare.com/client/v4/zones/__ZONEID__/dns_records/__ID__" http-header-field=X-Auth-Email:__EMAIL__,X-Auth-Key:__AUTHKEY__,http-content-type:application/json output=none http-data="{\"type\":\"A\",\"name\":\"__ARECORD__\",\"content\":\"192.168.1.1\"}"
status: failed
failure: closing connection: <400 Bad Request> 104.19.195.151:443 (4)
Thanks for the reply!!In the meantime this feature has been added.
Has anyone tried to use it with the Cloudflare v4 API ?
I am having difficulties with post to update a DNS zone.
It gives me error 400 bad request.
Code: Select all[admin@MikroTik-RB3011] > /tool fetch http-method=get url="https://api.cloudflare.com/client/v4/zones/__ZONEID__/dns_records/__ID__" http-header-field=X-Auth-Email:__EMAIL__,X-Auth-Key:__AUTH_KEY__,http-content-type:application/json output=none status: finished downloaded: 0KiBC-z pause] duration: 1s [admin@MikroTik-RB3011] > /tool fetch http-method=post url="https://api.cloudflare.com/client/v4/zones/__ZONEID__/dns_records/__ID__" http-header-field=X-Auth-Email:__EMAIL__,X-Auth-Key:__AUTH_KEY__,http-content-type:application/json output=none http-data="{\"type\":\"A\",\"name\":\"__A_RECORD__\",\"content\":\"192.168.1.1\"}" status: failed failure: closing connection: <400 Bad Request> 104.19.198.151:443 (4)
To update DNS zone, you must use PUT method. Replace http-method=post with http-method=put and add mode=https
Lol, I actually just missed that hahah.
Even though the error still persists, am I still missing something ?
Code: Select all[admin@MikroTik-RB3011] > /tool fetch http-method=put mode=https url="https://api.cloudflare.com/client/v4/zones/__ZONEID__/dns_records/__ID__" http-header-field=X-Auth-Email:__EMAIL__,X-Auth-Key:__AUTHKEY__,http-content-type:application/json output=none http-data="{\"type\":\"A\",\"name\":\"__ARECORD__\",\"content\":\"192.168.1.1\"}" status: failed failure: closing connection: <400 Bad Request> 104.19.195.151:443 (4)
Hahahah, nice catch!OK In header field replace http-content-type:application/json with content-type:application/json
curl -X POST -H 'Content-Type: application/json' --data '{"text":"Example"}' http://myip:3000/hooks/SHFuHFpDFHFOEFHOI5984w798q
/tool fetch keep-result=no mode=http url="http://myip:3000/hooks/SHFuHFpDFHFOEFHOI5984w798q" http-method=post http-content-type="application/json" http-data="\"text\":\"Example message\""
failure: closing connection: <400 Bad Request> myip:3000 (4)
How about this?Yes, currently only one. We will make multiple possible, check one of the new betas after New Year.http-header-field= - allows you to specify only once.
How to specify 3 headers?
-H "X-Auth-Email: max@hd.zp.ua" \
-H "X-Auth-Key: 1c2c585915534145fecded4526e8668177a33" \
-H "Content-Type: application/json" \
Code: Select all
curl -X POST -H "Content-Type: application/json" -d '{"value1":"RB4100","value2":"Shutdown","value3":"DSL"}' https://maker.ifttt.com/trigger/mtik/with/key/my_IFTTT_code
Code: Select all
/tool fetch https://maker.ifttt.com/trigger/mtik/with/key/my_IFTTT_code keep-result=no
http-header-field=http-content-type:application/json http-data="{\"value1\":\"RB4011\",\"value2\":\"shutting down\",\"value3\":\"DSL"}"
/tool fetch https://maker.ifttt.com/trigger/mtik/with/key/my_IFTTT_code keep-result=no \
http-header-field="Content-Type:application/json" \
http-data="{\"value1\":\"RB4011\",\"value2\":\"shutting down\",\"value3\":\"DSL"}"
status: failed
failure: closing connection: <400 Bad Request> 34.201.148.91:443 (4)
http-header-field="content-type:text/plain"
Wow wish this was on the man page for fetch. I just wasted two nights trying to figure this out.To owerload content type need use directive http-header-field and set key content-type in lower case, exampleCode: Select allhttp-header-field="content-type:text/plain"
{
log error ("Internet Mati --- Memulai Koneksi Ulang ......")
/ip dns cache flush
/ip dhcp-client release [find interface=wlan2]
log warning ("DHCP Client Baru")
delay 10
:local ip [/ip address get [/ip address find interface="wlan2"] address];
:local macadd [/interface wireless get [ find default-name=wlan2 ] mac-address];
:local ip [put [:pick $ip 0 [:find $ip "/"]]]
/tool fetch http-method=post http-data="username_=DalBan&username=DalBan.lPgC%40freeMS&password=DalBan" url=("https://welcome2.wifi.id/wms/auth/authnew/autologin/quarantine.php?ipc=$ip&gw_id=WAG-D4-GBL&mac=$macadd&wlan=TGSLW00005/TLK-WI124968-0001:UN%20CHECK") keep-result=no
log warning ("Internet Sudah Menyala")
}
fetch("https://welcome2.wifi.id/wms/auth/authnew/autologin/quarantine.php?ipc=10.148.103.193&gw_id=WAG-D4-GBL&mac=b4:cb:57:6f:7a:91&redirect=http://8.8.8.8/&wlan=TGSLW00005/TLK-WI124968-0001:RUMAH%20IQBAL&landURL=", {"credentials":"include","headers":{"accept":"application/json, text/javascript, */*; q=0.01","accept-language":"en","content-type":"application/x-www-form-urlencoded; charset=UTF-8","sec-fetch-mode":"cors","sec-fetch-site":"same-origin","x-requested-with":"XMLHttpRequest"},"referrer":"https://welcome2.wifi.id/wms/?gw_id=WAG-D4-GBL&client_mac=b4:cb:57:6f:7a:91&wlan=TGSLW00005/TLK-WI124968-0001:RUMAH%20IQBAL&sessionid=0800FFFF7802E286-5D60F78B&redirect=http://8.8.8.8/","referrerPolicy":"no-referrer-when-downgrade","body":"username_=DalBan&username=DalBan.xJjh%40freeMS&password=DalBan","method":"POST","mode":"cors"});
/tool fetch url="http://192.168.8.1/api/webserver/SesTokInfo" dst-path="ses_tok.txt"
global content [/file get [/file find name=ses_tok.txt] contents]
:local COOKIE [:pick $content 71 199]
:local TOKEN [:pick $content 220 252]
:local LOGIN "<request><Username>admin</Username><Password>admin</Password><password_type>3</password_type></request>"
log info "COOKIE: $COOKIE"
log info "TOKEN: $TOKEN"
/tool fetch mode=http http-method=post url="http://192.168.8.1/api/user/login" http-data=($LOGIN) http-header-field=(Cookie:$COOKIE,__RequestVerificationToken:$TOKEN,content-type:text/xml,Connection:keep-alive) dst-path="login_resp_hdr.txt" keep-result=no
18:17:58 info fetch: file "ses_tok.txt" downloaded
18:17:58 script,info COOKIE: hoVS1kv8/waT0S4OyMrwZQS5OFOymv1Ruy6XovYaLK7xffO2v2mjP
PctukTNEuc7NhK1jdqE0X8c/DjIxyWMrqKmp6K3x74n1ja8xrVY/pMJCg3YJzXf1jwMIybRaxG7
18:17:58 script,info TOKEN: 1L719lqR/w/T/XnOu+pu3JBj75e3EIAH
#!/bin/bash
curl -u admin:password \
-c cookie_router \
-X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "SelectLanguage=en_US&LogoutApplyAction=&DMZHostIP0=192.168.1.200&RouterIPAddress=192.168.1.1" \
http://192.168.1.1/goform/AdvancedDMZHost
Sorry to bring up a post from the dead.. but I can't find anything more recent.Hahahah, nice catch!OK In header field replace http-content-type:application/json with content-type:application/json
I've been trying this on yesterday's late night and I probably wasn't even looking anymore.
Thanks a lot, it worked perfectly.
/tool fetch mode=https http-method=put url="https://api.cloudflare.com/client/v4/zones/__ZONEID__/dns_records" http-header-field="content-type:application/json,X-Auth-Email:__EMAIL__,X-Auth-Key:__APIKEY__" http-data="{\"type\":\"A\",\"name\":\"__DOMAIN__\",\"content\":\"__IPADDRESS__\",\"ttl\":120,\"proxied\":false}" output=none
//working
curl -X POST "https://api.cloudflare.com/client/v4/zones/__ZONEID__/dns_records" -H "X-Auth-Email: __EMAIL__" -H "X-Auth-Key: __APIKEY__" -H "Content-Type: application/json" --data '{"type":"A","name":"__DOMAIN__","content":"__IPADDRESS__","ttl":120,"priority":10,"proxied":false}'
with fetch, how can I do curl command like this:Multiple headers already possible for a few versions, even documented in Wiki:
https://wiki.mikrotik.com/wiki/Manual:T ... Properties
It's also discussed in this topic:
viewtopic.php?f=9&t=120860&p=709811&hil ... rs#p717584
Guys?Hello everyone!
Can you also add a patch http method to fetch tool please? It can be very useful.
<form id="loginForm" action="https://welcome2.wifi.id/wms/auth/authnew/autologin/quarantine.php?ipc=10.212.63.176&gw_id=WAG-D5-KBL&mac=14:4d:67:98:69:9c&redirect=&wlan=BWRGJ00021-N%2FTLK-CI-47595%3Aelkafii" method="post">
<input type="text" name="username" id="username_hidden" value="2078orla.Ai03@freeMS" />
<input type="text" name="password" id="password" value="2078orla" />
<input type="submit" value="oke" />
</form>
{:local wmsip "10.212.63.176";
:local wmsmac "14:4d:67:98:69:9c";
:local wmspass "2078orla";
:local wmsssid "BWRGJ00021-N%2FTLK-CI-47595%3Aelkafii";
:local urllogin "https://welcome2.wifi.id/wms/auth/authnew/autologin/quarantine.php\?ipc=$wmsip&gw_id=WAG-D5-KBL&mac=$wmsmac&redirect=&wlan=$wmsssid";
:local ppostform "ipc=$wmsip&gw_id=WAG-D5-KBL&mac=$wmsmac&redirect=&wlan=$wmsssid&payload={\"username\":\"$wmspass.Ai03@freeMS\",\"password\":\"$wmspass\"}";
/log err $ppostform
/ip dns cache flush
:local wmsrespon ([/tool fetch mode=https http-method=post http-data=$ppostform url="$urllogin" http-header-field="content-type:application/json,User-Agent: chrome browser mumet" as-value output=user]->"data");
/log war $wmsrespon;}
http-header-field
http-header-field="Authorization:key=Izalg..gf,Content-Type:application/json"
http-data="{\"to\":\"deviceToken\",\"notification\":{\"title\":\"hello\",\"body\":\"world\"}}"
regurds
curl -d '{"token": "<roomid>", "message": "hi there @<username>"}' -H "Content-Type: application/json" -H "Accept: application/json" -H "OCS-APIRequest: true" -v -u "<username>:<password>" https://mydomain.tld/ocs/v1.php/apps/spreed/api/v1/chat/<roomid>
fetch("https://domaintld/ocs/v1.php/apps/spreed/api/v1/chat/<roomid>", {
body: "{"token": "<roomid>", "message": "hi there @<username>"}",
headers: {
Accept: "application/json",
Authorization: "Basic <hash here=>",
"Content-Type": "application/json",
"Ocs-Apirequest": "true"
},
method: "POST"
})
/tool fetch http-method=post http-header-field="{Accept:\"appli
cation/json\",Authorization:\"Basic <hash here=>\",\"Content-Type\":\"appl
ication/json\",\"OCS-APIRequest\":\"true\"}" http-data="{\"token\":\"<roomid>\",\"message\":\"hi t
here @<username>\"}" url="domain.tld/ocs/v1.php/apps/spreed/api/v1/chat/<roomid>"
user="<username>" password="<password>"
status: failed
failure: closing connection: <412 Precondition failed> 144.**.**.***:443 (5)
/tool/fetch follows RouterOS usual scheme for commands and types, so a direct conversation isn't possible... While shares same name as the W3C fetch(), it actually pretty different in operation. The curl example is closer to what's needed.Hi! Please, help to convert this string into the fetch format:
Code: Select allcurl -d '{"token": "<roomid>", "message": "hi there @<username>"}' -H "Content-Type: application/json" -H "Accept: application/json" -H "OCS-APIRequest: true" -v -u "<username>:<password>" https://mydomain.tld/ocs/v1.php/apps/spreed/api/v1/chat/<roomid>
I tried to convert it toCode: Select all/tool fetch http-method=post http-header-field="{Accept:\"appli cation/json\",Authorization:\"Basic <hash here=>\",\"Content-Type\":\"appl ication/json\",\"OCS-APIRequest\":\"true\"}" http-data="{\"token\":\"<roomid>\",\"message\":\"hi t here @<username>\"}" url="domain.tld/ocs/v1.php/apps/spreed/api/v1/chat/<roomid>" user="<username>" password="<password>"
However, got the response:Code: Select allstatus: failed failure: closing connection: <412 Precondition failed> 144.**.**.***:443 (5)
http-header-field="Content-Type:application/json,OCS-APIRequest:true,Accept:application/json"
Many-many-many thanks for your so kind guidance. It works now!
You may need the "Authentication" line, but think that will get set automatically by RouterOS when you use user= password= (can't recall). And yeah perhaps escaping. But that the header line is issue I suspect.
You might want to start a new topic in the forum, explaining what you're planning/doing with /tool/fetch & nextcloud. This thread is now 3+ years old, so new subtopics get really confusing. Plus, you may not be only person using a Mikrotik to Nextcloud. They seems to have a few possible APIs...maybe someone has a script already.What I would like to improve is to use the anonymous posts in public conversations, however it brings additional pain: need to use 2 curls and analyse cookies. I have had a conversation with the Talk's devs, and they left not so easy to take ideas https://github.com/nextcloud/spreed/issues/6736.
You may need the "Authentication" line, but think that will get set automatically by RouterOS when you use user= password= (can't recall). And yeah perhaps escaping. But that the header line is issue I suspect.
Thanks! I will probably follow your advice. Have a good start of the New year!You might want to start a new topic in the forum, explaining what you're planning/doing with /tool/fetch & nextcloud. This thread is now 3+ years old, so new subtopics get really confusing. Plus, you may not be only person using a Mikrotik to Nextcloud. They seems to have a few possible APIs...maybe someone has a script already.
What I would like to improve is to use the anonymous posts in public conversations, however it brings additional pain: need to use 2 curls and analyse cookies. I have had a conversation with the Talk's devs, and they left not so easy to take ideas https://github.com/nextcloud/spreed/issues/6736.
:local arr {"mac"="aa:bb:cc:dd:ee:ff";"ip"="192.168.100.80"}; /tool fetch url=("https://some-server.com/index.php") http-method=https http-data=$arr mode=post keep-result=yes;