Skip to content

抽出を取得

GET /v1/extractions/{id}

IDで単一の抽出レコードを取得します。このエンドポイントは主に、非同期抽出の結果をポーリングするために使用されます。

試してみる

このエンドポイントを Swagger UI でインタラクティブにテストできます。

認証が必要です

Authorization ヘッダーにAPIキーを含めてください。

リクエスト

ヘッダー

ヘッダー必須
AuthorizationBearer <token>はい

パスパラメータ

パラメータ必須説明
idstringはい抽出を実行エンドポイントから返された抽出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 オブジェクトが格納されています。

フィールド

各フィールドは抽出を実行のレスポンスと同じです。

フィールド説明
idstring一意の抽出ID。
userIdstringこの抽出を所有するユーザーのID。
templateIdstring抽出に使用されたテンプレートのID。
templateNamestring使用されたテンプレートの表示名。
fileNamestringアップロードされたドキュメントの元のファイル名。
status"processing" | "completed" | "failed"現在の抽出ステータス。
extractedDataobject | nullテンプレートフィールドに一致する抽出データ。処理中または失敗した場合は null
errorstring | null失敗した場合のエラーメッセージ。それ以外は null
variablesVariable[]抽出中に使用されたテンプレート変数定義の配列。
source"dashboard" | "api"抽出がトリガーされた方法。
runIdstring | null指定された場合のバッチ実行ID。
processingTimeMsnumber | null処理にかかった合計時間(ミリ秒)。処理中の場合は null
createdAtstring抽出が作成された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秒以内に完了します。

エラー

ステータスコード説明
401UNAUTHORIZEDAPIキー/トークンが欠落、無効、または期限切れです。
403FORBIDDENこの抽出は別のユーザーに属しています。
404NOT_FOUND指定されたIDの抽出が存在しません。

DocMap API ドキュメント