Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Predrag
Contributor
Contributor

Call QMS API with PowerShell and get running tasks

Hello everyone,

I am trying to write Powershell script that will call QMS API and  give me all currently running tasks on Qlikview server.  Script that i have wrote gives me only ID-es of all tasks on server, and not currently running tasks.  And also does not give me details on any tasks that has returned.  I have used GetTaskStatuses method from here , but I think am making some mistake in body of  GetTaskStatuses which i can't get to solve.
Could you please help me?

$url = "http://ip_adress:4799/QMS/Service"
function GetServiceKey
{
   param(
     [string]$url
   ) 
    $service = New-WebServiceProxy -Uri $url -Namespace QlikViewServer -UseDefaultCredential
    $serviceKey = $service.GetTimeLimitedServiceKey()
    return $serviceKey
}
$hdrs = @{}
$hdrs.Add("SOAPACTION","http://ws.qliktech.com/QMS/12/3/IQMS3/GetTaskStatuses")
$hdrs.Add("Content-Type", "text/xml;charset=utf-8")
$hdrs.Add('X-Service-Key',$(GetServiceKey -url $url))
$body = @{} $body = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body> <GetTaskStatuses xmlns="http://ws.qliktech.com/QMS/12/3/"> <filter> <TaskStatusFilter> <TaskStatuses>Running</TaskStatuses> </TaskStatusFilter> </filter> <Scope> <TaskStatusScope>Extended</TaskStatusScope> </Scope> </GetTaskStatuses> </s:Body> </s:Envelope>' $res = Invoke-WebRequest -Uri $url -Method Post -Body $body -UseDefaultCredential -Headers $hdrs [xml]$myXml = $res.Content $myXml.Envelope.Body.GetTaskStatusesResponse.GetTaskStatusesResult.TaskStatus

Thank you

2 Solutions

Accepted Solutions
Yang_Jiao
Support
Support

Hi,

I checked your request, and seems like the XML body has several incorrect places. Try this one:

$body = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetTaskStatuses xmlns="http://ws.qliktech.com/QMS/12/2/">
<filter xmlns:a="http://schemas.datacontract.org/2004/07/PIX.QMSAPI.DataObjects">
<a:TaskStatuses> 
<a:TaskStatusValue>Running</a:TaskStatusValue>
</a:TaskStatuses>
</filter>
<scope>General</scope>
</GetTaskStatuses>
</s:Body>
</s:Envelope>'

TaskStatusFilter is one type of the QMS API Data Objects, therefore you need to specify it in the name space. 

Please mark the post as SOLVED if this answers your question. Thanks.

View solution in original post

Predrag
Contributor
Contributor
Author

Hi Yjo,

Thank you for your response. I have tried your code and script gives an error while running and return all tasks.  But I have managed to use part of your code:

<a:TaskStatuses> 
<a:TaskStatusValue>Running</a:TaskStatusValue>
</a:TaskStatuses>

to get proper solution.

I used QMS Client application from power tools and Wireshark to track requests that application is sending to QMS API. Application can't return Running tasks so I saw xml request like this:

'<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
    <GetTaskStatuses xmlns="http://ws.qliktech.com/QMS/11/">
    <filter
        xmlns:a="http://schemas.datacontract.org/2004/07/PIX.QMSAPI.DataObjects"
        xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:Categories
            i:nil="true"
            xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
        <a:EnabledState>Enabled</a:EnabledState>
        <a:LastExecution
            i:nil="true"/>
        <a:QDSIds
            i:nil="true"
            xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
        <a:Schedule
            i:nil="true"/>
        <a:TaskIds
            i:nil="true"
            xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
        <a:TaskName
            i:nil="true"/>
        <a:TaskStatuses
            i:nil="true"/>
        <a:TaskTypes
            i:nil="true"/>   
    </filter>
    <scope>All</scope>
  </GetTaskStatuses>
</s:Body>
</s:Envelope>'

Then I inserted your part of code that I have mentioned above and get the right answer from QMS API. The proper code is:

$url = "http://ip_address :4799/QMS/Service"
 
function GetServiceKey
{
   param(
     [string]$url
   ) 
    $service = New-WebServiceProxy -Uri $url -Namespace QlikViewServer -UseDefaultCredential
    $serviceKey = $service.GetTimeLimitedServiceKey()
    return $serviceKey
}

$hdrs = @{}
$hdrs.Add("SOAPACTION","http://ws.qliktech.com/QMS/11/IQMS/GetTaskStatuses")
$hdrs.Add("Content-Type", "text/xml;charset=utf-8")
$hdrs.Add("X-Service-Key",$(GetServiceKey -url $url))
$hdrs.add("Accept-Encoding", "gzip, deflate")

$body = @{}
$body = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
    <GetTaskStatuses xmlns="http://ws.qliktech.com/QMS/11/">
    <filter
        xmlns:a="http://schemas.datacontract.org/2004/07/PIX.QMSAPI.DataObjects"
        xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:Categories
            i:nil="true"
            xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
        <a:EnabledState>Enabled</a:EnabledState>
        <a:LastExecution
            i:nil="true"/>
        <a:QDSIds
            i:nil="true"
            xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
        <a:Schedule
            i:nil="true"/>
        <a:TaskIds
            i:nil="true"
            xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
        <a:TaskName
            i:nil="true"/>
        <a:TaskStatuses>	   
            <a:TaskStatusValue>Running</a:TaskStatusValue>
        </a:TaskStatuses>
        <a:TaskTypes
            i:nil="true"/>   
    </filter>
    <scope>All</scope>
  </GetTaskStatuses>
