Public/UserCostAttribution.ps1
Function Remove-NmeUserCostAttributionConfiguration { <# .SYNOPSIS Delete configuration. .DESCRIPTION Delete configuration. This function calls the /api/v1/user-cost-attribution/configuration/{id} endpoint of the NME REST API, using the delete method. .PARAMETER Id ID of scripted Action #> [CmdletBinding()] Param( [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$Id ) Set-NmeAuthHeaders Try { $Result = Invoke-RestMethod "$script:NmeUri/api/v1/user-cost-attribution/configuration/$Id$Querystring" -Method delete -Headers $script:AuthHeaders -ContentType 'application/json' $Result.PSObject.TypeNames.Insert(0, 'NmeResponseWithJob') $Result | Add-Member -NotePropertyName 'id' -NotePropertyValue $id -erroraction 'SilentlyContinue' $Result | CapProps } Catch { $message = ParseErrorForResponseBody($_) write-error ($message | out-string) } } Function Get-NmeUserCostAttributionConfiguration { <# .SYNOPSIS Get configuration. .DESCRIPTION Get configuration. This function calls the /api/v1/user-cost-attribution/configuration/{id} endpoint of the NME REST API, using the get method. .PARAMETER Id ID of scripted Action #> [CmdletBinding()] Param( [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$Id ) Set-NmeAuthHeaders Try { $Result = Invoke-RestMethod "$script:NmeUri/api/v1/user-cost-attribution/configuration/$Id$Querystring" -Method get -Headers $script:AuthHeaders -ContentType 'application/json' $Result.PSObject.TypeNames.Insert(0, 'NmeUserCostAttributionConfigurationModel') $Result | Add-Member -NotePropertyName 'id' -NotePropertyValue $id -erroraction 'SilentlyContinue' $Result | CapProps } Catch { $message = ParseErrorForResponseBody($_) write-error ($message | out-string) } } Function Set-NmeUserCostAttributionConfiguration { <# .SYNOPSIS Partially update configuration. .DESCRIPTION Partially update configuration. This function calls the /api/v1/user-cost-attribution/configuration/{id} endpoint of the NME REST API, using the patch method. .PARAMETER Id ID of scripted Action .PARAMETER NmeUserCostAttributionConfigurationPatchModel Requires an NmeUserCostAttributionConfigurationPatchModel object, as generated by the New-NmeUserCostAttributionConfigurationPatchModel command. #> [CmdletBinding()] Param( [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$Id, [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$True)][ValidateScript({if ($_.PSObject.TypeNames -contains "NmeUserCostAttributionConfigurationPatchModel"){$true} else{throw " is not a NmeUserCostAttributionConfigurationPatchModel object."}})]$NmeUserCostAttributionConfigurationPatchModel ) Set-NmeAuthHeaders Try { $json = $NmeUserCostAttributionConfigurationPatchModel | ConvertTo-Json -Depth 20 Write-Debug 'json:' Write-Debug $json $Result = Invoke-RestMethod "$script:NmeUri/api/v1/user-cost-attribution/configuration/$Id$QueryString" -Method patch -Headers $script:AuthHeaders -ContentType 'application/json' -body $json Write-Verbose ($result | out-string) $Result.PSObject.TypeNames.Insert(0, 'NmeResponseWithJobAndUserCostAttributionConfigurationModel') $Result | Add-Member -NotePropertyName 'id' -NotePropertyValue $id -erroraction 'SilentlyContinue' $Result | CapProps } Catch { $message = ParseErrorForResponseBody($_) write-error ($message | out-string) } } Function Get-NmeUserCostAttributionConfiguration { <# .SYNOPSIS List configurations. .DESCRIPTION List configurations. This function calls the /api/v1/user-cost-attribution/configuration endpoint of the NME REST API, using the get method. #> [CmdletBinding()] Param( ) Set-NmeAuthHeaders Try { $Result = Invoke-RestMethod "$script:NmeUri/api/v1/user-cost-attribution/configuration$Querystring" -Method get -Headers $script:AuthHeaders -ContentType 'application/json' $Result.PSObject.TypeNames.Insert(0, 'NmeUserCostAttributionConfigurationModel') $Result | CapProps } Catch { $message = ParseErrorForResponseBody($_) write-error ($message | out-string) } } Function New-NmeUserCostAttributionConfiguration { <# .SYNOPSIS Create configuration. .DESCRIPTION Create configuration. This function calls the /api/v1/user-cost-attribution/configuration endpoint of the NME REST API, using the post method. .PARAMETER NmeUserCostAttributionConfigurationCreateModel Requires an NmeUserCostAttributionConfigurationCreateModel object, as generated by the New-NmeUserCostAttributionConfigurationCreateModel command. #> [CmdletBinding()] Param( [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$True)][ValidateScript({if ($_.PSObject.TypeNames -contains "NmeUserCostAttributionConfigurationCreateModel"){$true} else{throw " is not a NmeUserCostAttributionConfigurationCreateModel object."}})]$NmeUserCostAttributionConfigurationCreateModel ) Set-NmeAuthHeaders Try { $json = $NmeUserCostAttributionConfigurationCreateModel | ConvertTo-Json -Depth 20 Write-Debug 'json:' Write-Debug $json $Result = Invoke-RestMethod "$script:NmeUri/api/v1/user-cost-attribution/configuration$QueryString" -Method post -Headers $script:AuthHeaders -ContentType 'application/json' -body $json Write-Verbose ($result | out-string) $Result.PSObject.TypeNames.Insert(0, 'NmeResponseWithJobAndUserCostAttributionConfigurationModel') $Result | CapProps } Catch { $message = ParseErrorForResponseBody($_) write-error ($message | out-string) } } Function Get-NmeUserCostAttributionReport { <# .SYNOPSIS Get report status and result if available. .DESCRIPTION Get report status and result if available. This function calls the /api/v1/user-cost-attribution/configuration/{id}/report/{year}/{month} endpoint of the NME REST API, using the get method. .PARAMETER Id ID of scripted Action .PARAMETER Year The year for the report .PARAMETER Month The month for the report .PARAMETER ReportType Uniform, Proportional, or Unallocated #> [CmdletBinding()] Param( [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][ValidatePattern('(\{|\()?[A-Za-z0-9]{4}([A-Za-z0-9]{4}\-?){4}[A-Za-z0-9]{12}(\}|\()?')][string]$Id, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][int]$Year, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][int]$Month, [Parameter(ValueFromPipelineByPropertyName=$true)][ValidateSet("Uniform", "Proportional", "Unallocated")][string]$ReportType ) Set-NmeAuthHeaders Try { $QueryString = '?' $QueryStrings = @{} $QueryStrings += @{reportType= $reportType} $QueryString += ($QueryStrings.GetEnumerator() | % { "$($_.Key)=$($_.Value)" }) -join '&' $Result = Invoke-RestMethod "$script:NmeUri/api/v1/user-cost-attribution/configuration/$Id/report/$Year/$Month$Querystring" -Method get -Headers $script:AuthHeaders -ContentType 'application/json' $Result.PSObject.TypeNames.Insert(0, 'NmeUserCostAttributionReportResponse') $Result | Add-Member -NotePropertyName 'id' -NotePropertyValue $id -erroraction 'SilentlyContinue' $Result | Add-Member -NotePropertyName 'year' -NotePropertyValue $year -erroraction 'SilentlyContinue' $Result | Add-Member -NotePropertyName 'month' -NotePropertyValue $month -erroraction 'SilentlyContinue' $Result | CapProps } Catch { $message = ParseErrorForResponseBody($_) write-error ($message | out-string) } } Function New-NmeUserCostAttributionReport { <# .SYNOPSIS Create report. .DESCRIPTION Create report. This function calls the /api/v1/user-cost-attribution/configuration/{id}/report/{year}/{month} endpoint of the NME REST API, using the post method. .PARAMETER Id ID of scripted Action .PARAMETER Year The year for the report .PARAMETER Month The month for the report #> [CmdletBinding()] Param( [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][ValidatePattern('(\{|\()?[A-Za-z0-9]{4}([A-Za-z0-9]{4}\-?){4}[A-Za-z0-9]{12}(\}|\()?')][string]$Id, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][int]$Year, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][int]$Month ) Set-NmeAuthHeaders Try { $Result = Invoke-RestMethod "$script:NmeUri/api/v1/user-cost-attribution/configuration/$Id/report/$Year/$Month$Querystring" -Method post -Headers $script:AuthHeaders -ContentType 'application/json' $Result.PSObject.TypeNames.Insert(0, 'NmeResponseWithJob') $Result | Add-Member -NotePropertyName 'id' -NotePropertyValue $id -erroraction 'SilentlyContinue' $Result | Add-Member -NotePropertyName 'year' -NotePropertyValue $year -erroraction 'SilentlyContinue' $Result | Add-Member -NotePropertyName 'month' -NotePropertyValue $month -erroraction 'SilentlyContinue' $Result | CapProps } Catch { $message = ParseErrorForResponseBody($_) write-error ($message | out-string) } } Function Get-NmeUserCostAttributionReportExport { <# .SYNOPSIS Export report (csv). .DESCRIPTION Export report (csv). This function calls the /api/v1/user-cost-attribution/configuration/{id}/report/{year}/{month}/export endpoint of the NME REST API, using the get method. .PARAMETER Id ID of scripted Action .PARAMETER Year The year for the report .PARAMETER Month The month for the report .PARAMETER ReportType Uniform, Proportional, or Unallocated .PARAMETER ExportType UserCostDetail, ResourceCostDetail, or ResourceCostSummary #> [CmdletBinding()] Param( [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][ValidatePattern('(\{|\()?[A-Za-z0-9]{4}([A-Za-z0-9]{4}\-?){4}[A-Za-z0-9]{12}(\}|\()?')][string]$Id, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][int]$Year, [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][int]$Month, [Parameter(ValueFromPipelineByPropertyName=$true)][ValidateSet("Uniform", "Proportional", "Unallocated")][string]$ReportType, [Parameter(ValueFromPipelineByPropertyName=$true)][ValidateSet("UserCostDetail", "ResourceCostDetail", "ResourceCostSummary")][string]$ExportType ) Set-NmeAuthHeaders Try { $QueryString = '?' $QueryStrings = @{} $QueryStrings += @{reportType= $reportType} $QueryStrings += @{exportType= $exportType} $QueryString += ($QueryStrings.GetEnumerator() | % { "$($_.Key)=$($_.Value)" }) -join '&' $Result = Invoke-RestMethod "$script:NmeUri/api/v1/user-cost-attribution/configuration/$Id/report/$Year/$Month/export$Querystring" -Method get -Headers $script:AuthHeaders -ContentType 'application/json' $Result | CapProps } Catch { $message = ParseErrorForResponseBody($_) write-error ($message | out-string) } } |