How to run your own SyncJS scripts¶
Syncplify.me AFT! is very flexible, and allows you to run your scripts (AFT tasks) in several different ways, so that you can run them interactively, or even automate their execution when necessary.
Run scripts from within the web interface¶
This is probably the most intuitive way to run your scripts. In the “Scripts” section of the web interface, simply hit the “run” button next to the script you want to execute.
Run scripts via REST API¶
Syncplify.me AFT! also allows you to run your scripts via REST API. To do so, first you have to create an API Key, as shown in the picture here below.
Please keep in mind that it’s highly recommended to limit each API Key you create with a “whitelist”. A whitelist is a list of IP addresses and networks from which such API Key will be accepted. If someone tries to run a script using this API Key from a machine (remote IP address) that’s not in the Key’s whitelist, the script will not be executed. This provides an additional level of security and safety.
Once your API Key exists, then you can run your scripts by simply consuming the following REST API endpoint (which is super easy to do in practically every modern development language and/or shell):
curl --request POST \
--url https://127.0.0.1:44399/jobs \
--header 'Authorizaton: Bearer' \
--header 'Content-Type: application/json' \
--header 'X-API-Key: put_your_api_key_here' \
--data '{
"jobType": "SCRIPT",
"id": "id_of_the_script_you_wish_to_run",
"params": [
{
"name": "someParameterName",
"value": "actual parameter value"
}
]
}'
Run scripts interactively from the command prompt¶
From the command prompt (or even from the PowerShell) you can invoke the execution of a script that’s saved in a file very easily by using the “run” command built into AFT! itself, and the –file (or -f shorthand) parameter, as shown in the picture here below.
This method is very useful also to schedule the execution of your scripts (saved as files) from the Windows Scheduler (or cron in Linux).
Run scripts interactively by double-clicking on them¶
Since you can save scripts as normal plain text files, you can also run them by simply double-clicking on them from within your operating system’s window manager (Explorer in Windows, or GNOME/KDE/… in Linux).
Note
In Windows, if your file has a “.syncjs” extension it will be run and then the console it’s been run into will remain open for you to check the resulting log; if, on the other hand, the file has a “.syncjsx” extension, the console window will be automatically closed after the script finishes running.
Run scripts from the command-line (but via REST API)¶
There are cases in which you may want to start the execution of a script from the command-line, but you don’t want such scripts to run in the context of the current user, instead you want to start their execution inside of the system service, which runs with different (usually higher) privileges.
As of version 3.0, Syncplify.me AFT! has added the capability to start jobs via the START command-line switch and parameters. To be clear, unlike the RUN command (which executes a script from file in the context of whatever shell you invoked it) the START command will actually call a REST API for you to start the job within the context of the Syncplify.me AFT! system service.
.\aft.exe start -s "p3fEoexohdHj6SXrvuT8H8" -a "xiM2ruBm2QZkhTSN6BPd9BqmxVEBVbrgNYVMkNQb6hfj" --params "[{\`"name\`":\`"character\`",\`"value\`":\`"goofy\`"}]" --host "127.0.0.1:44399"
The example here above assumes you’re invoking the command via PowerShell… please keep in mind that other shells (like cmd.exe or Unix/Linux shells) may have different string “escaping” mechanisms and notations.