REST APIで新規チケット登録するときにカスタムフィールドに値を入れたい

1,070 views
Skip to first unread message

keigo kikuchi

unread,
Jun 9, 2020, 8:43:01 PM6/9/20
to Redmine Users (japanese)
こんにちは。

Excel VBAを使い、REST APIで新規チケット登録をしようとしています。
タイトルだけ指定した場合は問題なく登録できますが、カスタムフィールドに値を入れようとすると「400」というエラーが出てしまいます。

下記のようなプログラムを書きました。
「ここからカスタムフィールド」と「ここまでカスタムフィールド」の間のコードをコメントアウトすると正常にチケットが登録されます。
しかし、コメントアウトを解除すると「400」というエラーが出てチケットが登録できません。

カスタムフィールドに値を入れる場合はなにか作法があるのでしょうか?

ption Explicit Public Const REDMINE_URL As String = "https://'URL'" Public Sub Test1() Dim requestStatus As String requestStatus = addIssue( _ "'APIキー'", _ "追加テスト") MsgBox requestStatus End Sub Public Function addIssue( _ ByVal apiKey As String, _ ByVal subject As String) As String Dim sendBody As Variant sendBody = "<?xml version=""1.0""?><issue>" sendBody = sendBody & "<project_id>9</project_id>" sendBody = sendBody & "<subject>" & subject & "</subject>" 'ここからカスタムフィールド sendBody = sendBody & "<custom_fields type=array>" sendBody = sendBody & "<custom_field id=""85"">" sendBody = sendBody & "<value>5</value>" sendBody = sendBody & "</custom_field>" sendBody = sendBody & "</custom_fields>" 'ここまでカスタムフィールド sendBody = sendBody & "</issue>" Dim xmlHttp As New MSXML2.XMLHTTP60 With xmlHttp .Open "POST", REDMINE_URL & "issues.xml?format=xml&?key=" & apiKey, False .SetRequestHeader "Content-Type", "text/xml" .Send sendBody addIssue = CStr(.Status) End With Set xmlHttp = Nothing End Function

よろしくお願いします。

吉澤拓成

unread,
Jun 11, 2020, 7:25:34 AM6/11/20
to Redmine Users (japanese)
kikuchi様

ぱっと見で勘違いだっったらごめんなさい

"<custom_fields type=array>"
のところで、 type="array" になるようにするのかもと思いましたがどうでしょうか?


2020年6月10日水曜日 9時43分01秒 UTC+9 keigo kikuchi:
Message has been deleted

keigo kikuchi

unread,
Jun 11, 2020, 8:51:24 PM6/11/20
to Redmine Users (japanese)
吉澤様

こんにちは。
ご回答ありがとうございます。

ご指摘の通りでした!!
ご指摘の通り修正したところ、無事に登録できました。

ありがとうございました。

2020年6月11日木曜日 20時25分34秒 UTC+9 吉澤拓成:
Reply all
Reply to author
Forward
0 new messages