Community discussions

MikroTik App
 
miszeli
just joined
Topic Author
Posts: 12
Joined: Fri May 19, 2017 12:19 pm

Api script add from file

Wed Apr 04, 2018 2:53 pm

Hello,
I have a bit problem with api , i need to import content of file (file already exist at mikrotik) as source of script ., i try :
/system/script/add =name=Test =source=[/file get script.txt content]
But source in script is [/file .....] , no content of file , anybody have any solution ?
Thanks so much !
 
User avatar
ADahi
Member Candidate
Member Candidate
Posts: 209
Joined: Thu Sep 21, 2017 7:16 pm
Location: Iraq, Ninavah
Contact:

Re: Api script add from file

Fri Apr 06, 2018 11:38 am

via CLI:
/system script add name=test source=[/file get run.txt contents];
 
miszeli
just joined
Topic Author
Posts: 12
Joined: Fri May 19, 2017 12:19 pm

Re: Api script add from file

Fri Apr 06, 2018 12:04 pm

It works normally in CLI , but i ask about how to do it via API , that is a problem
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Api script add from file

Fri Apr 06, 2018 11:28 pm

You make two API calls - one to get the file contents from the router to the API client, another to put that content into the script. That's also how CLI does it, except that it's on a single line.

Or you could add the script with the CLI contents in it, and run it, to let it modify itself. That's also two API calls, but the file contents won't need to be downloaded and reuploaded.

e.g. API flow
/system/script/add
=name=Test
=source=/system script set Test source=[/file get script.txt contents];

!done
=ret=*a1

/system/script/run
=number=Test

!done

Who is online

Users browsing this forum: No registered users and 23 guests