LoginSignup
0
0

More than 1 year has passed since last update.

最低限のリクエストでさっくりWrikeAPIを叩いてみた

Posted at

Applibot Advent Calendar 2021 」 23日目の記事になります。
前日は @16cho さんの GoでPadding Oracle Attackしたい! という記事でした。

はじめに

自分が担当するプロジェクトではタスクの管理にWrikeを使っています。
日々の業務でWrike上で作業をする機会があるのですが、その中にアプリのビルドが完了したら成果物のリンクをチケットに記載する作業があり、地味に時間が取られてしまっていたので、当作業を自動化して簡略化出来ないかWrikeのAPIを調べてみました。

WrikeのAPIドキュメント

概要

  • WrikeAPIのPOSTやPUTを最低限のパラメーターで叩いてみる

導入まわり

今回は下調べが目的だっため、テスト環境を用意して永久アクセス・トークンを使用しました。
WrikeAPIの導入方法は既に分かりやすく記事にしていただいているので省略します。

自分が導入した際は以下の記事を参考にさせて頂きました。
Wrike APIの叩き方

導入時に一点見落として引っかかってしまったのですが、ユーザー毎にAPIを叩くに必要なベースのURLが異なる様です。

Please notice the "host" parameter. Wrike stores customer data in several data centers located in USA and European Union and you need to use a specific base URL to access user's data, based on where it is located. All the following requests on behalf of this user should be done using the base URL which you build by using the "host":

そのためドキュメントに記載されているURLは直接アクセス出来ない様なのでご注意ください。

curl -X GET -H "Authorization: bearer <アクセストークン>" https://<ユーザー毎に異なるベースURL>.wrike.com/api/v4/contacts?me=true

Wrike API を叩いてみる

GET /folders/{folderId}/folders

まずは任意のフォルダーを作るために、既存のフォルダー情報を取得します。

curl -X GET -H "Authorization: bearer <アクセストークン>" https://<ベースURL>.wrike.com/api/v4/folders

実行すると、既存のフォルダー情報が取得できました。

{
  "kind": "folderTree",
  "data": [
    {
      "id": "IEAE6KXRI7777777",
      "title": "Root",
      "childIds": [
        "IEAE6KXRI4YJGKCV",
        "IEAE6KXRI4YJGKD5"
      ],
      "scope": "WsRoot"
    },
    {
      "id": "IEAE6KXRI7777776",
      "title": "Recycle Bin",
      "childIds": [],
      "scope": "RbRoot"
    },
    {
      "id": "IEAE6KXRI4YJGKCV",
      "title": "個人専用",
      "childIds": [],
      "scope": "WsFolder"
    },
    {
      "id": "IEAE6KXRI4YJGKD5",
      "title": "依存関係があるプロジェクト",
      "childIds": [
        "IEAE6KXRI4YJGKD6"
      ],
      "scope": "WsFolder"
    },
    {
      "id": "IEAE6KXRI4YJGKD6",
      "title": "依存関係があるプロジェクト",
      "childIds": [],
      "scope": "WsFolder",
      "project": {
        "authorId": "KUALSMX2",
        "ownerIds": [
          "KUALSMX2"
        ],
        "customStatusId": "IEAE6KXRJMAAAAAA",
        "createdDate": "2021-12-20T19:55:44Z"
      }
    }
  ]
}

POST /folders/{folderId}/folders

先ほど取得したフォルダー情報から個人専用フォルダーのfolderIdを使って、個人専用フォルダー内に新しくフォルダーを作ります。

キー 説明 設定した値
{folderId} 親となるフォルダーのID IEAE6KXRI4YJGKCV
title フォルダーの名前 test_folder
curl -g -X POST -H "Authorization: bearer <アクセストークン>" -d "title=test_folder" "https://<ベースURL>.wrike.com/api/v4/folders/IEAE6KXRI4YJGKCV/folders"

実行すると以下の情報が返ってくるとともに

