@@ -61,6 +61,89 @@ $('#all_attributes').on('change', target, function() {
61
61
});
62
62
```
63
63
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
+
64
147
## Using the REST API to fetch issue
65
148
66
149
By using Redmine REST API, you can get information about issues that are not displayed on the screen.
0 commit comments