Rest api with csharp » History » Version 6
Maxim Okunev, 2024-08-19 21:56
1 | 1 | Dorin Huzum | h1. Using the REST API with .NET |
---|---|---|---|
2 | |||
3 | "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 | |||
5 | 4 | Seung Soo Mun | To use this library from PowerShell, see [[REST API with PowerShell]] |
6 | |||
7 | 1 | Dorin Huzum | Sample usage: |
8 | 2 | Dorin Huzum | |
9 | <pre> |
||
10 | using System; |
||
11 | using System.Collections.Specialized; |
||
12 | using Redmine.Net.Api; |
||
13 | using Redmine.Net.Api.Types; |
||
14 | |||
15 | namespace RedmineTest |
||
16 | { |
||
17 | class Program |
||
18 | { |
||
19 | static void Main(string[] args) |
||
20 | { |
||
21 | string host = ""; |
||
22 | string apiKey = ""; |
||
23 | 5 | Maxim Okunev | string issueId = "<issue-id>"; |
24 | 2 | Dorin Huzum | |
25 | var manager = new RedmineManager(host, apiKey); |
||
26 | 1 | Dorin Huzum | |
27 | 5 | Maxim Okunev | //parameter - fetch associated relations. |
28 | var parameters = new NameValueCollection {{RedmineKeys.INCLUDE, RedmineKeys.RELATIONS}}; |
||
29 | |||
30 | var issue = manager.GetObject<Issue>(issueId, parameters); |
||
31 | Console.WriteLine("Issue: {0}.", issue); |
||
32 | 1 | Dorin Huzum | |
33 | //Create a issue. |
||
34 | 5 | Maxim Okunev | Issue newissue = new Issue(); |
35 | newissue.Project = IdentifiableName.Create<IdentifiableName>(id: 1); |
||
36 | newissue.Tracker = IdentifiableName.Create<IdentifiableName>(id: 1); |
||
37 | newissue.Subject = "Example"; |
||
38 | newissue.Description = "Description"; |
||
39 | |||
40 | Issue savedIssue = manager.CreateObject(newissue); |
||
41 | 6 | Maxim Okunev | Console.WriteLine("Saved issue {0}." ,savedIssue); |
42 | 2 | Dorin Huzum | |
43 | } |
||
44 | } |
||
45 | } |
||
46 | </pre> |