Add opera_roomlist_creator.ps1
This commit is contained in:
parent
53a698bbca
commit
de4a0e1f9d
87
opera_roomlist_creator.ps1
Normal file
87
opera_roomlist_creator.ps1
Normal file
@ -0,0 +1,87 @@
|
||||
# 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
|
||||
RoomType = $roomType
|
||||
RoomDescription = $roomDescription
|
||||
}
|
||||
}
|
||||
|
||||
# Export to CSV
|
||||
$roomData | Export-Csv -Path "RoomStatusReport.csv" -NoTypeInformation -Encoding UTF8
|
||||
Write-Output "Room status data has been saved to RoomStatusReport.csv"
|
Loading…
x
Reference in New Issue
Block a user