Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Manish
Creator
Creator

Get Qlik Sense Task ID by passing Task Name using API endpoint from C# .net code

Hi

I have a requirement where I would like to get task ID by passing the task name using QS API endpoint from C#.net code.

Is this something that can be done?

I tried below code which is giving me all the tasks but I want to pass a task name and get its specific task id.

var restClient = new RestClient(qliksenseurl);

var executeTask1 = $"/qrs/task/";

var rsp1 = await restClient.GetAsync<JArray>(executeTask1);

Labels (2)
1 Solution

Accepted Solutions
marksouzacosta
Partner - Specialist
Partner - Specialist

Hi @Manish,

We are here again 🙂

Use this code and you should be fine. I used as a filter a task name called 'Temp Test':

try
{
Console.WriteLine("Starting Qlik Sense Connection");
var restClient = new RestClient(qlikSenseUrl);
restClient.AsNtlmUserViaProxy(new NetworkCredential(userName, securePassword, userDomain), certificateValidation: false);
Console.WriteLine("Connection stabilished");

var getTaskURL = $"/qrs/task?filter=name eq 'Temp Test'";
foreach (var task in await restClient.GetAsync<JArray>(getTaskURL))
{
Console.WriteLine(task["id"]);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

 

Read more at Data Voyagers - datavoyagers.net

View solution in original post

5 Replies
marksouzacosta
Partner - Specialist
Partner - Specialist

Hi @Manish,

We are here again 🙂

Use this code and you should be fine. I used as a filter a task name called 'Temp Test':

try
{
Console.WriteLine("Starting Qlik Sense Connection");
var restClient = new RestClient(qlikSenseUrl);
restClient.AsNtlmUserViaProxy(new NetworkCredential(userName, securePassword, userDomain), certificateValidation: false);
Console.WriteLine("Connection stabilished");

var getTaskURL = $"/qrs/task?filter=name eq 'Temp Test'";
foreach (var task in await restClient.GetAsync<JArray>(getTaskURL))
{
Console.WriteLine(task["id"]);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}

 

Read more at Data Voyagers - datavoyagers.net
Manish
Creator
Creator
Author

Hahah... Yes, I thought it is better to start a new discussion rather than using the old one.

Thanks @marksouzacosta It worked perfectly.

Øystein_Kolsrud
Employee
Employee

You might also want to have a look at this page describing filtering options:
https://help.qlik.com/en-US/sense-developer/May2024/Subsystems/RepositoryServiceAPI/Content/Sense_Re...

Manish
Creator
Creator
Author

Thanks @Øystein_Kolsrud . It is helpful to know.

Marc
Employee
Employee

As a little trick, 

There is a PowerShell binary module QlikSenseCLI. in recent versions of Qlik Sense this will be in you install directory \Tools\QlikSenseCLI


you can add the QlikSenseCLI.dll to you C# project, and use that to communicate with the QRS Apis.

bool TrustAllCertificates = true;
// you can authenticate in a variety of ways
//Current User Local system
client = QlikSenseCLI.QlikSense.Connect();
//QlikClient Certificate Auth
client = QlikSenseCLI.QlikSense.Connect(hostname, x509Cetificate, "Internal\\sa_api", TrustAllCertificates);
//Specified host Current User Auth
client = QlikSenseCLI.QlikSense.Connect(hostname,TrustAllCertificates);
//Specified host, specified credentials
client = QlikSenseCLI.QlikSense.Connect(hostname,networkCredentials,TrustAllCertificates);

var getTaskURL = $"/qrs/task?filter=name eq 'Temp Test'";
QlikSenseCLI.Model.TaskCondensed[] tasks = client.InvokeGet(getTaskURL);

var getTaskFullURL = $"/qrs/task/full?filter=name eq 'Temp Test'";
QlikSenseCLI.Model.Task[] tasksFull = client.InvokeGet(getTaskFullURL);