shonen.hateblo.jp

やったこと,しらべたことを書く.

手っ取り早くredmineのREST APIを叩く

redmineAPIを提供していることを知った。外から叩けるので、その気になればSlackと連携させることも出来る。

情報

これを読めば良いです。

www.redmine.org

手順

認証

redmineはclosedなので、認証をしないと中のデータが読み取れない。

Authentication
Most of the time, the API requires authentication. To enable the API-style authentication, you have to check Enable REST API in Administration -> Settings -> API. Then, authentication can be done in 2 different ways:

    using your regular login/password via HTTP Basic authentication.
    using your API key which is a handy way to avoid putting a password in a script. The API key may be attached to each request in one of the following way:
        passed in as a "key" parameter
        passed in as a username with a random password via HTTP Basic authentication
        passed in as a "X-Redmine-API-Key" HTTP header (added in Redmine 1.1.0)

You can find your API key on your account page ( /my/account ) when logged in, on the right-hand pane of the default layout.

basic認証する方法もあるが、APIアクセスキーを用いた方法が一番楽。

redmineにログイン→右上の「個人設定」→右側に「APIアクセスキー」があるので、これをメモする。

httpのクエリのヘッダに X-Redmine-API-Key: REDMINE-API-KEY-HERE を付けてredmineに投げれば良い。

試す

APIキーを a1b2c3d4e5f6 とする。 次のコマンドで、ユーザ一覧が取得出来る。

curl -s https://redmine.ukibune.net/users.json -H 'X-Redmine-API-Key: a1b2c3d4e5f6'

何も表示されなかった場合。コマンドの末尾に -i を付加して、ステータスコードを確認する。 もし401が返ってきているならapikeyが間違っている。403が返ってきているなら、そのアカウントにユーザ一覧を表示する権限が無い。

#

よく使われそうなのはissue一覧取得かな

www.redmine.org