Private/Invoke-HPIncSOAPRequest.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<#
    .SYNOPSIS
        Invokes a SOAP Request.
    .DESCRIPTION
        Sends a SOAP Request to Hewlett-Packard and returns Entitlement data for non Enterprise systems.
    .INPUTS
        None.
    .OUTPUTS
        System.Xml
    .PARAMETER SOAPRequest
        The Xml formated request to send
    .PARAMETER Url
        The URL to send the SOAP request.
    .LINK
        http://dotps1.github.io/HPWarranty
#>

Function Invoke-HPIncSOAPRequest {

    [CmdletBinding()]
    [OutputType(
        [Xml]
    )]

    Param (
        [Parameter(
            Mandatory = $true
        )]
        [Xml]
        $SOAPRequest,
        
        [Parameter()]
        [String]
        $Url = 'https://api-uns-sgw.external.hp.com/gw/hpit/egit/obligation.sa/1.1'
    )

    $soapWebRequest = [System.Net.WebRequest]::Create($URL) 
    $soapWebRequest.Headers.Add('X-HP-SBS-ApplicationId','hpi-obligation-hpsa')
    $soapWebRequest.Headers.Add('X-HP-SBS-ApplicationKey','ft2VGa2hx9j$')
    $soapWebRequest.ContentType = 'text/xml; charset=utf-8'
    $soapWebRequest.Accept = 'text/xml'
    $soapWebRequest.Method = 'POST'

    try {
        $SOAPRequest.Save(
            ($requestStream = $soapWebRequest.GetRequestStream())
        )

        $requestStream.Close() 

        $responseStream = ($soapWebRequest.GetResponse()).GetResponseStream()
        
        [Xml]([System.IO.StreamReader]($responseStream)).ReadToEnd()

        $responseStream.Close() 
    } catch {
        throw $_
    }
}