Jump to content
Welcome to our new Citrix community!
  • 1

Citrix Cloud REST API - Machine Maintenance Mode


Paul Whiston

Question

Trying to place a multi-session machine into maintenance mode using a REST API. 

 

$response = Invoke-WebRequest "https://api.cloud.com/cvadapis/<siteID>/Machines/<MachineID>" -Headers $headers -Method PATCH -Body @{InMaintenanceMode = "true"} -ContentType "application/json"

 

Any guidance on if this is possible and if so, what code i should be using?

 

thanks.

Link to comment

3 answers to this question

Recommended Posts

  • 2

You're on the right track - you just need to JSON-encode the payload. Note that a successful PATCH request returns an empty HTTP response with status code 204.

PS /Users/pat/Documents> $response = Invoke-WebRequest "https://api.cloud.com/cvadapis/$siteId/Machines/$machineId" `
    -Headers $headers `
    -Method PATCH `
    -Body (@{InMaintenanceMode = "true"} | ConvertTo-Json) `
    -ContentType "application/json"
PS /Users/pat/Documents> $response

StatusCode        : 204
StatusDescription : NoContent
Content           : {}
RawContent        : HTTP/1.1 204 NoContent
                    Cache-Control: no-store, must-revalidate, no-cache
                    Pragma: no-cache
                    Vary: Accept-Encoding
                    Citrix-TransactionId: abf03693-862f-4555-baaa-2a9dfc2dcb76
                    X-Content-Type-Options: nosn…
Headers           : {[Cache-Control, System.String[]], [Pragma, System.String[]], [Vary, System.String[]], [Citrix-TransactionId, System.String[]]…}
RawContentLength  : 0
RelationLink      : {}


PS /Users/pat/Documents> $response = Invoke-WebRequest "https://api.cloud.com/cvadapis/$siteId/Machines/$machineId" `
    -Headers $headers
PS /Users/pat/Documents> ($response | ConvertFrom-Json).InMaintenanceMode
True
PS /Users/pat/Documents> $response = Invoke-WebRequest "https://api.cloud.com/cvadapis/$siteId/Machines/$machineId" `
    -Headers $headers `
    -Method PATCH `
    -Body (@{InMaintenanceMode = "false"} | ConvertTo-Json) `
    -ContentType "application/json"
PS /Users/pat/Documents> $response

StatusCode        : 204                                                                                                           StatusDescription : NoContent
Content           : {}
RawContent        : HTTP/1.1 204 NoContent
                    Cache-Control: no-store, must-revalidate, no-cache
                    Pragma: no-cache
                    Vary: Accept-Encoding
                    Citrix-TransactionId: 1809f653-19a1-4855-a19e-782866962cbd
                    X-Content-Type-Options: nosn…
Headers           : {[Cache-Control, System.String[]], [Pragma, System.String[]], [Vary, System.String[]], [Citrix-TransactionId, System.String[]]…}
RawContentLength  : 0
RelationLink      : {}


PS /Users/pat/Documents> $response = Invoke-WebRequest "https://api.cloud.com/cvadapis/$siteId/Machines/$machineId" `
    -Headers $headers
PS /Users/pat/Documents> ($response | ConvertFrom-Json).InMaintenanceMode
False

 

  • Like 3
Link to comment
  • 0

Any idea how I could search for all machines in maintenance mode.     I tried to use the search I found from this post  https://developer.cloud.com/citrixworkspace/virtual-apps-and-desktops/cvad-rest-apis/docs/how-to-perform-an-advanced-search-for-machines  using a search in body 
 

$body = @{
    "SearchFilters" = @([ordered]@{
        
            Property= "InMaintenanceMode"
            Value= "True"
            Operator= "Equals"
         })
         }|ConvertTo-Json

 

but I'm getting an error:

Cannot send a content-body with this verb-type.

Thanks

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...