Accessing portions of your ConfigMgr database via a webAPI can really open some doors for some pretty spectacular solutions and of course some nifty automation. Most of the automation “low hanging fruit” for WebAPI usage is during OSD. You can do things like combine data from an asset management system and the CM database to do things like name the device, select appropriate applications, place the device in a proper OU, validate it is corporate owned, etc etc… if you can think it up and you have the data available to you, you should be able to right the logic into your web API.
When creating a web API, be sure to consider the tooling before you get too deep. For the example webAPI I created I choose to a RESTful WebAPI using ASP .NET Core. For the actual coding environment I used Visual Studio Code.
Why ASP Net Core vs Full .NET?
The functionality I needed (essentially to read from a database) was available in .NET core. No need for the full .NET 4.x.x client. NET Core is open source and Operating System independent, it can run on Linux, Mac and Windows (i.e. hosted anywhere). The project is actively maintained by the community. It is very Azure friendly and in a cloud first, automation first world, this is a very good thing.
.Net Core is NOT fully featured compared to the full .NET client. An example of this is the lack of Directory Services support (Active Directory). It is coming though. Do your homework before you get too far down the .NET core route and find out something important isn’t available.
Why VS Code vs. Visual Studio Express
I was doing dev work on many VMs across many domains. It was far simpler to install and manage a 90MB VS Code installation vs. an 8GB full blown Visual Studio deployment. Also, I am not sure what features Visual Studio has that VS Code is missing that I would actually use. Including a full debugger and source control integration. After using VS Code for a while, I simply enjoy using it more than Visual Studio. It seems more intuitive with a far less noisy UI and a new release seems to come out weekly with nice enhancements.
You can still do full .NET client development in VS Code, it works fine, you just can’t debug a project in VS Code that runs on a full .NET Framework like 4.6.1, etc.
Things you want to know before starting a new webAPI project.
Here are some great walkthrough on creating your first web API.
How to use source control. I prefer GIT, but it doesn’t matter. You need a source control solution. This book was all I needed to get sharp enough with GIT. Expert level source control is not required for success. But a basic understanding of source control is.
The service account you will be using to access your data. Be sure it has the least amount of privilege necessary to execute its purpose. For ConfigMgr, granting the service account the db_reader role on the database is a good start. Especially with ConfigMgr, because modifying the database directly isn’t support anyway so don’t get yourself in a situation where you allow your service account to do it.
Next Up – a working WebAPI Example