Rest api with csharp » History » Version 3

Guriy Samarin, 2019-12-11 13:00

1 1 Dorin Huzum
h1. Using the REST API with .NET
2 1 Dorin Huzum
3 1 Dorin Huzum
"Redmine .NET API library":https://code.google.com/p/redmine-net-api is a FREE third-party C# library that can be used to access the Redmine API. It is released under Apache 2 open-source license.
4 1 Dorin Huzum
5 1 Dorin Huzum
Sample usage:
6 2 Dorin Huzum
7 2 Dorin Huzum
<pre>
8 2 Dorin Huzum
using System;
9 2 Dorin Huzum
using System.Collections.Specialized;
10 2 Dorin Huzum
using Redmine.Net.Api;
11 2 Dorin Huzum
using Redmine.Net.Api.Types;
12 2 Dorin Huzum
13 2 Dorin Huzum
namespace RedmineTest
14 2 Dorin Huzum
{
15 2 Dorin Huzum
    class Program
16 2 Dorin Huzum
    {
17 2 Dorin Huzum
        static void Main(string[] args)
18 2 Dorin Huzum
        {
19 2 Dorin Huzum
            string host = "";
20 2 Dorin Huzum
            string apiKey = "";
21 2 Dorin Huzum
22 2 Dorin Huzum
            var manager = new RedmineManager(host, apiKey);
23 2 Dorin Huzum
24 2 Dorin Huzum
            var parameters = new NameValueCollection {{"status_id", "*"}};
25 3 Guriy Samarin
            foreach (var issue in manager.GetObjects<Issue>(parameters))
26 2 Dorin Huzum
            {
27 2 Dorin Huzum
                Console.WriteLine("#{0}: {1}", issue.Id, issue.Subject);
28 2 Dorin Huzum
            }
29 2 Dorin Huzum
30 2 Dorin Huzum
            //Create a issue.
31 2 Dorin Huzum
            var newIssue = new Issue { Subject = "test", Project = new IdentifiableName{Id =  1}};
32 2 Dorin Huzum
            manager.CreateObject(newIssue);
33 2 Dorin Huzum
34 2 Dorin Huzum
        }
35 2 Dorin Huzum
    }
36 2 Dorin Huzum
}
37 2 Dorin Huzum
</pre>