Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
We are trying to prepare our server for patching with a scheduled job to shutdown our distribution service gracefully.
I’ve spend a lot of time in the code, but I keep getting the error: Invoke-WebRequest : The remote server returned an error: (401) Unauthorized.
I’m able to get the service statuses etc. with the API, but I can’t stop it.
The PowerShell code is as following
## URL for the QMS API endpoint
$url = "http://127.0.0.1:4799/QMS/Service "
$service = New-WebServiceProxy -Uri $url -Namespace QlikViewServer -UseDefaultCredential
$serviceKey = $service.GetTimeLimitedServiceKey()
$hdrs = @{}
$hdrs.Add("SOAPACTION","http://ws.qliktech.com/QMS/12/2/IQMS2/GetServices ")
$hdrs.Add("Content-Type", "text/xml;charset=utf-8")
$hdrs.Add('X-Service-Key',$serviceKey)
$body = @{}
$body = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/ ">
<s:Body>
<GetServices xmlns="http://ws.qliktech.com/QMS/12/2/ ">
<serviceTypes>All</serviceTypes>
</GetServices>
</s:Body>
</s:Envelope>'
Write-Output $hdrs
$res = Invoke-WebRequest -Uri $url -Method POST -Body $body -UseDefaultCredential -Headers $hdrs
[xml]$qdsServices = $res
$qdsService = $qdsServices.Envelope.Body.GetServicesResponse.GetServicesResult.ServiceInfo
$serviceName = "DSC@xxxxxxxx" #adjusttoservername
$service = $qdsservice | Where-Object { $_.Name -eq $serviceName }
$serviceId = $service.Id
$serviceAddress = $service.Address
$service = New-WebServiceProxy -Uri $url -Namespace QlikViewServer -UseDefaultCredential
$serviceKey = $service.GetTimeLimitedServiceKey()
$body = @{}
$body = '
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/ " xmlns:qms="http://schemas.qliktech.com/QMS/12/ ">
<soapenv:Header/>
<soapenv:Body>
<qms:ShutdownDistributionService>
<qms:serviceKey>'+$serviceKey+'</qms:serviceKey>
<qms:qdsID>'+$serviceId+'</qms:qdsID>
<qms:nodeID>'+'00000000-0000-0000-0000-000000000000'+'</qms:nodeID>
<qms:address>'+$serviceAddress+'</qms:address>
</qms:ShutdownDistributionService>
</soapenv:Body>
</soapenv:Envelope>'
Write-Output $hdrs2
Write-Output $body
Write-Output $serviceId
$res2 = Invoke-WebRequest -Uri $Url -Method Post -Headers $hdrs2 -Body $Body
$res2.Content
Does anyone know how I can get around the 401 authorization error?
Invoke-WebRequest : The remote server returned an error: (401) Unauthorized.
At C:\Users\XXXX\Desktop\Almost.ps1:57 char:9
+ $res2 = Invoke-WebRequest -Uri $Url -Method Post -Headers $hdrs2 -Bod ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
We are running Qlikview 12.70.20100.0
Access:
Ports on the firewall are open for 4799
Hi,
We found the solution and here is the working code:
## URL for the QMS API endpoint
$url = "http://127.0.0.1:4799/QMS/Service"
$service = New-WebServiceProxy -Uri $url -Namespace QlikViewServer -UseDefaultCredential
$serviceKey = $service.GetTimeLimitedServiceKey()
$hdrs = @{}
$hdrs.Add("SOAPACTION","http://ws.qliktech.com/QMS/12/2/IQMS2/GetReloadEngineServices")
$hdrs.Add("Content-Type", "text/xml;charset=utf-8")
$hdrs.Add('X-Service-Key',$serviceKey)
$body = @{}
$body = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
</s:Body>
</s:Envelope>'
$res = Invoke-WebRequest -Uri $url -Method POST -Body $body -UseDefaultCredential -Headers $hdrs
[xml]$qdsServices = $res
$qdsService = $qdsServices.Envelope.Body.GetReloadEngineServicesResponse.GetReloadEngineServicesResult.ServiceInfo
$serviceType = "QlikViewDistributionService"
$service = $qdsservice | Where-Object { $_.Type -eq $serviceType }
$serviceId = $service.Id
$serviceAddress = $service.Address
$service = New-WebServiceProxy -Uri $url -Namespace QlikViewServer -UseDefaultCredential
$serviceKey = $service.GetTimeLimitedServiceKey()
$hdrs2 = @{}
$hdrs2.Add("SOAPACTION","http://ws.qliktech.com/QMS/12/2/IQMS2/ShutdownDistributionService")
$hdrs2.Add("Content-Type", "text/xml;charset=utf-8")
$hdrs2.Add('X-Service-Key',$serviceKey)
$body2 = @{}
$body2 = '
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<ShutdownDistributionService xmlns="http://ws.qliktech.com/QMS/12/2/">
<qdsID>'+$serviceId+'</qdsID>
<nodeID>'+'00000000-0000-0000-0000-000000000000'+'</nodeID>
<address>'+$serviceAddress+'</address>
</ShutdownDistributionService>
</s:Body>
</s:Envelope>'
$res2 = Invoke-WebRequest -Uri $url -Method Post -Body $body2 -UseDefaultCredential -Headers $hdrs2
Hi,
We found the solution and here is the working code:
## URL for the QMS API endpoint
$url = "http://127.0.0.1:4799/QMS/Service"
$service = New-WebServiceProxy -Uri $url -Namespace QlikViewServer -UseDefaultCredential
$serviceKey = $service.GetTimeLimitedServiceKey()
$hdrs = @{}
$hdrs.Add("SOAPACTION","http://ws.qliktech.com/QMS/12/2/IQMS2/GetReloadEngineServices")
$hdrs.Add("Content-Type", "text/xml;charset=utf-8")
$hdrs.Add('X-Service-Key',$serviceKey)
$body = @{}
$body = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
</s:Body>
</s:Envelope>'
$res = Invoke-WebRequest -Uri $url -Method POST -Body $body -UseDefaultCredential -Headers $hdrs
[xml]$qdsServices = $res
$qdsService = $qdsServices.Envelope.Body.GetReloadEngineServicesResponse.GetReloadEngineServicesResult.ServiceInfo
$serviceType = "QlikViewDistributionService"
$service = $qdsservice | Where-Object { $_.Type -eq $serviceType }
$serviceId = $service.Id
$serviceAddress = $service.Address
$service = New-WebServiceProxy -Uri $url -Namespace QlikViewServer -UseDefaultCredential
$serviceKey = $service.GetTimeLimitedServiceKey()
$hdrs2 = @{}
$hdrs2.Add("SOAPACTION","http://ws.qliktech.com/QMS/12/2/IQMS2/ShutdownDistributionService")
$hdrs2.Add("Content-Type", "text/xml;charset=utf-8")
$hdrs2.Add('X-Service-Key',$serviceKey)
$body2 = @{}
$body2 = '
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<ShutdownDistributionService xmlns="http://ws.qliktech.com/QMS/12/2/">
<qdsID>'+$serviceId+'</qdsID>
<nodeID>'+'00000000-0000-0000-0000-000000000000'+'</nodeID>
<address>'+$serviceAddress+'</address>
</ShutdownDistributionService>
</s:Body>
</s:Envelope>'
$res2 = Invoke-WebRequest -Uri $url -Method Post -Body $body2 -UseDefaultCredential -Headers $hdrs2