質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Redmine

Redmineは、プロジェクトのタスク管理、進捗管理、情報共有が可能な、 オープンソースプロジェクト管理ソフトウェアです。

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

Q&A

解決済

2回答

1766閲覧

Redmine:ニュースのAPI登録可否について

a-syuji

総合スコア16

Redmine

Redmineは、プロジェクトのタスク管理、進捗管理、情報共有が可能な、 オープンソースプロジェクト管理ソフトウェアです。

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

0グッド

0クリップ

投稿2019/10/23 17:58

編集2019/10/23 23:13

前提・実現したいこと

APIでニュースを登録することは可能でしょうか。
(下記のURLを見るとGETメソッドしか実装されていないようにも見える。)
https://www.redmine.org/projects/redmine/wiki/Rest_News

発生している問題・エラーメッセージ

curl -XPOST http://localhost/redmine/news.json?key=xxxxx -d '{ "news": { "project_id": "1", "author_id": "6", "title": "test", "summary": "", "description": "memo" }' <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Redmine 404 error</title> <style> body {font-family: "Trebuchet MS", Georgia, "Times New Roman", serif; color: #303030; margin: 10px;} h1 {font-size:1.5em;} p {font-size:0.8em;} </style> </head> <body> <h1>Page not found</h1> <p>The page you were trying to access doesn't exist or has been removed.</p> <p><a href="javascript:history.back()">Back</a></p> </body> </html>

試したこと

APIでニュース情報が取得できることは確認済み。

# curl -s -XGET http://localhost/redmine/news.json | jq .news[0] { "id": 5, "project": { "id": 1, "name": "テストプロジェクト" }, "author": { "id": 6, "name": "テストユーザ" }, "title": "20191024_メモ", "summary": "", "description": "メモです。", "created_on": "2019-10-24T01:13:54Z" }

補足情報(FW/ツールのバージョンなど)

Environment:
Redmine version 3.4.11.stable.18600
Ruby version 2.4.1-p111 (2017-03-22) [x86_64-linux]
Rails version 4.2.11.1
Environment production
Database adapter PostgreSQL
SCM:
Subversion 1.7.14
Git 1.8.3.1
Filesystem

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

../redmine/app/controllers/news_controller.rb のファイルを修正して、

修正前:accept_api_auth :index
修正後:accept_api_auth :index, :create

とすれば、POSTもできます。

*ですが、現在のコードで許可していないのはなぜでしょうね。

投稿2019/10/24 03:11

編集2019/10/24 03:13
takashikawai

総合スコア172

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

dodox86

2019/10/24 03:16

。。。おー。無効にしている理由に少し興味があります。
dodox86

2019/10/24 03:37

ご案内ありがとうございます。案外泥臭い理由があるのかなと思いまして、単なる好奇心からでした。redmineは業務により使わせてもらう機会があるのですが、面倒を起こすのも申し訳ないので、改めて聞くのは止めておきます。
a-syuji

2019/10/25 16:13 編集

