< Back

Invoke-CBRestMethod

Mon Jan 13, 2020 3:27 am

NAME Invoke-CBRestMethod



SYNOPSIS

Calls a method in the CloudBolt REST API.





SYNTAX

Invoke-CBRestMethod -Session <Object> -Method {Default | Get | Head | Post | Put | Delete | Trace | Options |

Merge | Patch} -ResourcePath <String> [-Body <String>] [-WhatIf] [-Confirm] [<CommonParameters>]



Invoke-CBRestMethod -Session <Object> -Method {Default | Get | Head | Post | Put | Delete | Trace | Options |

Merge | Patch} -ResourcePath <String> -IsPaged [-PageSize <Int32>] [-WhatIf] [-Confirm] [<CommonParameters>]





DESCRIPTION

The `Invoke-CBRestMethod` function calls a method in the CloudBolt REST API. Pass a session/connection object to

the `Session` parameter (use `New-CBSession` to create a session object), the HTTP method to use to the `Method`

parameter, the relative path to the endpoint to the `ResourcePath` parameter (i.e. everything after `api/v2/` in

the endpoint's path), and the body of the request (if any) to the `Body` parameter. A result object is returned,

which is different for each endpoint.



Any endpoint that returns a list of objects is paged. Use the `IsPaged` parameter to tell `Invoke-CBRestMethod`

that the results are paged and to page through and return all objects. For each page of results, this function

will call the API to return that page. You can control how big the page size is with the `PageSize` parameter. The

default is `10`. The maximum value is `100`. If you pass a value bigger than `100`, CloudBolt will still only

return 100 results per page.





PARAMETERS

-Session <Object>

The session/connecton to the CloudBolt instance to use. Use `New-CBSession` to create a session object.



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Method

The HTTP method to use for the request.



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-ResourcePath <String>

The relative path to the endpoint to request. This is the part of the URI after `api/v2/`. It usually needs to

end with a `/`.



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Body <String>

The body of the request.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-IsPaged [<SwitchParameter>]

Is the API endpoint paged or not? If this switch is `true`, the `Invoke-CBRestMethod` function will treat the

results as paged and will make a web request for each page of results and return all objects. Use the

`PageSize` function to control how many results to return in each page (i.e. to increase or decrease the

number of HTTP requests to make).



Required? true

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-PageSize <Int32>

How many results to return in each page. The default is `10`. The maximum value is `100`. If you pass a value

greater than `100`, CloudBolt will still only return `100` results per page.



Required? false

Position? named

Default value $defaultPageSize

Accept pipeline input? false

Accept wildcard characters? false



-WhatIf [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Confirm [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Invoke-CBRestMethod -Session $Session -Method Get -ResourcePath ('orders/{0}/' -f $ID)



Demonstrates how to use `Invoke-CBRestMethod` to call an endpoint that returns a single object. In this case, a

specific order.









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Invoke-CBRestMethod -Session $Session -Method Get -ResourcePath 'groups/' -IsPaged -PageSize 100



Demonstrates how to use `Invoke-CBRestMethod` to call a paged/list endpoint. In this case, `Invoke-CBRestMethod`

will return all groups in CloudBolt. It will make a request for each page of results so that all groups are

returned.











RELATED LINKS