FredBainbridge

Implementing a Sample ConfigMgr Web API

The following steps get you a working WebAPI that can show data retrieved from a ConfigMgr database. The project is hosted at https://github.com/fredbainbridge/CMWebAPI.

Prerequisites:

You need remote TCP Connectivity to the ConfigMgr database. (probably port 1433 )

Implementing a simple yet awesome ConfigMgr Web API.

Clone the repository

From PowerShell or commadn prompt run:

git clone https://github.com/fredbainbridge/CMWebAPI

This will create a folder named CMWebAPI containing all the source code.

Open the folder in VS Code. Let the C# extension do it’s thing for a moment. The extension will configure itself whenever it finds an appsettings.json in the folder.

Open AppSettings.json and change the Database connection string to match your environment.

Press F5 to start the debugger! Your new shiny ConfigMgr webAPI is now live.

Tester / Example PowerShell Script

[CmdletBinding()]
param (
    [string]$apiURL,
    [string]$DP,
    [string]$AppName
)

if($AppName -ne $null)
{
    $url = "$apiURL/dpjson/$($DP)?appname=$AppName"
}

else 
{
    $url =  "$apiURL/dpjson/$($DP)"  
}

Write-Verbose $url
Write-Output (Invoke-WebRequest -uri $url | ConvertFrom-Json)

Example URLs

All Applications.

http://localhost:5000/cmapplication

All Applications on a DP with 01 in it’s hostname. http://localhost:5000/cmapplication/dp/01

All Applications on Specific DP (JSON)

http://localhost:5000/cmapplication/name/mic

Applications with “mic” in name on specific DP.

http://localhost:5000/cmapplication/dp/01?appName=mic

Application with “mic” in name on specific DP (JSON).

http://localhost:5000/cmapplication/dpjson/01?appName=mic

 

JSON Output

 

Non-JSON output

 

Happy automating. 🙂


Share