Skip to content

Commit a6a734b

Browse files
committed
[Tips] REST APIによるIssue作成のTips追加(親子まとめて実施する方法も)
1 parent 0f658a6 commit a6a734b

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

tips/tips.md

+83
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,89 @@ $('#all_attributes').on('change', target, function() {
6161
});
6262
```
6363

64+
## Using the REST API to create an issue
65+
66+
By using the Redmine REST API, you can create an issue.
67+
68+
* [Rest Issues \- Redmine](https://www.redmine.org/projects/redmine/wiki/Rest_Issues)
69+
70+
```javascript
71+
const issue = {
72+
'issue': {
73+
'project_id': 1,
74+
'tracker_id': 1,
75+
'subject': 'XYZ: ' + new Date().toISOString()
76+
}
77+
};
78+
79+
$.ajax({
80+
type: 'POST',
81+
url: '/issues.json',
82+
headers: {
83+
'X-Redmine-API-Key': ViewCustomize.context.user.apiKey
84+
},
85+
dataType: 'json',
86+
contentType: 'application/json',
87+
data: JSON.stringify(issue)
88+
})
89+
.done(function(response) {
90+
alert('Succeed. issue Id: ' + response.issue.id);
91+
})
92+
.fail(function() {
93+
alert('Failed.');
94+
});
95+
```
96+
97+
When creating parents and children together, do the following.
98+
99+
```javascript
100+
const parentIssue = {
101+
'issue': {
102+
'project_id': 1,
103+
'tracker_id': 1,
104+
'subject': 'Parent: ' + new Date().toISOString()
105+
}
106+
};
107+
108+
const childIssue = {
109+
'issue': {
110+
'project_id': 1,
111+
'tracker_id': 1,
112+
'subject': 'Child: ' + new Date().toISOString()
113+
}
114+
};
115+
116+
$.ajax({
117+
type: 'POST',
118+
url: '/issues.json',
119+
headers: {
120+
'X-Redmine-API-Key': ViewCustomize.context.user.apiKey
121+
},
122+
dataType: 'json',
123+
contentType: 'application/json',
124+
data: JSON.stringify(parentIssue)
125+
})
126+
.then(function(response) {
127+
childIssue.issue.parent_issue_id = response.issue.id;
128+
return $.ajax({
129+
type: 'POST',
130+
url: '/issues.json',
131+
headers: {
132+
'X-Redmine-API-Key': ViewCustomize.context.user.apiKey
133+
},
134+
dataType: 'json',
135+
contentType: 'application/json',
136+
data: JSON.stringify(childIssue)
137+
});
138+
})
139+
.done(function(response) {
140+
alert('Succeed. parent issue Id: ' + response.issue.parent.id + ', child issue Id: ' + response.issue.id);
141+
})
142+
.fail(function() {
143+
alert('Failed.');
144+
});
145+
```
146+
64147
## Using the REST API to fetch issue
65148

66149
By using Redmine REST API, you can get information about issues that are not displayed on the screen.

0 commit comments

Comments
 (0)