Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Qlik Enterprise Manager API is a set of API commands that can be run in the Windows Command Line or Linux Shells to automate actions. You will notice that certain characters can be interpreted differently when Curl commands are executed in these environments. This can cause the API commands to disregard any information presented after the special characters. The special characters must be escaped for them to be interpreted as normal text.
The Ampersand symbol (&) is considered to be one of the special characters. The '&' symbol can be found within many curl commands as a way to pass additional arguments to add additional behavior to the API commands. In our case, we will be using the RunTask API as an example.
Please refer to the Enterprise Manager API Guide for the full list of API commands. The code snippet below shows the syntax and example Curl request for the RunTask API.
https://{host}/attunityenterprisemanager/api/v1/servers/{ServerName}/tasks/{TaskName}?action=run&option={option}&timeout={timeout}
curl -i -k -X POST --header "EnterpriseManager.APISessionID: wCo0_KvjEUFROvfHF5KGrw" --header "Content-Length: 0" https://
computer.network.net/attunityenterprisemanager/api/
v1/servers/myrepsrv1/tasks/SalesDBBackup?action=run&option=RELOAD_TARGET
From the syntax above, you can see that the API action is to run the task with two optional arguments that you can add. They are the option and timeout arguments that allow you to specify another way to start the task and add a timeout time limit for this API request.
For our example, we will be running API with the option argument set to RELOAD_TARGET. This means when the API is executed, the task tables will be reloaded in addition to starting the task.
NOTE: The task must be in a stopped state for the RunTask API to execute
In the first example below, we will execute the Curl requests without escaping the '&' symbol. There can be two expected outcomes. One potential outcome is the Curl request completing partially and returning an error. The other outcome is the Curl request failing completely and timing out. If the Curl request is completed partially, you will see that the actions of the Curl command for 'run' executes and the additional arguments would be ignored. In our case, the RELOAD_TARGET argument will not be executed.
curl -i -k -X POST --header "EnterpriseManager.APISessionID: ddevtIlywer5xG_BPdL20w" --header "Content-Length: 0" https://usrem-gxy/attunityenterprisemanager/api/v1/servers/NewServer/tasks/ExampleTask?action=run&option=RELOAD_TARGET
In the image above, you will see that the Curl request is successful along with an error message. The error message indicates that the word 'option' could not be interpreted. From the Curl syntax seen earlier, the word 'option' appears right after the '&' symbol that we did not escape. The '&' symbol is causing the word 'option' to be interpreted differently instead of normal text.
Any attempts to execute the RunTask API with the task already running will result in the following 'error_code' message along with the normal 'error_message' if the Curl request fails.
"error_code":"AEM_TASK_ALREADY_RUNNING"
In our second example, we will be escaping the '&' symbols. This will allow all the arguments to be interpreted correctly. In the Windows Command Line, the Caret key (^) should be used for escaping characters while in Linux Shell environments, the backslash key (\) should be used.
Adding the escape key in front of the '&' symbols in the Curl request will allow the Curl request to be interpreted correctly. You will need to add one escape key in front of every '&' symbol if the Curl request contains more than one '&' symbol.
curl -i -k -X POST --header "EnterpriseManager.APISessionID: ddevtIlywer5xG_BPdL20w" --header "Content-Length: 0" https://usrem-gxy/attunityenterprisemanager/api/v1/servers/NewServer/tasks/ExampleTask?action=run^&option=RELOAD_TARGET
No error message is seen from the successful Curl request and when you check the task status, you will find that the task would have been reloaded from your Curl request.
The information in this article is provided as-is and to be used at own discretion. Depending on tool(s) used, customization(s), and/or other factors ongoing support on the solution below may not be provided by Qlik Support.