CCRestMethod.ps1
# # Citrix API Rest Call (Support Export/Prepare/GetJob) # Function BuildUrl([string]$deployment, [string]$serviceRoute, [hashtable]$query) { if ($deployment) { $baseUrl = "https://$deployment/" } else { $baseUrl = "https://api.layering.cloud.com/" } $queryParams = [System.Web.HttpUtility]::ParseQueryString([String]::Empty) $query.Keys | ForEach-Object { $queryParams.Add($_, $query[$_]) } $url = [System.UriBuilder]$baseUrl $url.Path = $serviceRoute $url.Query = $queryParams.ToString() return $url.Uri } Function GetAuthHeaders([string]$customerId, [string]$secureClientId, [string]$secureSecret) { if ([string]::IsNullOrEmpty($GLOBAL:XDAuthToken)) { try { $parameters = AuthToCitrixCloud $CustomerId $SecureClientId $SecureSecret } catch { throw "Failed to get bearer token: $_" } } $headers = @{ 'Authorization' = $GLOBAL:XDAuthToken 'Citrix-CustomerId' = $customerId 'Accept' = 'application/json' 'Content-Type' = 'application/json;charset=utf-8' } return $headers } Function Invoke-CCRestMethod( [string]$method, [string]$deployment, [string]$serviceRoute, [string]$customerId, [string]$secureClientId, [string]$secureSecret, [hashtable]$query = @{}, [psobject]$json = $null ) { $url = BuildUrl $deployment $serviceRoute $query $headers = GetAuthHeaders $customerId $secureClientId $secureSecret $moduleInfo = Get-InstalledModule "Citrix.Workloads.Portability" $parameters = @{ Headers = $headers Method = $method UserAgent = "Citrix.Workloads.Portability/$($moduleInfo.Version) Powershell/$($PSVersionTable.PSVersion)" Verbose = $Global:LogVerbose } if ($json) { $parameters['Body'] = $json } try { return Invoke-RestMethod $url @parameters } catch { throw "$method REST method failed: $_" } } |