Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
covering
Contributor II
Contributor II

Start a task, wait for execution end and check task execution status using .NET

We use the PowerShell module "Qlik-CLI" for years to start Qlik Sense tasks, wait for task execution end and check execution status.
Due to recurrent issues with out enterprise Security tools about the PowerShell module "Qlik-CLI" we need to switch to another technology and we are trying the Øystein Kolsrud's C#/.NET library "Qlik.Sense.RestClient" available on github and nuget. This library is not documented for our purpose : we can start a task with the method RestClient.Post but we are not able to get the response and get the execution ID needed to poll the execution status.

Could you please provide a solution to start a Qlik Sense task in .NET/C#, wait for execution end and check the status.
Thanks in advance for your answer.

Labels (1)
1 Solution

Accepted Solutions
covering
Contributor II
Contributor II
Author

I found the solution the day after my post but forgot to close this post.

Sorry about that.

Below the methods I use to  start a task and poll the execution status :

        private static String StartTask(RestClient restClient, String TaskId)
        {
            String task_start_response = restClient.Post("/qrs/task/" +  TaskId + "/start/synchronous");
            return JObject.Parse(task_start_response)["value"].Value<string>();
        }
        private static String GetExecutionStatus(RestClient restClient, String ExecutionId, String TaskId)
        {
            String ResultId;
            try
            {
                String execution_session_response = restClient.Get("/qrs/executionSession/" + ExecutionId);
                ResultId = JObject.Parse(execution_session_response)["executionResult"]["id"].Value<string>();
            }
            catch
            {
                String reloadtask_response = restClient.Get("/qrs/reloadTask/" + TaskId);
                ResultId = JObject.Parse(reloadtask_response)["operational"]["lastExecutionResult"]["id"].Value<string>();
            }
            String execution_result_response = restClient.Get("/qrs/executionResult/" + ResultId);
            return JObject.Parse(execution_result_response)["status"].Value<string>();
        }
    }

Best regards

View solution in original post

3 Replies
covering
Contributor II
Contributor II
Author

I realized I posted in "QlikView Integrations". Sorry about that. Would it be possible to move this request to Qlik Sense ?

Chip_Matejowsky
Support
Support

Hi @covering.

I moved this post to the Qlik Sense > Deployment & Management forum as you requested.

Best Regards

Principal Technical Support Engineer with Qlik Support
Help users find answers! Don't forget to mark a solution that worked for you!
covering
Contributor II
Contributor II
Author

I found the solution the day after my post but forgot to close this post.

Sorry about that.

Below the methods I use to  start a task and poll the execution status :

        private static String StartTask(RestClient restClient, String TaskId)
        {
            String task_start_response = restClient.Post("/qrs/task/" +  TaskId + "/start/synchronous");
            return JObject.Parse(task_start_response)["value"].Value<string>();
        }
        private static String GetExecutionStatus(RestClient restClient, String ExecutionId, String TaskId)
        {
            String ResultId;
            try
            {
                String execution_session_response = restClient.Get("/qrs/executionSession/" + ExecutionId);
                ResultId = JObject.Parse(execution_session_response)["executionResult"]["id"].Value<string>();
            }
            catch
            {
                String reloadtask_response = restClient.Get("/qrs/reloadTask/" + TaskId);
                ResultId = JObject.Parse(reloadtask_response)["operational"]["lastExecutionResult"]["id"].Value<string>();
            }
            String execution_result_response = restClient.Get("/qrs/executionResult/" + ResultId);
            return JObject.Parse(execution_result_response)["status"].Value<string>();
        }
    }

Best regards