Chef API with C#

Hello! I was not able to get enough information about setting up API calls from the chef-server API page on the docs (https://docs.chef.io/api_chef_server.html). Where can I find pointers on how to access the Chef API from outside, especially C#?

I’m not certain how much the API has changed in the last two years but you may find this repository to be a good example to work from https://github.com/mattberther/dotnet-chef-api

1 Like

Beyond the docs, I’d suggest going to the code, since it’s all open source. There are several things that might help you here. The guts of the Chef server are in oc_erchef, the erlang code that powers most of it. That’s here: https://github.com/chef/chef-server/tree/master/src/oc_erchef

Tucked into that source code you’ll find RAML (http://raml.org/) documentation that documents a lot of the API and might be of use: https://github.com/chef/chef-server/tree/master/src/oc_erchef/raml-docs.

There are also the pedant tests: https://github.com/chef/chef-server/tree/master/oc-chef-pedant. These are basically an rspec integration test suite of the Chef server. They can sometimes be cryptic, but they are the absolute best source for learning how the Chef server works, short of reading all the code. In there is code that setup up API calls.

In addition, I know there are a number of ruby gems that make calls agains the Chef server API, so you could find one and observer what it’s doing, or even inspect how Chef itself is making API calls to the Chef server.

Hope that helps. I realize it doesn’t answer your question directly but should give you pointers to determine the answer. Ultimately it’s just an http request, so it’s just a matter of getting the headers and payload correct.

1 Like