barrycarey / SnipeSharp

A c# wrapper for the Snipe IT API
25 stars 30 forks source link

Creating license from API #21

Open kovrobert opened 5 years ago

kovrobert commented 5 years ago

Dear Developer,

please create an update on the project. Especially on the licensemanager. In the license class the category field does not exist but in the snipeit. This will lead to an error if you try to create a license.

Is that possible that you will update all the endpoint models? It would be great.

Thank You: Robi

gnh1201 commented 4 years ago

Unfortunately, I modified SnipeSharp's JsonProperty but couldn't solve this problem. So I implemented it myself using RestSharp and succeeded in creating it.

var client = new RestClient(ApiUrl);
var request = new RestRequest("/licenses", Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddHeader("Accept", "application/json");
request.AddParameter("name", software.DisplayName);
request.AddParameter("seats", 1);
request.AddParameter("category_id", 1);
if(manufacturer != null) {
    request.AddParameter("manufacturer_id", manufacturer.Id);
}
if (company != null)
{
    request.AddParameter("company_id", company.Id);
}
client.AddDefaultHeader("Authorization", string.Format("Bearer {0}", AccessToken));
client.Execute(request);
gnh1201 commented 4 years ago

https://github.com/gnh1201/SnipeITWindowsAgentPOC