takashikawaiさん、度々ありがとうございます。 ファイルを修正しましたがPOST失敗しています。 少し調べましたが原因分からず、ご教示頂けますでしょうか。 ■redmine/app/controllers/news_controller.rb diff news_controller.rb_bk20191025 news_controller.rb 27c27 < accept_api_auth :index --- > accept_api_auth :index, :create ■POST curl -XPOST "http://localhost/redmine/news.json?key=$KEY" -H 'Content-Type: application/json' -d '{ "news": { "project_id": 1, "description": "test" } }' -vvv * About to connect() to localhost port 80 (#0) * Trying ::1... * Connected to localhost (::1) port 80 (#0) > POST /redmine/news.json?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx HTTP/1.1 > User-Agent: curl/7.29.0 > Host: localhost > Accept: */* > Content-Type: application/json > Content-Length: 66 > * upload completely sent off: 66 out of 66 bytes < HTTP/1.1 404 Not Found < Date: Fri, 25 Oct 2019 16:07:04 GMT < Server: Apache/2.4.6 (CentOS) Phusion_Passenger/5.1.12 < X-Request-Id: 5f2a2b86-baff-4483-baa6-56adb188f674 < Content-Length: 459 < Status: 404 Not Found < Content-Type: text/html; charset=utf-8 < <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Redmine 404 error</title> <style> body {font-family: "Trebuchet MS", Georgia, "Times New Roman", serif; color: #303030; margin: 10px;} h1 {font-size:1.5em;} p {font-size:0.8em;} </style> </head> <body> <h1>Page not found</h1> <p>The page you were trying to access doesn't exist or has been removed.</p> <p><a href="javascript:history.back()">Back</a></p> </body> </html> * Connection #0 to host localhost left intact ■redmine/log/production.log Started POST "/redmine/news.json?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" for ::1 at 2019-10-26 01:07:04 +0900 ActionController::RoutingError (No route matches [POST] "/news.json"): vendor/bundle/ruby/2.4.0/gems/actionpack-4.2.11.1/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' vendor/bundle/ruby/2.4.0/gems/actionpack-4.2.11.1/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' vendor/bundle/ruby/2.4.0/gems/railties-4.2.11.1/lib/rails/rack/logger.rb:38:in `call_app' vendor/bundle/ruby/2.4.0/gems/railties-4.2.11.1/lib/rails/rack/logger.rb:20:in `block in call' vendor/bundle/ruby/2.4.0/gems/activesupport-4.2.11.1/lib/active_support/tagged_logging.rb:68:in `block in tagged' vendor/bundle/ruby/2.4.0/gems/activesupport-4.2.11.1/lib/active_support/tagged_logging.rb:26:in `tagged' vendor/bundle/ruby/2.4.0/gems/activesupport-4.2.11.1/lib/active_support/tagged_logging.rb:68:in `tagged' vendor/bundle/ruby/2.4.0/gems/railties-4.2.11.1/lib/rails/rack/logger.rb:20:in `call' vendor/bundle/ruby/2.4.0/gems/actionpack-4.2.11.1/lib/action_dispatch/middleware/request_id.rb:21:in `call' vendor/bundle/ruby/2.4.0/gems/rack-1.6.11/lib/rack/methodoverride.rb:22:in `call' vendor/bundle/ruby/2.4.0/gems/rack-1.6.11/lib/rack/runtime.rb:18:in `call' vendor/bundle/ruby/2.4.0/gems/activesupport-4.2.11.1/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' vendor/bundle/ruby/2.4.0/gems/actionpack-4.2.11.1/lib/action_dispatch/middleware/static.rb:120:in `call' vendor/bundle/ruby/2.4.0/gems/rack-1.6.11/lib/rack/content_length.rb:15:in `call' vendor/bundle/ruby/2.4.0/gems/rack-1.6.11/lib/rack/sendfile.rb:113:in `call' vendor/bundle/ruby/2.4.0/gems/railties-4.2.11.1/lib/rails/engine.rb:518:in `call' vendor/bundle/ruby/2.4.0/gems/railties-4.2.11.1/lib/rails/application.rb:165:in `call' vendor/bundle/ruby/2.4.0/gems/railties-4.2.11.1/lib/rails/railtie.rb:194:in `public_send' vendor/bundle/ruby/2.4.0/gems/railties-4.2.11.1/lib/rails/railtie.rb:194:in `method_missing' passenger (5.1.12) src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request' passenger (5.1.12) src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:160:in `accept_and_process_next_request' passenger (5.1.12) src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:113:in `main_loop' passenger (5.1.12) src/ruby_supportlib/phusion_passenger/request_handler.rb:416:in `block (3 levels) in start_threads' passenger (5.1.12) src/ruby_supportlib/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'
takashikawai

2019/10/26 03:31 編集

"https://localhost/redmine/projects/プロジェクト名/news.json?key=$KEY" に変更 "title":"test" "auther_id":"6" を追加 で試してみてください。 私の環境では、以下でPOSTできました。*ニュースの画面で、「タイトル」は必須項目になっているので、含めないとエラーになるようです。 curl -v -H "Content-Type: application/json" -X POST -d '{"news": {"project_id": 1, "auther_id": 6, "title":"タイトルです", "summary":"サマリーです", "description": "説明です"}}' --insecure --user user:password https://localhost/redmine/projects/プロジェクト名/news.json?key=APIKEY
a-syuji

2019/10/26 05:36 編集

私の環境でもニュースの登録ができました。ありがとうございます。 最後に2点教えて下さい。 1.ニュースの登録時にリダイレクト(302)が返ってきます。チケットをAPIで登録した際はOK(200)でしたので気になりました。 <html><body>You are being <a href="http://localhost/redmine/projects/プロジェクト名/news">redirected</a>.</body></html> 2.URLを/redmine/projects/プロジェクト名とすることはどのようにして分かったのでしょうか?(トライ&エラーでしょうか。)
a-syuji

2019/10/26 06:46

勉強になります。ありがとうございました。
guest

0

ここの表を見るとそもそもGETでのニュース一覧取得もプロトタイプ扱いなので、登録はまだまだなのでしょう。

Redmine API - API Description

News Prototype Prototype implementation for index only 1.1

質問者さんが作ってcontributeすれば、喜ばれると思いますよ。

投稿2019/10/24 01:03

dodox86

総合スコア9183

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問