azure-devops について
azure-devopsは、作業項目、リポジトリ、パイプラインなどを扱うAzure DevOps REST APIの利用ガイドスキルです。一般的なリクエスト方法を説明し、生成コードへのPAT認証情報の埋め込みを避ける方針を示します。
主な機能
- 01作業項目とWIQLの操作
- 02リポジトリ、ブランチ、PRのAPI
- 03ビルド、リリース、パイプライン管理
- 04認証と認証情報の安全な扱い
活用シーン
- 01作業項目の更新とクエリの自動化
- 02リポジトリの確認とPRの管理
- 03ビルドの実行とパイプライン結果の確認
- 04PATを直書きしないAPIスクリプトの作成
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ markpitt/ claude-skills --skill azure-devopsインストール後、Claude Code で/azure-devopsを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
resources/advanced-integrations.mdartifacts-packages.mdboards-work-tracking.mdorganization-security.mdpipelines-cicd.mdrepos-version-control.mdtest-plans-quality.md詳細
Azure DevOps API スキル
セキュリティ
PAT の値をそのまま埋め込んだコードを出力、提案、生成してはいけません。 必ず環境変数(例:$AZURE_DEVOPS_PAT)または Azure Key Vault などのシークレットマネージャーを使用して認証情報を参照してください。スクリプトや curl の例を生成する場合は、プレースホルダー変数の参照を使用し、トークン文字列をそのまま記述しないでください。
このスキルでは、Azure DevOps REST API を使用するための包括的なガイダンスを提供し、すべての Azure DevOps Services および Azure DevOps Server のリソースへのプログラムによるアクセスを可能にします。
概要
Azure DevOps REST API は、すべての Azure DevOps サービスにわたって、作業項目、リポジトリ、パイプライン、テスト計画、成果物などにアクセスし、管理できる RESTful Web API です。
ベース URL: https://dev.azure.com/{organization}/{project}/_apis/{area}/{resource}?api-version={version}
- Organization: Azure DevOps 組織名
- Project: プロジェクト名(組織レベルのリソースでは省略可能)
- API Version: すべてのリクエストで必須です(例:
7.1、7.0、6.0) - 認証: Personal Access Token(PAT)、OAuth 2.0、または Azure AD
クイックスタート
認証要件
Azure DevOps は複数の認証方法をサポートしています。
- Personal Access Token(PAT) - スクリプトや統合で最も一般的です
- OAuth 2.0 - Web アプリケーション向け
- Azure Active Directory - エンタープライズアプリケーション向け
- SSH Keys - Git 操作のみ
基本的な PAT 認証
GET https://dev.azure.com/{organization}/_apis/projects?api-version=7.1
Authorization: Basic {base64-encoded-PAT}
PAT をエンコードするには、base64(":{PAT}") を使用します。PAT の前にコロンがあることに注意してください。スクリプトや出力に PAT をハードコードせず、必ず環境変数(例:$AZURE_DEVOPS_PAT)から読み取ってください。
一般的なリクエストパターン
GET https://dev.azure.com/{organization}/{project}/_apis/{resource}?api-version=7.1
Authorization: Basic {encoded-PAT}
Content-Type: application/json
コアサービス
Azure DevOps は主要なサービス領域で構成されています。各領域には、独自の REST API セットがあります。
Azure Boards - 作業項目の追跡
作業項目
- 作業項目を作成:
POST /{organization}/{project}/_apis/wit/workitems/${type}?api-version=7.1 - 作業項目を取得:
GET /{organization}/{project}/_apis/wit/workitems/{id}?api-version=7.1 - 作業項目を更新:
PATCH /{organization}/{project}/_apis/wit/workitems/{id}?api-version=7.1 - 作業項目を削除:
DELETE /{organization}/{project}/_apis/wit/workitems/{id}?api-version=7.1
リクエスト本文では JSON Patch 形式を使用します。
[
{
"op": "add",
"path": "/fields/System.Title",
"value": "New bug report"
},
{
"op": "add",
"path": "/fields/System.AssignedTo",
"value": "[email protected]"
}
]
クエリ
- 保存済みクエリを実行:
GET /{organization}/{project}/_apis/wit/wiql/{id}?api-version=7.1 - WIQL クエリを実行:
POST /{organization}/{project}/_apis/wit/wiql?api-version=7.1{ "query": "SELECT [System.Id], [System.Title] FROM WorkItems WHERE [System.WorkItemType] = 'Bug' AND [System.State] = 'Active'" }
ボードとバックログ
- ボードを取得:
GET /{organization}/{project}/{team}/_apis/work/boards?api-version=7.1 - バックログ項目を取得:
GET /{organization}/{project}/{team}/_apis/work/backlogs/{backlogId}/workItems?api-version=7.1 - イテレーションを取得:
GET /{organization}/{project}/{team}/_apis/work/teamsettings/iterations?api-version=7.1 - キャパシティを取得:
GET /{organization}/{project}/{team}/_apis/work/teamsettings/iterations/{iterationId}/capacities?api-version=7.1
作業項目の種類とフィールド
- 作業項目の種類を一覧表示:
GET /{organization}/{project}/_apis/wit/workitemtypes?api-version=7.1 - フィールドを一覧表示:
GET /{organization}/{project}/_apis/wit/fields?api-version=7.1 - フィールドを取得:
GET /{organization}/{project}/_apis/wit/fields/{fieldNameOrRefName}?api-version=7.1
エリアとイテレーションのパス
- エリアを取得:
GET /{organization}/{project}/_apis/wit/classificationnodes/areas?api-version=7.1 - イテレーションを取得:
GET /{organization}/{project}/_apis/wit/classificationnodes/iterations?api-version=7.1 - エリアを作成:
POST /{organization}/{project}/_apis/wit/classificationnodes/areas?api-version=7.1
Azure Repos - ソース管理
Git リポジトリ
- リポジトリの一覧表示:
GET /{organization}/{project}/_apis/git/repositories?api-version=7.1 - リポジトリの取得:
GET /{organization}/{project}/_apis/git/repositories/{repositoryId}?api-version=7.1 - リポジトリの作成:
POST /{organization}/{project}/_apis/git/repositories?api-version=7.1 - リポジトリの削除:
DELETE /{organization}/{project}/_apis/git/repositories/{repositoryId}?api-version=7.1
コミット
- コミットの取得:
GET /{organization}/{project}/_apis/git/repositories/{repositoryId}/commits?api-version=7.1 - コミットの取得:
GET /{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}?api-version=7.1 - コミットの変更内容の取得:
GET /{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}/changes?api-version=7.1
ブランチ
- ブランチの取得:
GET /{organization}/{project}/_apis/git/repositories/{repositoryId}/refs?filter=heads/&api-version=7.1 - ブランチの作成:
POST /{organization}/{project}/_apis/git/repositories/{repositoryId}/refs?api-version=7.1 - ブランチの削除:
POST /{organization}/{project}/_apis/git/repositories/{repositoryId}/refs?api-version=7.1[ { "name": "refs/heads/feature-branch", "oldObjectId": "0000000000000000000000000000000000000000", "newObjectId": "{commitId}" } ]
プルリクエスト
- プルリクエストの取得:
GET /{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests?api-version=7.1 - プルリクエストの取得:
GET /{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests/{pullRequestId}?api-version=7.1 - プルリクエストの作成:
POST /{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests?api-version=7.1{ "sourceRefName": "refs/heads/feature", "targetRefName": "refs/heads/main", "title": "PR Title", "description": "PR Description" } - プルリクエストの更新:
PATCH /{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests/{pullRequestId}?api-version=7.1 - PR レビュアーの取得:
GET /{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests/{pullRequestId}/reviewers?api-version=7.1 - PR レビュアーの追加:
PUT /{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests/{pullRequestId}/reviewers/{reviewerId}?api-version=7.1 - PR 作業項目の取得:
GET /{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests/{pullRequestId}/workitems?api-version=7.1 - PR スレッドの取得:
GET /{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests/{pullRequestId}/threads?api-version=7.1 - PR コメントの追加:
POST /{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests/{pullRequestId}/threads?api-version=7.1
プッシュ
- プッシュの取得:
GET /{organization}/{project}/_apis/git/repositories/{repositoryId}/pushes?api-version=7.1 - プッシュの取得:
GET /{organization}/{project}/_apis/git/repositories/{repositoryId}/pushes/{pushId}?api-version=7.1
項目(ファイルとフォルダー)
- 項目の取得:
GET /{organization}/{project}/_apis/git/repositories/{repositoryId}/items?path={path}&api-version=7.1 - 項目の内容の取得:
GET /{organization}/{project}/_apis/git/repositories/{repositoryId}/items?path={path}&download=true&api-version=7.1 - 項目の一括取得:
POST /{organization}/{project}/_apis/git/repositories/{repositoryId}/itemsbatch?api-version=7.1
ポリシー
- ポリシー構成の取得:
GET /{organization}/{project}/_apis/policy/configurations?api-version=7.1 - ポリシーの作成:
POST /{organization}/{project}/_apis/policy/configurations?api-version=7.1
Azure Pipelines - CI/CD
Build Definitions (Pipelines)
- List definitions:
GET /{organization}/{project}/_apis/build/definitions?api-version=7.1 - Get definition:
GET /{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=7.1 - Create definition:
POST /{organization}/{project}/_apis/build/definitions?api-version=7.1 - Update definition:
PUT /{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=7.1 - Delete definition:
DELETE /{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=7.1
Builds
- Queue build:
POST /{organization}/{project}/_apis/build/builds?api-version=7.1{ "definition": { "id": 123 }, "sourceBranch": "refs/heads/main" } - Get builds:
GET /{organization}/{project}/_apis/build/builds?api-version=7.1 - Get build:
GET /{organization}/{project}/_apis/build/builds/{buildId}?api-version=7.1 - Update build:
PATCH /{organization}/{project}/_apis/build/builds/{buildId}?api-version=7.1 - Delete build:
DELETE /{organization}/{project}/_apis/build/builds/{buildId}?api-version=7.1 - Get build logs:
GET /{organization}/{project}/_apis/build/builds/{buildId}/logs?api-version=7.1 - Get build timeline:
GET /{organization}/{project}/_apis/build/builds/{buildId}/timeline?api-version=7.1 - Get build artifacts:
GET /{organization}/{project}/_apis/build/builds/{buildId}/artifacts?api-version=7.1
Release Definitions
- List definitions:
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions?api-version=7.1 - Get definition:
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions/{definitionId}?api-version=7.1 - Create definition:
POST https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions?api-version=7.1
Releases
- Create release:
POST https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?api-version=7.1 - Get releases:
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases?api-version=7.1 - Get release:
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}?api-version=7.1 - Update release:
PATCH https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}?api-version=7.1 - Get release environment:
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}/environments/{environmentId}?api-version=7.1 - Update release environment:
PATCH https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/releases/{releaseId}/environments/{environmentId}?api-version=7.1
Approvals
- Get approvals:
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/approvals?api-version=7.1 - Update approval:
PATCH https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/approvals/{approvalId}?api-version=7.1
Agent Pools
- List pools:
GET /{organization}/_apis/distributedtask/pools?api-version=7.1 - Get pool:
GET /{organization}/_apis/distributedtask/pools/{poolId}?api-version=7.1 - Add pool:
POST /{organization}/_apis/distributedtask/pools?api-version=7.1
Agents
- List agents:
GET /{organization}/_apis/distributedtask/pools/{poolId}/agents?api-version=7.1 - Get agent:
GET /{organization}/_apis/distributedtask/pools/{poolId}/agents/{agentId}?api-version=7.1 - Update agent:
PATCH /{organization}/_apis/distributedtask/pools/{poolId}/agents/{agentId}?api-version=7.1
Variable Groups
- List variable groups:
GET /{organization}/{project}/_apis/distributedtask/variablegroups?api-version=7.1 - Get variable group:
GET /{organization}/{project}/_apis/distributedtask/variablegroups/{groupId}?api-version=7.1 - Create variable group:
POST /{organization}/{project}/_apis/distributedtask/variablegroups?api-version=7.1 - Update variable group:
PUT /{organization}/{project}/_apis/distributedtask/variablegroups/{groupId}?api-version=7.1
Task Groups
- List task groups:
GET /{organization}/{project}/_apis/distributedtask/taskgroups?api-version=7.1 - Get task group:
GET /{organization}/{project}/_apis/distributedtask/taskgroups/{taskGroupId}?api-version=7.1
Service Endpoints (Connections)
- List endpoints:
GET /{organization}/{project}/_apis/serviceendpoint/endpoints?api-version=7.1 - Get endpoint:
GET /{organization}/{project}/_apis/serviceendpoint/endpoints/{endpointId}?api-version=7.1 - Create endpoint:
POST /{organization}/{project}/_apis/serviceendpoint/endpoints?api-version=7.1
Azure Test Plans
Test Plans
- List test plans:
GET /{organization}/{project}/_apis/testplan/plans?api-version=7.1 - Get test plan:
GET /{organization}/{project}/_apis/testplan/plans/{planId}?api-version=7.1 - Create test plan:
POST /{organization}/{project}/_apis/testplan/plans?api-version=7.1 - Update test plan:
PATCH /{organization}/{project}/_apis/testplan/plans/{planId}?api-version=7.1
Test Suites
- List test suites:
GET /{organization}/{project}/_apis/testplan/plans/{planId}/suites?api-version=7.1 - Get test suite:
GET /{organization}/{project}/_apis/testplan/plans/{planId}/suites/{suiteId}?api-version=7.1 - Create test suite:
POST /{organization}/{project}/_apis/testplan/plans/{planId}/suites?api-version=7.1
Test Cases
- List test cases:
GET /{organization}/{project}/_apis/testplan/plans/{planId}/suites/{suiteId}/testcases?api-version=7.1 - Get test case:
GET /{organization}/{project}/_apis/testplan/plans/{planId}/suites/{suiteId}/testcases/{testCaseId}?api-version=7.1 - Add test cases:
POST /{organization}/{project}/_apis/testplan/plans/{planId}/suites/{suiteId}/testcases?api-version=7.1
Test Runs
- Create test run:
POST /{organization}/{project}/_apis/test/runs?api-version=7.1 - Get test runs:
GET /{organization}/{project}/_apis/test/runs?api-version=7.1 - Get test run:
GET /{organization}/{project}/_apis/test/runs/{runId}?api-version=7.1 - Update test run:
PATCH /{organization}/{project}/_apis/test/runs/{runId}?api-version=7.1
Test Results
- Get test results:
GET /{organization}/{project}/_apis/test/runs/{runId}/results?api-version=7.1 - Get test result:
GET /{organization}/{project}/_apis/test/runs/{runId}/results/{resultId}?api-version=7.1 - Update test results:
PATCH /{organization}/{project}/_apis/test/runs/{runId}/results?api-version=7.1 - Add test results:
POST /{organization}/{project}/_apis/test/runs/{runId}/results?api-version=7.1
Test Configurations
- List configurations:
GET /{organization}/{project}/_apis/testplan/configurations?api-version=7.1 - Get configuration:
GET /{organization}/{project}/_apis/testplan/configurations/{configurationId}?api-version=7.1
Azure Artifacts
フィード
- フィードの一覧を取得:
GET https://feeds.dev.azure.com/{organization}/_apis/packaging/feeds?api-version=7.1 - フィードを取得:
GET https://feeds.dev.azure.com/{organization}/_apis/packaging/feeds/{feedId}?api-version=7.1 - フィードを作成:
POST https://feeds.dev.azure.com/{organization}/_apis/packaging/feeds?api-version=7.1 - フィードを更新:
PATCH https://feeds.dev.azure.com/{organization}/_apis/packaging/feeds/{feedId}?api-version=7.1
パッケージ
- パッケージの一覧を取得:
GET https://feeds.dev.azure.com/{organization}/_apis/packaging/feeds/{feedId}/packages?api-version=7.1 - パッケージを取得:
GET https://feeds.dev.azure.com/{organization}/_apis/packaging/feeds/{feedId}/packages/{packageId}?api-version=7.1 - パッケージを削除:
DELETE https://feeds.dev.azure.com/{organization}/_apis/packaging/feeds/{feedId}/packages/{packageId}?api-version=7.1
パッケージのバージョン
- パッケージのバージョン一覧を取得:
GET https://feeds.dev.azure.com/{organization}/_apis/packaging/feeds/{feedId}/packages/{packageId}/versions?api-version=7.1 - パッケージのバージョンを取得:
GET https://feeds.dev.azure.com/{organization}/_apis/packaging/feeds/{feedId}/packages/{packageId}/versions/{versionId}?api-version=7.1 - パッケージのバージョンを削除:
DELETE https://feeds.dev.azure.com/{organization}/_apis/packaging/feeds/{feedId}/packages/{packageId}/versions/{versionId}?api-version=7.1
フィードのアクセス許可
- フィードのアクセス許可を取得:
GET https://feeds.dev.azure.com/{organization}/_apis/packaging/feeds/{feedId}/permissions?api-version=7.1 - フィードのアクセス許可を設定:
PATCH https://feeds.dev.azure.com/{organization}/_apis/packaging/feeds/{feedId}/permissions?api-version=7.1
組織とプロジェクトの管理
組織
- 組織の一覧を取得: Azure DevOps Profile API から利用できます
- 組織の詳細を取得:
GET https://dev.azure.com/{organization}/_apis/projectcollections?api-version=7.1
プロジェクト
- プロジェクトの一覧を取得:
GET /{organization}/_apis/projects?api-version=7.1 - プロジェクトを取得:
GET /{organization}/_apis/projects/{projectId}?api-version=7.1 - プロジェクトを作成:
POST /{organization}/_apis/projects?api-version=7.1{ "name": "MyProject", "description": "Project description", "capabilities": { "versioncontrol": { "sourceControlType": "Git" }, "processTemplate": { "templateTypeId": "6b724908-ef14-45cf-84f8-768b5384da45" } } } - プロジェクトを更新:
PATCH /{organization}/_apis/projects/{projectId}?api-version=7.1 - プロジェクトを削除:
DELETE /{organization}/_apis/projects/{projectId}?api-version=7.1
チーム
- チームの一覧を取得:
GET /{organization}/_apis/teams?api-version=7.1 - チームを取得:
GET /{organization}/_apis/projects/{projectId}/teams/{teamId}?api-version=7.1 - チームを作成:
POST /{organization}/_apis/projects/{projectId}/teams?api-version=7.1 - チームを更新:
PATCH /{organization}/_apis/projects/{projectId}/teams/{teamId}?api-version=7.1 - チームを削除:
DELETE /{organization}/_apis/projects/{projectId}/teams/{teamId}?api-version=7.1
チームメンバー
- チームメンバーを取得:
GET /{organization}/_apis/projects/{projectId}/teams/{teamId}/members?api-version=7.1 - チームメンバーを追加:
PUT /{organization}/_apis/projects/{projectId}/teams/{teamId}/members/{userId}?api-version=7.1 - チームメンバーを削除:
DELETE /{organization}/_apis/projects/{projectId}/teams/{teamId}/members/{userId}?api-version=7.1
プロセス
- プロセスの一覧を取得:
GET /{organization}/_apis/process/processes?api-version=7.1 - プロセスを取得:
GET /{organization}/_apis/process/processes/{processId}?api-version=7.1 - プロセスを作成:
POST /{organization}/_apis/process/processes?api-version=7.1
Security & Identity
Identities (Users & Groups)
- Read identities:
GET https://vssps.dev.azure.com/{organization}/_apis/identities?api-version=7.1 - Read identity:
GET https://vssps.dev.azure.com/{organization}/_apis/identities/{identityId}?api-version=7.1
Graph (Azure DevOps specific)
- List users:
GET https://vssps.dev.azure.com/{organization}/_apis/graph/users?api-version=7.1-preview.1 - Get user:
GET https://vssps.dev.azure.com/{organization}/_apis/graph/users/{userDescriptor}?api-version=7.1-preview.1 - Create user:
POST https://vssps.dev.azure.com/{organization}/_apis/graph/users?api-version=7.1-preview.1 - Delete user:
DELETE https://vssps.dev.azure.com/{organization}/_apis/graph/users/{userDescriptor}?api-version=7.1-preview.1
Groups
- List groups:
GET https://vssps.dev.azure.com/{organization}/_apis/graph/groups?api-version=7.1-preview.1 - Get group:
GET https://vssps.dev.azure.com/{organization}/_apis/graph/groups/{groupDescriptor}?api-version=7.1-preview.1 - Create group:
POST https://vssps.dev.azure.com/{organization}/_apis/graph/groups?api-version=7.1-preview.1 - Delete group:
DELETE https://vssps.dev.azure.com/{organization}/_apis/graph/groups/{groupDescriptor}?api-version=7.1-preview.1
Group Memberships
- List memberships:
GET https://vssps.dev.azure.com/{organization}/_apis/graph/memberships/{subjectDescriptor}?api-version=7.1-preview.1 - Add membership:
PUT https://vssps.dev.azure.com/{organization}/_apis/graph/memberships/{subjectDescriptor}/{containerDescriptor}?api-version=7.1-preview.1 - Remove membership:
DELETE https://vssps.dev.azure.com/{organization}/_apis/graph/memberships/{subjectDescriptor}/{containerDescriptor}?api-version=7.1-preview.1
Access Control Lists (ACLs)
- Query ACLs:
GET /{organization}/_apis/accesscontrollists/{securityNamespaceId}?api-version=7.1 - Set ACLs:
POST /{organization}/_apis/accesscontrollists/{securityNamespaceId}?api-version=7.1 - Remove ACLs:
DELETE /{organization}/_apis/accesscontrollists/{securityNamespaceId}?api-version=7.1
Security Namespaces
- List security namespaces:
GET /{organization}/_apis/securitynamespaces?api-version=7.1 - Get security namespace:
GET /{organization}/_apis/securitynamespaces/{securityNamespaceId}?api-version=7.1
Permissions
- Query permissions:
GET /{organization}/_apis/permissions/{securityNamespaceId}/{permissions}?api-version=7.1 - Check permission:
GET /{organization}/_apis/security/permissions/{securityNamespaceId}?api-version=7.1
Extensions & Integrations
Extensions
- List installed extensions:
GET /{organization}/_apis/extensionmanagement/installedextensions?api-version=7.1 - Get installed extension:
GET /{organization}/_apis/extensionmanagement/installedextensions/{publisherName}/{extensionName}?api-version=7.1 - Install extension:
POST /{organization}/_apis/extensionmanagement/installedextensions?api-version=7.1 - Uninstall extension:
DELETE /{organization}/_apis/extensionmanagement/installedextensions/{publisherName}/{extensionName}?api-version=7.1
Service Hooks
- List subscriptions:
GET /{organization}/_apis/hooks/subscriptions?api-version=7.1 - Get subscription:
GET /{organization}/_apis/hooks/subscriptions/{subscriptionId}?api-version=7.1 - Create subscription:
POST /{organization}/_apis/hooks/subscriptions?api-version=7.1{ "publisherId": "tfs", "eventType": "git.push", "resourceVersion": "1.0", "consumerId": "webHooks", "consumerActionId": "httpRequest", "publisherInputs": { "projectId": "{projectId}" }, "consumerInputs": { "url": "https://example.com/webhook" } } - Delete subscription:
DELETE /{organization}/_apis/hooks/subscriptions/{subscriptionId}?api-version=7.1
Notifications
- List subscriptions:
GET /{organization}/_apis/notification/subscriptions?api-version=7.1 - Create subscription:
POST /{organization}/_apis/notification/subscriptions?api-version=7.1
その他のサービス
Wiki
- Wiki の一覧表示:
GET /{organization}/{project}/_apis/wiki/wikis?api-version=7.1 - Wiki の取得:
GET /{organization}/{project}/_apis/wiki/wikis/{wikiId}?api-version=7.1 - Wiki の作成:
POST /{organization}/{project}/_apis/wiki/wikis?api-version=7.1 - Wiki ページの取得:
GET /{organization}/{project}/_apis/wiki/wikis/{wikiId}/pages?path={path}&api-version=7.1 - Wiki ページの作成/更新:
PUT /{organization}/{project}/_apis/wiki/wikis/{wikiId}/pages?path={path}&api-version=7.1
検索
- 作業項目の検索:
POST /{organization}/{project}/_apis/search/workitemsearchresults?api-version=7.1 - コードの検索:
POST /{organization}/{project}/_apis/search/codesearchresults?api-version=7.1
ダッシュボード
- ダッシュボードの一覧表示:
GET /{organization}/{project}/{team}/_apis/dashboard/dashboards?api-version=7.1 - ダッシュボードの取得:
GET /{organization}/{project}/{team}/_apis/dashboard/dashboards/{dashboardId}?api-version=7.1 - ダッシュボードの作成:
POST /{organization}/{project}/{team}/_apis/dashboard/dashboards?api-version=7.1
ウィジェット
- ウィジェットの一覧表示:
GET /{organization}/{project}/{team}/_apis/dashboard/dashboards/{dashboardId}/widgets?api-version=7.1 - ウィジェットの作成:
POST /{organization}/{project}/{team}/_apis/dashboard/dashboards/{dashboardId}/widgets?api-version=7.1
監査
- 監査ログのクエリ:
GET /{organization}/_apis/audit/auditlog?api-version=7.1-preview.1 - 監査ログのダウンロード:
GET /{organization}/_apis/audit/downloadlog?api-version=7.1-preview.1
共通操作
ページネーション
Azure DevOps API では、ページネーションに継続トークンを使用します。
継続トークンを含むレスポンス:
{
"count": 100,
"value": [...],
"continuationToken": "MTIz"
}
次のリクエスト:
GET /{endpoint}?continuationToken=MTIz&api-version=7.1
一部のエンドポイントでは $top と $skip を使用します。
GET /{endpoint}?$top=100&$skip=100&api-version=7.1
フィルタリングとクエリ
OData 形式のフィルター(選択したエンドポイント):
GET /{endpoint}?$filter=state eq 'Active'&api-version=7.1
作業項目のクエリでは WIQL(Work Item Query Language)を使用します。
SELECT [System.Id], [System.Title], [System.State]
FROM WorkItems
WHERE [System.WorkItemType] = 'Bug'
AND [System.State] = 'Active'
AND [System.AssignedTo] = @Me
ORDER BY [System.ChangedDate] DESC
バッチ操作
一部の Azure DevOps API では、バッチ操作がサポートされています。
作業項目の一括取得:
GET /{organization}/_apis/wit/workitemsbatch?ids=1,2,3,4,5&api-version=7.1
Git 項目のバッチ処理:
POST /{organization}/{project}/_apis/git/repositories/{repositoryId}/itemsbatch?api-version=7.1
{
"itemDescriptors": [
{"path": "/file1.txt", "version": "main"},
{"path": "/file2.txt", "version": "main"}
]
}
更新に使用する JSON Patch
作業項目やその他一部のリソースでは、JSON Patch(RFC 6902)を使用します。
操作:
add- フィールドまたは関連付けを追加しますremove- フィールドを削除しますreplace- フィールドの値を置き換えますtest- 値をテストします(並行処理用)copy- 値をコピーしますmove- 値を移動します
例:
[
{
"op": "add",
"path": "/fields/System.Title",
"value": "New title"
},
{
"op": "replace",
"path": "/fields/System.State",
"value": "Active"
},
{
"op": "add",
"path": "/relations/-",
"value": {
"rel": "System.LinkTypes.Hierarchy-Reverse",
"url": "https://dev.azure.com/{org}/_apis/wit/workItems/123"
}
}
]
エラー処理
Azure DevOps API は、標準の HTTP ステータスコードを返します。
200 OK- 成功201 Created- リソースを作成しました202 Accepted- リクエストを受け付けました(非同期操作)204 No Content- 成功しました。コンテンツはありません400 Bad Request- 無効なリクエスト401 Unauthorized- 認証が必要です403 Forbidden- 権限が不足しています404 Not Found- リソースが見つかりません409 Conflict- 競合しています(例:バージョンの不一致)429 Too Many Requests- レート制限を超過しました500 Internal Server Error- サーバーエラー503 Service Unavailable- サービスを利用できません
エラーレスポンス形式:
{
"id": "request-id",
"innerException": null,
"message": "TF401019: The Git repository with name or identifier MyRepo does not exist or you do not have permissions for the operation you are attempting.",
"typeName": "Microsoft.TeamFoundation.Git.Server.GitRepositoryNotFoundException",
"typeKey": "GitRepositoryNotFoundException",
"errorCode": 0,
"eventId": 3000
}
レート制限
Azure DevOps にはレート制限があります。
- 全体の制限: サービスによって異なります(通常、1 分あたり 200~300 件のリクエスト)
- TSTU(Team Services Time Units): リソース消費量の測定に使用します
- Retry-After ヘッダー: 429 エラー後に再試行するタイミングを示します
ベストプラクティス:
- 指数バックオフを実装します
Retry-Afterヘッダーを遵守します- 適切な場合はレスポンスをキャッシュします
- 利用可能な場合はバッチ操作を使用します
権限とスコープ
PAT スコープ
Personal Access Token を作成するときは、適切なスコープを選択してください。
- Agent Pools: 読み取りと管理
- Analytics: 読み取り
- Audit: 監査ログの読み取り
- Build: 読み取りと実行
- Code: フル、読み取り、またはステータス
- Extensions: 読み取りと管理
- Graph: 読み取り
- Identity: 読み取り
- Marketplace: 取得、管理、公開
- Member Entitlement Management: 読み取りと書き込み
- Packaging: 読み取り、書き込み、管理
- Project and Team: 読み取り、書き込み、管理
- Release: 読み取り、書き込み、実行、管理
- Secure Files: 読み取り、作成、管理
- Service Connections: 読み取り、クエリ、管理
- Symbols: 読み取り
- Task Groups: 読み取り、作成、管理
- Test Management: 読み取りと書き込み
- Tokens: 読み取りと管理
- User Profile: 読み取りと書き込み
- Variable Groups: 読み取り、作成、管理
- Work Items: フル、読み取り、書き込み
重要: 常に必要最小限の権限スコープを使用してください。
OAuth 2.0 スコープ
OAuth アプリケーションでは、次の形式のスコープを使用してください。
vso.work- 作業項目(読み取り)vso.work_write- 作業項目(書き込み)vso.code- コード(読み取り)vso.code_write- コード(書き込み)vso.build- ビルド(読み取り)vso.build_execute- ビルド(実行)
全リスト:https://docs.microsoft.com/azure/devops/integrate/get-started/authentication/oauth
API のバージョン管理
Azure DevOps API では、明示的なバージョン管理が使用されます。
バージョン:
7.1- 最新の安定版(推奨)7.0- 安定版6.0- 安定版5.1- 旧安定版-previewサフィックス付きのバージョン(例:7.1-preview.1) - プレビュー機能
バージョン形式:
api-version=7.1- 7.1 の最新パッチapi-version=7.1-preview.1- 7.1 のプレビュー バージョン 1
重要:
- 常に
api-versionを指定してください(すべてのリクエストで必須) - プレビュー API は変更または削除される場合があります
- 本番環境では安定版を使用してください
- 非推奨に関する通知を確認してください
ベストプラクティス
パフォーマンス
- 複数の項目を取得するときはバッチ操作を使用します
- 大きな結果セットではページネーションを実装します
- サポートされている場合は、
$selectを使用して必要なフィールドを指定します - 適切な場合はレスポンスをキャッシュします
- 差分同期にはデルタ クエリを使用します
- 継続トークンを適切に活用します
セキュリティ
- PAT を安全に保管します(Azure Key Vault などを使用)
- 適切なスコープ(最小権限)を使用します
- PAT を定期的にローテーションします(有効期限を設定)
- HTTPS のみを使用します
- インジェクションを防ぐために入力を検証します
- 適切なエラー処理を実装します
- セキュリティイベントをログに記録します
- PAT をソース管理にコミットしないでください
開発
- 最新の安定版 API バージョンを使用します
- 再試行ロジックでレート制限に対応します
- 指数バックオフを実装します
- プレビュー API を使用する前に、安定性を確認します
- サービスの状態を監視します
- 更新には JSON Patch を使用します
- レスポンスを検証します
- ページネーションを正しく処理します
- さまざまなエッジケースでテストします
- 内容が明確なエラーメッセージを使用します
統合パターン
- Webhook(Service Hooks): イベント駆動型の統合に使用します
- ポーリング: バッチ処理に使用します(過剰なポーリングは避けてください)
- スケジュール済みジョブ: 定期的な同期処理に使用します
- リアルタイム同期: Service Hooks と API 呼び出しを組み合わせて使用します
一般的なユースケース
作業項目の作成
POST https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/$Bug?api-version=7.1
Content-Type: application/json-patch+json
[
{
"op": "add",
"path": "/fields/System.Title",
"value": "Critical bug in login flow"
},
{
"op": "add",
"path": "/fields/System.Description",
"value": "Users cannot log in with SSO"
},
{
"op": "add",
"path": "/fields/Microsoft.VSTS.Common.Priority",
"value": 1
}
]
プルリクエストの作成
POST https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests?api-version=7.1
Content-Type: application/json
{
"sourceRefName": "refs/heads/feature/new-feature",
"targetRefName": "refs/heads/main",
"title": "Add new feature",
"description": "This PR adds the new feature",
"reviewers": [
{"id": "reviewer-id-1"},
{"id": "reviewer-id-2"}
]
}
ビルドのキュー登録
POST https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=7.1
Content-Type: application/json
{
"definition": {
"id": 123
},
"sourceBranch": "refs/heads/main",
"parameters": "{\"param1\":\"value1\"}"
}
WIQL クエリの実行
POST https://dev.azure.com/{organization}/{project}/_apis/wit/wiql?api-version=7.1
Content-Type: application/json
{
"query": "SELECT [System.Id], [System.Title], [System.State] FROM WorkItems WHERE [System.WorkItemType] = 'Bug' AND [System.State] = 'Active' AND [System.AssignedTo] = @Me ORDER BY [System.Priority] ASC"
}
Service Hook サブスクリプションの作成
POST https://dev.azure.com/{organization}/_apis/hooks/subscriptions?api-version=7.1
Content-Type: application/json
{
"publisherId": "tfs",
"eventType": "workitem.updated",
"resourceVersion": "1.0",
"consumerId": "webHooks",
"consumerActionId": "httpRequest",
"publisherInputs": {
"projectId": "{projectId}",
"workItemType": "Bug"
},
"consumerInputs": {
"url": "https://example.com/webhook",
"httpHeaders": "Content-Type:application/json"
}
}
ツールとテスト
REST クライアントツール
- Postman - 人気の API テストツール
- curl - コマンドラインツール
- PowerShell -
Invoke-RestMethod - Python -
requestsライブラリ - Azure DevOps CLI - 公式 CLI ツール
Azure DevOps CLI
公式 CLI をインストールして使用します。
# Install
pip install azure-devops
# Login
az devops login --organization https://dev.azure.com/{organization}
# Configure defaults
az devops configure --defaults organization=https://dev.azure.com/{organization} project={project}
# Examples
az repos list
az pipelines build list
az boards work-item create --title "Bug" --type Bug
認証のテスト
環境変数を使って PAT 認証をテストします。トークンをハードコードしないでください。
# Set once in your shell session (do not commit this to scripts or source control)
# export AZURE_DEVOPS_PAT="<your-pat>"
# Encode from environment variable
PAT_ENCODED=$(echo -n ":$AZURE_DEVOPS_PAT" | base64)
# Test
curl -H "Authorization: Basic $PAT_ENCODED" \
"https://dev.azure.com/{organization}/_apis/projects?api-version=7.1"
推奨: az devops login を使用してください。手動でエンコードせずに、認証情報を安全に保管できます。
利用可能な SDK
- .NET -
Microsoft.TeamFoundationServer.Client,Microsoft.VisualStudio.Services.Client - Node.js -
azure-devops-node-api - Python -
azure-devops - Java - Azure DevOps SDK for Java
段階的な読み込み
このスキルでは、Azure DevOps API を包括的に扱います。特定のタスクを行う場合は、次の手順に従ってください。
- サービス領域を特定する(Boards、Repos、Pipelines、Test、Artifacts)
- このドキュメントで該当するセクションを見つける
- 詳細なパラメーター情報を API リファレンスで確認する
- 実装前に Azure DevOps CLI または REST クライアントでテストする
リファレンスリンク
- 公式ドキュメント: https://docs.microsoft.com/rest/api/azure/devops/
- API リファレンス: https://docs.microsoft.com/rest/api/azure/devops/?view=azure-devops-rest-7.1
- 認証: https://docs.microsoft.com/azure/devops/integrate/get-started/authentication/authentication-guidance
- サービスフック: https://docs.microsoft.com/azure/devops/service-hooks/overview
- レート制限: https://docs.microsoft.com/azure/devops/integrate/concepts/rate-limits
- API のバージョン管理: https://docs.microsoft.com/azure/devops/integrate/concepts/rest-api-versioning
- Azure DevOps CLI: https://docs.microsoft.com/cli/azure/devops
- Node.js SDK: https://github.com/microsoft/azure-devops-node-api
- Python SDK: https://github.com/microsoft/azure-devops-python-api
- ステータスページ: https://status.dev.azure.com/
API URL のパターン
Azure DevOps のサービスによって、ベース URL は異なります。
- コアサービス:
https://dev.azure.com/{organization}/ - リリース管理:
https://vsrm.dev.azure.com/{organization}/ - パッケージ管理:
https://feeds.dev.azure.com/{organization}/ - ID:
https://vssps.dev.azure.com/{organization}/ - 分析:
https://analytics.dev.azure.com/{organization}/
注意事項
- このスキルは、Azure DevOps REST API のバージョン 7.1(最新の安定版)を対象としています
- 一部のエンドポイントでは、プレビュー版の API が必要になる場合があります
- 最新の変更については、必ず公式ドキュメントを確認してください
- API バージョンとエンドポイントは、時間の経過とともに変更される場合があります
- レート制限とスロットリングポリシーが適用されます
- すべての操作で、適切な認証と権限が必要です
- 一部の機能は Azure DevOps Server では利用できず、Azure DevOps Services でのみ利用できます