</s:Body>
</s:Envelope>'

$res = Invoke-WebRequest -Uri $url -Method Post -Body $body -UseDefaultCredential -Headers $hdrs

[xml]$myXml = $res.Content

$myXml.Envelope.Body.GetTaskStatusesResponse.GetTaskStatusesResult.TaskStatus

View solution in original post

5 Replies
Yang_Jiao
Support
Support

Hi,

I checked your request, and seems like the XML body has several incorrect places. Try this one:

$body = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<GetTaskStatuses xmlns="http://ws.qliktech.com/QMS/12/2/">
<filter xmlns:a="http://schemas.datacontract.org/2004/07/PIX.QMSAPI.DataObjects">
<a:TaskStatuses> 
<a:TaskStatusValue>Running</a:TaskStatusValue>
</a:TaskStatuses>
</filter>
<scope>General</scope>
</GetTaskStatuses>
</s:Body>
</s:Envelope>'

TaskStatusFilter is one type of the QMS API Data Objects, therefore you need to specify it in the name space. 

Please mark the post as SOLVED if this answers your question. Thanks.

Predrag
Contributor
Contributor
Author

Hi Yjo,

Thank you for your response. I have tried your code and script gives an error while running and return all tasks.  But I have managed to use part of your code:

<a:TaskStatuses> 
<a:TaskStatusValue>Running</a:TaskStatusValue>
</a:TaskStatuses>

to get proper solution.

I used QMS Client application from power tools and Wireshark to track requests that application is sending to QMS API. Application can't return Running tasks so I saw xml request like this:

'<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
    <GetTaskStatuses xmlns="http://ws.qliktech.com/QMS/11/">
    <filter
        xmlns:a="http://schemas.datacontract.org/2004/07/PIX.QMSAPI.DataObjects"
        xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:Categories
            i:nil="true"
            xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
        <a:EnabledState>Enabled</a:EnabledState>
        <a:LastExecution
            i:nil="true"/>
        <a:QDSIds
            i:nil="true"
            xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
        <a:Schedule
            i:nil="true"/>
        <a:TaskIds
            i:nil="true"
            xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
        <a:TaskName
            i:nil="true"/>
        <a:TaskStatuses
            i:nil="true"/>
        <a:TaskTypes
            i:nil="true"/>   
    </filter>
    <scope>All</scope>
  </GetTaskStatuses>
</s:Body>
</s:Envelope>'

Then I inserted your part of code that I have mentioned above and get the right answer from QMS API. The proper code is:

$url = "http://ip_address :4799/QMS/Service"
 
function GetServiceKey
{
   param(
     [string]$url
   ) 
    $service = New-WebServiceProxy -Uri $url -Namespace QlikViewServer -UseDefaultCredential
    $serviceKey = $service.GetTimeLimitedServiceKey()
    return $serviceKey
}

$hdrs = @{}
$hdrs.Add("SOAPACTION","http://ws.qliktech.com/QMS/11/IQMS/GetTaskStatuses")
$hdrs.Add("Content-Type", "text/xml;charset=utf-8")
$hdrs.Add("X-Service-Key",$(GetServiceKey -url $url))
$hdrs.add("Accept-Encoding", "gzip, deflate")

$body = @{}
$body = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
    <GetTaskStatuses xmlns="http://ws.qliktech.com/QMS/11/">
    <filter
        xmlns:a="http://schemas.datacontract.org/2004/07/PIX.QMSAPI.DataObjects"
        xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:Categories
            i:nil="true"
            xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
        <a:EnabledState>Enabled</a:EnabledState>
        <a:LastExecution
            i:nil="true"/>
        <a:QDSIds
            i:nil="true"
            xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
        <a:Schedule
            i:nil="true"/>
        <a:TaskIds
            i:nil="true"
            xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
        <a:TaskName
            i:nil="true"/>
        <a:TaskStatuses>	   
            <a:TaskStatusValue>Running</a:TaskStatusValue>
        </a:TaskStatuses>
        <a:TaskTypes
            i:nil="true"/>   
    </filter>
    <scope>All</scope>
  </GetTaskStatuses>
</s:Body>
</s:Envelope>'

$res = Invoke-WebRequest -Uri $url -Method Post -Body $body -UseDefaultCredential -Headers $hdrs

[xml]$myXml = $res.Content

$myXml.Envelope.Body.GetTaskStatusesResponse.GetTaskStatusesResult.TaskStatus
Yang_Jiao
Support
Support

Hi Predrag,

Yes, using the request from the QMS Client as template is a good approach. I used the same approach as well.

Actually you don't need all the  "i:nil=true" values in your request I think, as they are NULL values.

And in the Scope you can use General instead of All, because the status you want is listed under the General section in the response.

Best regards,
Yang

dmitrydv
Contributor II
Contributor II

Yang,

Thank you for your answer.

Could you please help with TaskStatusFilter  "Categories" property.

I would like to retrive tasks with Category = "Applications" or "ReportsHR".

-- updated..

I tried this part of xml body, but it doesn't affected and responce contains all tasks...

$body = '

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<s:Body>
<GetTaskStatuses xmlns="http://ws.qliktech.com/QMS/12/2/">

<filter xmlns:a="http://schemas.datacontract.org/2004/07/PIX.QMSAPI.DataObjects">

<a:Categories>
<a:Category>Applications</a:Category>
</a:Categories>

</filter>

<scope>All</scope>
</GetTaskStatuses>
</s:Body>
</s:Envelope>'

 

Marc
Employee
Employee