109 lines
4.5 KiB
PowerShell
109 lines
4.5 KiB
PowerShell
# Load the hotel configuration
|
|
$hotelConfig = Get-Content -Path "HotelConfig.json" | ConvertFrom-Json
|
|
|
|
# Endpoint and SOAP action
|
|
$endpoint = "$($hotelConfig.SiteURL)/ResvAdvanced"
|
|
$soapAction = "http://webservices.micros.com/og/4.3/ResvAdvanced/FetchRoomStatusRequest"
|
|
|
|
# Bypass SSL certificate validation (use with caution)
|
|
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
|
|
|
|
# Set the current time in UTC for timestamps
|
|
$currentTime = [DateTime]::UtcNow
|
|
$createdTime = $currentTime.ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
|
|
$expiresTime = $currentTime.AddMinutes(1).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
|
|
|
|
# Define the SOAP request body with dynamic hotel data
|
|
$xmlContent = @"
|
|
<soapenv:Envelope xmlns:core="http://webservices.micros.com/og/4.3/Core/" xmlns:hot="http://webservices.micros.com/og/4.3/HotelCommon/" xmlns:res="http://webservices.micros.com/og/4.3/ResvAdvanced/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
|
|
<soapenv:Header>
|
|
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
|
|
<wsu:Timestamp wsu:Id="TS-8549BADB527F5C3D8417298576962481">
|
|
<wsu:Created>$createdTime</wsu:Created>
|
|
<wsu:Expires>$expiresTime</wsu:Expires>
|
|
</wsu:Timestamp>
|
|
<wsse:UsernameToken>
|
|
<wsse:Username>$($hotelConfig.UserName)</wsse:Username>
|
|
<wsse:Password>$($hotelConfig.Password)</wsse:Password>
|
|
</wsse:UsernameToken>
|
|
</wsse:Security>
|
|
<core:OGHeader primaryLangID="E" timeStamp="$createdTime" transactionID="919554d9-1929-474d-89a6-369a131911fe">
|
|
<core:Origin entityID="$($hotelConfig.OriginEntityID)" systemType="$($hotelConfig.OriginSystemType)"/>
|
|
<core:Destination entityID="$($hotelConfig.DestinationEntityID)" systemType="$($hotelConfig.DestinationSystemType)"/>
|
|
<core:Authentication>
|
|
<core:UserCredentials>
|
|
<core:UserName>$($hotelConfig.SiteUsername)</core:UserName>
|
|
<core:Domain>$($hotelConfig.Domain)</core:Domain>
|
|
</core:UserCredentials>
|
|
</core:Authentication>
|
|
</core:OGHeader>
|
|
</soapenv:Header>
|
|
<soapenv:Body>
|
|
<res:FetchRoomStatusRequest RoomNumber="">
|
|
<res:HotelReference chainCode="$($hotelConfig.ChainCode)" hotelCode="$($hotelConfig.HotelCode)"/>
|
|
</res:FetchRoomStatusRequest>
|
|
</soapenv:Body>
|
|
</soapenv:Envelope>
|
|
"@
|
|
|
|
# Define the headers
|
|
$headers = @{
|
|
"Content-Type" = "text/xml; charset=utf-8"
|
|
"SOAPAction" = $soapAction
|
|
}
|
|
|
|
$byteArray = [System.Text.Encoding]::UTF8.GetBytes($xmlContent)
|
|
|
|
# Send the request with verbose output
|
|
$response = Invoke-WebRequest -Uri $endpoint -Method Post -Body $byteArray -Headers $headers -UseBasicParsing -Verbose
|
|
|
|
# Output the response
|
|
$response.Content
|
|
|
|
# Parse the XML content for namespaces
|
|
[xml]$xmlResponse = $response.Content
|
|
$namespaceManager = New-Object System.Xml.XmlNamespaceManager($xmlResponse.NameTable)
|
|
$namespaceManager.AddNamespace("res", "http://webservices.micros.com/og/4.3/ResvAdvanced/")
|
|
|
|
# Select nodes with the namespace prefix
|
|
$roomNodes = $xmlResponse.SelectNodes("//res:RoomStatus", $namespaceManager)
|
|
|
|
# Collect room data
|
|
$roomData = @()
|
|
foreach ($room in $roomNodes) {
|
|
$roomID = $room.RoomNumber
|
|
$roomType = $room.RoomType
|
|
$roomDescription = $room.RoomDescription
|
|
|
|
$roomData += [PSCustomObject]@{
|
|
RoomID = $roomID
|
|
Rflag = 0
|
|
RoomDescription = $roomDescription
|
|
RoomTypeCode = $roomType
|
|
TelNo1 = ""
|
|
TelNo2 = ""
|
|
}
|
|
}
|
|
|
|
|
|
|
|
# Export to CSV
|
|
$roomData | Export-Csv -Path "RoomStatusReport.csv" -NoTypeInformation -Encoding UTF8
|
|
|
|
# The below parameter is used for version 7 of powershell for the above command
|
|
# -UseQuotes never
|
|
Write-Output "Room status data has been saved to RoomStatusReport.csv"
|
|
|
|
# because we cannot remove the quote marks due to the powershell version, we use the below command to remove them
|
|
(Get-Content .\RoomStatusReport.csv -Encoding UTF8) | % {$_ -replace '"',''} | Select-String -Pattern "^\d\d\d," | out-File .\RoomStatusReport.csv -Encoding utf8
|
|
|
|
Write-Output "removed Quotes"
|
|
|
|
#adding the headers back in
|
|
$header = 'RoomID,Rflag,RoomDescription,RoomTypeCode,TelNo1,TelNo2'
|
|
$data = Get-Content .\RoomStatusReport.csv -Encoding UTF8
|
|
|
|
$header | Set-Content .\RoomStatusReport.csv -NoNewline
|
|
$data | Add-Content .\RoomStatusReport.csv
|
|
|
|
Write-Output "added headers back in" |