Public/Push-BookingsIDPMSToBB.ps1
Function Push-BookingsIDPMSToBB { <# .SYNOPSIS Get information of the bookings and process it directly in GoBright .DESCRIPTION Get information of the bookings and process it directly in GoBright .PARAMETER CSVFile The path to the CSVFile (not the format should match the required format) .PARAMETER CSVContainsHeader If the CSV contains a header, this header should not be taken as a reservation, with this switch the first line can be skipped .PARAMETER BrightBookingApiUrl Address of the BrightBooking API, e.g.: https://t1b.gobright.cloud/ .PARAMETER BrightBookingApiKey API key of the user to use to process the import .PARAMETER BrightBookingIntegrationName Name of the integration to link the users to .EXAMPLE Push-BookingsIDPMSToBB -CSVFile "[path to IDPMS csv export file]" -BrightBookingApiUrl "https://t1b.gobright.cloud/" -BrightBookingApiKey "[your api key]" -BrightBookingIntegrationName "HotelConcepts IDPMS" # Parse the CSV file and let BrightBooking process it directly .LINK https://support.gobright.com/ #> [CmdletBinding()] Param( [Parameter(Mandatory=$True)] [string]$CSVFile, [Parameter(Mandatory=$False)] [Switch]$CSVContainsHeader, [Parameter(Mandatory=$True)] [string]$BrightBookingApiUrl, [Parameter(Mandatory=$True)] [string]$BrightBookingApiKey, [Parameter(Mandatory=$True)] [string]$BrightBookingIntegrationName ) Process { Write-Output "Reading CSV file: $CSVFile" $readdata = Import-Csv $CSVFile -Header FromDate,UntilDate,FromTime,UntilTime,RoomName,OrganizationDescription,ActivityDescription If ($readdata) { If ($CSVContainsHeader.IsPresent) { $readdata = $readdata | Select-Object -Skip 1 } Write-Output "Read $($readdata.Count) reservations" # put/post to the api $access_token = Get-BBAccessToken -BrightBookingApiUrl $BrightBookingApiUrl -BrightBookingApiKey $BrightBookingApiKey $resturi = [System.Uri]::new([System.Uri]::new($BrightBookingApiUrl), "api/integrations/import/bookings/idpms") $Request = [System.UriBuilder]($resturi) $body = @{ "IntegrationName" = $BrightBookingIntegrationName "Bookings" = $readdata } $body = $body | ConvertTo-Json $hdrs = @{} $hdrs.Add("Authorization", "Bearer "+ $access_token) Try { $response = Invoke-RestMethod -Uri $Request.Uri -Method Put -Body ([System.Text.Encoding]::UTF8.GetBytes($body)) -Headers $hdrs -ContentType 'application/json' If ($response.StatusCode -eq 200 -or $response.StatusCode -eq 201) { Write-Output "Finished synchronizing reservations to GoBright successfully" } } Catch { $statusCode = $_.Exception.Response.StatusCode.Value__ $responseText = $_ If ($statusCode -eq 304) { Write-Output "Finished synchronizing reservations to GoBright successfully (reservations were not changed)" } Else { Try { $jsonresponse = $responseText | ConvertFrom-Json If ($jsonresponse.SyncRoot) { $statusMessage = $jsonresponse.SyncRoot | Out-String } Else { $statusMessage = $responseText } } Catch { $statusMessage = $responseText } Write-Output "Synchronizing reservations failed:" Write-Output "Statuscode: $statusCode, message: $statusMessage" Write-Output "" Write-Output "Please review the messages above, and if needed please review the log in the GoBright portal" Write-Output "" Write-Error "Could not process all reservations to GoBright" } } } } } |