{
  "kind": "folders",
  "data": [
    {
      "id": "IEAE6KXRI4YK76KU",
      "accountId": "IEAE6KXR",
      "title": "test_folder",
      "createdDate": "2021-12-23T10:37:27Z",
      "updatedDate": "2021-12-23T10:37:27Z",
      "description": "",
      "sharedIds": [
        "KUALSMX2"
      ],
      "parentIds": [
        "IEAE6KXRI4YJGKCV"
      ],
      "childIds": [],
      "superParentIds": [],
      "scope": "WsFolder",
      "hasAttachments": false,
      "permalink": "https://<ベースURL>.wrike.com/open.htm?id=816838996",
      "workflowId": "IEAE6KXRK773BVIP",
      "metadata": [],
      "customFields": []
    }
  ]
}

Wrikeのページ上にもフォルダーが作られているのが確認できました。
スクリーンショット 2021-12-23 19.39.40.png

POST /folders/{folderId}/tasks

次は先ほど作ったフォルダー内に、新しくタスクを追加していきます。

キー 説明 設定した値
{folderId} タスクを格納するフォルダーのID IEAE6KXRI4YK76KU
title タスクの名前 test_task
description タスクの説明 test_description
curl -g -X POST -H "Authorization: bearer <アクセストークン>" -d "title=test_task&description=test_description" "https://<ベースURL>.wrike.com/api/v4/folders/IEAE6KXRI4YK76KU/tasks"

実行すると以下の情報が返ってくるとともに

{
  "kind": "tasks",
  "data": [
    {
      "id": "IEAE6KXRKQYK76PA",
      "accountId": "IEAE6KXR",
      "title": "test_task",
      "description": "test_description",
      "briefDescription": "test_description",
      "parentIds": [
        "IEAE6KXRI4YK76KU"
      ],
      "superParentIds": [],
      "sharedIds": [
        "KUALSMX2"
      ],
      "responsibleIds": [],
      "status": "Active",
      "importance": "Normal",
      "createdDate": "2021-12-23T10:53:52Z",
      "updatedDate": "2021-12-23T10:53:52Z",
      "dates": {
        "type": "Backlog"
      },
      "scope": "WsTask",
      "authorIds": [
        "KUALSMX2"
      ],
      "customStatusId": "IEAE6KXRJMAAAAAA",
      "hasAttachments": false,
      "attachmentCount": 0,
      "permalink": "https://<ベースURL>.wrike.com/open.htm?id=816839136",
      "priority": "014f20008000000000002000",
      "followedByMe": true,
      "followerIds": [
        "KUALSMX2"
      ],
      "superTaskIds": [],
      "subTaskIds": [],
      "dependencyIds": [],
      "metadata": [],
      "customFields": []
    }
  ]
}

Wrikeのページ上にもタスクが作られているのが確認できました。
スクリーンショット 2021-12-23 19.57.16.png

POST /workflows

次はワークフローを追加します。

キー 説明 設定した値
name ワークフローの名前 test_workflow
curl -g -X POST -H "Authorization: bearer <アクセストークン>" -d "name=test_workflow" "https://<ベースURL>.wrike.com/api/v4/workflows"

実行すると以下の情報が返ってくるとともに

{
  "kind": "workflows",
  "data": [
    {
      "id": "IEAE6KXRK4CMPX6W",
      "name": "test_workflow",
      "standard": false,
      "hidden": false,
      "customStatuses": [
        {
          "id": "IEAE6KXRJMCMPX6W",
          "name": "Active",
          "standardName": false,
          "color": "Blue",
          "standard": false,
          "group": "Active",
          "hidden": false
        },
        {
          "id": "IEAE6KXRJMCMPX6X",
          "name": "Completed",
          "standardName": false,
          "color": "Green",
          "standard": false,
          "group": "Completed",
          "hidden": false
        }
      ]
    }
  ]
}

Wrikeのページ上にもワークフローが作られているのが確認できました。
スクリーンショット 2021-12-23 20.11.31.png

PUT /workflows/{workflowId}

次は先ほど作成したワークフローにステータスを追加します。

