抽出を取得
GET /v1/extractions/{id}
IDで単一の抽出レコードを取得します。このエンドポイントは主に、非同期抽出の結果をポーリングするために使用されます。
試してみる
このエンドポイントを Swagger UI でインタラクティブにテストできます。
認証が必要です
Authorization ヘッダーにAPIキーを含めてください。
リクエスト
ヘッダー
| ヘッダー | 値 | 必須 |
|---|---|---|
Authorization | Bearer <token> | はい |
パスパラメータ
| パラメータ | 型 | 必須 | 説明 |
|---|---|---|---|
id | string | はい | 抽出を実行エンドポイントから返された抽出ID。 |
コード例
bash
curl https://api.docmap.io/v1/extractions/extract_9k2m4n6p8q0r1s3t \
-H "Authorization: Bearer dm_live_abc123def456ghi789jkl012mno345"typescript
const apiKey = process.env.DOCMAP_API_KEY
const response = await fetch(
'https://api.docmap.io/v1/extractions/extract_9k2m4n6p8q0r1s3t',
{ headers: { 'Authorization': `Bearer ${apiKey}` } },
)
const { data } = await response.json()
console.log(data.status, data.extractedData)python
import requests
api_key = "dm_live_abc123def456ghi789jkl012mno345"
response = requests.get(
"https://api.docmap.io/v1/extractions/extract_9k2m4n6p8q0r1s3t",
headers={"Authorization": f"Bearer {api_key}"},
)
data = response.json()["data"]
print(data["status"], data["extractedData"])レスポンス
ステータス: 200 OK
レスポンスボディには、単一の抽出レコードを含む data オブジェクトが格納されています。
フィールド
各フィールドは抽出を実行のレスポンスと同じです。
| フィールド | 型 | 説明 |
|---|---|---|
id | string | 一意の抽出ID。 |
userId | string | この抽出を所有するユーザーのID。 |
templateId | string | 抽出に使用されたテンプレートのID。 |
templateName | string | 使用されたテンプレートの表示名。 |
fileName | string | アップロードされたドキュメントの元のファイル名。 |
status | "processing" | "completed" | "failed" | 現在の抽出ステータス。 |
extractedData | object | null | テンプレートフィールドに一致する抽出データ。処理中または失敗した場合は null。 |
error | string | null | 失敗した場合のエラーメッセージ。それ以外は null。 |
variables | Variable[] | 抽出中に使用されたテンプレート変数定義の配列。 |
source | "dashboard" | "api" | 抽出がトリガーされた方法。 |
runId | string | null | 指定された場合のバッチ実行ID。 |
processingTimeMs | number | null | 処理にかかった合計時間(ミリ秒)。処理中の場合は null。 |
createdAt | string | 抽出が作成されたISO 8601タイムスタンプ。 |
例(完了)
json
{
"data": {
"id": "extract_9k2m4n6p8q0r1s3t",
"userId": "uid_a1b2c3d4e5f6",
"templateId": "tmpl_8f3a2b1c4d5e6f7g",
"templateName": "Invoice Template",
"fileName": "invoice-2024-001.pdf",
"status": "completed",
"extractedData": {
"vendor_name": "Acme Corp",
"invoice_number": "INV-2024-001",
"total_amount": 1250.00
},
"error": null,
"variables": [
{
"name": "vendor_name",
"type": "string",
"description": "Name of the vendor or supplier"
}
],
"source": "api",
"runId": null,
"processingTimeMs": 3842,
"createdAt": "2024-11-20T14:30:00.000Z"
}
}例(処理中)
json
{
"data": {
"id": "extract_9k2m4n6p8q0r1s3t",
"userId": "uid_a1b2c3d4e5f6",
"templateId": "tmpl_8f3a2b1c4d5e6f7g",
"templateName": "Invoice Template",
"fileName": "invoice-2024-001.pdf",
"status": "processing",
"extractedData": null,
"error": null,
"variables": [
{
"name": "vendor_name",
"type": "string",
"description": "Name of the vendor or supplier"
}
],
"source": "api",
"runId": null,
"processingTimeMs": null,
"createdAt": "2024-11-20T14:30:00.000Z"
}
}ポーリングパターン
非同期抽出を使用する場合、ステータスが "processing" でなくなるまでこのエンドポイントをポーリングします:
typescript
async function pollExtraction(extractionId: string, apiKey: string) {
const maxAttempts = 30
const intervalMs = 2000
for (let i = 0; i < maxAttempts; i++) {
const response = await fetch(
`https://api.docmap.io/v1/extractions/${extractionId}`,
{ headers: { 'Authorization': `Bearer ${apiKey}` } },
)
const { data } = await response.json()
if (data.status !== 'processing') {
return data
}
await new Promise((resolve) => setTimeout(resolve, intervalMs))
}
throw new Error('Extraction timed out')
}python
import time
import requests
def poll_extraction(extraction_id: str, api_key: str):
max_attempts = 30
interval_s = 2
for _ in range(max_attempts):
response = requests.get(
f"https://api.docmap.io/v1/extractions/{extraction_id}",
headers={"Authorization": f"Bearer {api_key}"},
)
data = response.json()["data"]
if data["status"] != "processing":
return data
time.sleep(interval_s)
raise TimeoutError("Extraction timed out")TIP
ポーリング間隔は2秒が推奨されます。ほとんどの抽出は5〜30秒以内に完了します。
エラー
| ステータス | コード | 説明 |
|---|---|---|
401 | UNAUTHORIZED | APIキー/トークンが欠落、無効、または期限切れです。 |
403 | FORBIDDEN | この抽出は別のユーザーに属しています。 |
404 | NOT_FOUND | 指定されたIDの抽出が存在しません。 |
