Project

General

Profile

Rest api with powershell » History » Version 2

Seung Soo Mun, 2019-02-22 12:41

1 1 Seung Soo Mun
h1. Using the REST API with Powershell
2
3
h2. *Powershell*:
4
5
<pre>
6
$Cred = Get-Credential
7
8
Invoke-RestMethod http://demo.redmine.org/issues/12345.json -Credential $Cred
9
Invoke-RestMethod http://demo.redmine.org/projects/12.json -Credential $Cred
10
Invoke-RestMethod http://demo.redmine.org/versions/123.json -Credential $Cred
11
12
(Invoke-RestMethod http://demo.redmine.org/issues.json -Credential $Cred).issues
13
(Invoke-RestMethod http://demo.redmine.org/projects.json -Credential $Cred).projects
14
(Invoke-RestMethod http://demo.redmine.org/projects/12/versions.json -Credential $Cred).versions
15
16
Invoke-RestMethod http://demo.redmine.org/projects/12.json -Credential $Cred -Method PUT -ContentType 'application/json' -Body '{"project": {"default_version_id": "398"}}'
17
Invoke-RestMethod http://demo.redmine.org/projects/testproject.json -Credential $Cred -Method PUT -ContentType 'application/json' -Body '{"project": {"default_version_id": "398"}}'
18 2 Seung Soo Mun
19
Invoke-RestMethod http://demo.redmine.org/projects/12/versions.json -Credential $Cred -Method POST -ContentType 'application/json' -Body '{"version": {"name": "Test ver", "description": "Test version desc"}}'
20
Invoke-RestMethod http://demo.redmine.org/issues.json -Credential $Cred -Method POST -ContentType 'application/json' -Body '{"issue": {"project_id": 438, "subject": "test watchers", "watcher_user_ids": [7,11,110]}}'
21 1 Seung Soo Mun
</pre>
22
23
h2. *PSRedmine*:
24
25
https://github.com/hamletmun/PSRedmine
26
27
<pre>
28
Connect-Redmine demo.redmine.org
29
30
New-RedmineResource project -identifier test99 -name testproject
31
New-RedmineResource version -project_id 475 -name testversion
32
New-RedmineResource issue -project_id test99 -subject testissue
33
34
Search-RedmineResource project -keyword testproject
35
Search-RedmineResource membership -project_id test99
36
Search-RedmineResource version -project_id test99 -keyword testversion 
37
Search-RedmineResource issue -keyword testissue
38
Search-RedmineResource user -keyword testuser # Administrator only
39
40
Get-RedmineResource project test99
41
Get-RedmineResource project 475
42
Get-RedmineResource membership 74
43
Get-RedmineResource version 408
44
Get-RedmineResource issue 29552
45
Get-RedmineResource user 20 # Administrator only
46
47
Edit-RedmineResource project -id test99 -description 'change description'
48
Edit-RedmineResource version -id 408 -description 'add desc' -due_date 2018-09-29
49
Edit-RedmineResource issue -id 29552 -version_id 406
50
51
Remove-RedmineResource issue 29552
52
Remove-RedmineResource version 408
53
Remove-RedmineResource project test99 # Administrator only
54
Remove-RedmineResource user 20 # Administrator only
55
56
Disconnect-Redmine
57
</pre>