キー 説明 設定した値
{workflowId} ワークフローの名前 IEAE6KXRK4CMPX6W
customStatus.name ステータスの名前 test_status
customStatus.color ステータスに設定する色(省略時はBlue) Green
customStatus.group グループの種類 Active
curl -g -X PUT -H "Authorization: bearer <アクセストークン>" -d 'customStatus={"name":"test_status","color":"Green","group":"Active"}' "https://<ベースURL>.wrike.com/api/v4/workflows/IEAE6KXRK4CMPX6W"

実行すると以下の情報が返ってくるとともに

{
  "kind": "workflows",
  "data": [
    {
      "id": "IEAE6KXRK4CMPX6W",
      "name": "test_workflow",
      "standard": false,
      "hidden": false,
      "customStatuses": [
        {
          "id": "IEAE6KXRJMCMPX6W",
          "name": "Active",
          "standardName": false,
          "color": "Blue",
          "standard": false,
          "group": "Active",
          "hidden": false
        },
        {
          "id": "IEAE6KXRJMCMPYCE",
          "name": "test_status",
          "standardName": false,
          "color": "Green",
          "standard": false,
          "group": "Active",
          "hidden": false
        },
        {
          "id": "IEAE6KXRJMCMPX6X",
          "name": "Completed",
          "standardName": false,
          "color": "Green",
          "standard": false,
          "group": "Completed",
          "hidden": false
        }
      ]
    }
  ]
}

Wrikeのページ上にもステータスが作られているのが確認できました。
スクリーンショット 2021-12-23 20.24.26.png

PUT /tasks/{taskId}

次は以前作成したタスクに、先ほど作成したステータスを設定します。

キー 説明 設定した値
{taskId} タスクのID IEAE6KXRKQYK76PA
customStatus ステータスのID IEAE6KXRJMCMPYCE
curl -g -X PUT -H "Authorization: bearer <アクセストークン>" -d "customStatus=IEAE6KXRJMCMPYCE" "https://<ベースURL>.wrike.com/api/v4/tasks/IEAE6KXRKQYK76PA"

実行すると以下の情報が返ってくるとともに

{
  "kind": "tasks",
  "data": [
    {
      "id": "IEAE6KXRKQYK76PA",
      "accountId": "IEAE6KXR",
      "title": "test_task",
      "description": "test_description<br />",
      "briefDescription": "test_description",
      "parentIds": [
        "IEAE6KXRI4YK76KU"
      ],
      "superParentIds": [],
      "sharedIds": [
        "KUALSMX2"
      ],
      "responsibleIds": [],
      "status": "Active",
      "importance": "Normal",
      "createdDate": "2021-12-23T10:53:52Z",
      "updatedDate": "2021-12-23T11:50:11Z",
      "dates": {
        "type": "Backlog"
      },
      "scope": "WsTask",
      "authorIds": [
        "KUALSMX2"
      ],
      "customStatusId": "IEAE6KXRJMCMPYCE",
      "hasAttachments": false,
      "attachmentCount": 0,
      "permalink": "https://<ベースURL>.wrike.com/open.htm?id=816839136",
      "priority": "014f20008000000000002000",
      "followedByMe": true,
      "followerIds": [
        "KUALSMX2"
      ],
      "superTaskIds": [],
      "subTaskIds": [],
      "dependencyIds": [],
      "metadata": [],
      "customFields": []
    }
  ]
}

Wrikeのページ上のタスクにもステータスが設定されているのが確認できました。
スクリーンショット 2021-12-23 20.54.31.png

おわりに

いくつかのPOSTやPUTを叩いてみましたが、非常に少ないパラメーターで実行できるので内容が分かりやすかったです。
今回は簡略化のため最低限のパラメーターのみでの動作しか載せておりませんが、オプションの種類が多く、やろうと思えば複雑な動作も可能な印象でした。

今回は載せられませんでしたが、今後WrikeAPIを活用して作業を簡略化してみた記事を書いてみようと思います。

WrikeAPIのドキュメントがとても見やすかったので、興味のある方は気軽に触ってみてはどうでしょうか?

以上「 Applibot Advent Calendar 2021 」 23日目の記事でした!

最後まで見て頂きありがとうございました!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0