Description

As of Chocolatey Central Management v0.4.0, the API is exposed via Swagger. The API documentation and examples can be reached from your Chocolatey Central Management dashboard by selecting the API option on the left sidebar. The information contained there is referenced here, but you can additionally try out the various API endpoints directly from the Swagger API page for your own CCM environment.

WARNING

The Swagger UI does not work in Internet Explorer. Please use another browser.

Authentication

Before being able to utilise the Chocolatey Central Management API, you will need to create an authenticated session. This can be done by targeting the /Account/Login endpoint and submitting the username and password. You will need to use the authenticated session variable for any API calls.

# Replace 'chocoserver' with the hostname of your CCM server in your environment
$CcmServerHostname = 'chocoserver'
$Credential = Get-Credential ccmadmin

$LoginArguments = @{
    Uri = "https://$CcmServerHostname/Account/Login"
    Method = "POST"
    Body = @{
        usernameOrEmailAddress = $Credential.UserName
        password = $Credential.GetNetworkCredential().Password
    }
    ContentType = "application/x-www-form-urlencoded"
    SessionVariable = "Session"
    UseBasicParsing = $true
}

$null = Invoke-WebRequest @LoginArguments

While authenticated, you can target API endpoints like this (using Computers/GetAll as the example):

Invoke-RestMethod -Uri "https://$CcmServerHostname/api/services/app/Computers/GetAll" -WebSession $Session -UseBasicParsing

Endpoints

For detailed and accurate information on the API endpoints and their parameters for your version of Chocolatey Central Management, select the API option from the sidebar on the Chocolatey Central Management dashboard, or navigate to https://CCM_SERVER_HOSTNAME/swagger/.