> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 単一の API コールでドキュメントを処理する

> ABBYY Vantage で、1 回の統合された API コールによりドキュメントを処理します。Skill の一覧の取得、トランザクションの作成と開始、ステータスの監視、結果ファイルのダウンロードを行います。

export const VantageRegion = ({children}) => {
  const STORAGE_KEY = "abbyy.vantage.region";
  const REGIONS = [{
    code: "eu",
    label: "Europe"
  }, {
    code: "us",
    label: "North America"
  }, {
    code: "au",
    label: "Australia / Asia-Pacific"
  }];
  const [region, setRegion] = useState("eu");
  const [open, setOpen] = useState(false);
  const containerRef = useRef(null);
  const dropdownRef = useRef(null);
  function safeGetSavedRegion() {
    try {
      const saved = typeof window !== "undefined" ? window.localStorage.getItem(STORAGE_KEY) : null;
      const valid = new Set(REGIONS.map(r => r.code));
      return saved && valid.has(saved) ? saved : "eu";
    } catch {
      return "eu";
    }
  }
  function safeSetSavedRegion(code) {
    try {
      if (typeof window !== "undefined") {
        window.localStorage.setItem(STORAGE_KEY, code);
      }
    } catch {}
  }
  function dispatchRegionChanged(code) {
    try {
      if (typeof window !== "undefined") {
        window.dispatchEvent(new CustomEvent("abbyy:region-changed", {
          detail: {
            code
          }
        }));
      }
    } catch {}
  }
  function replaceRegionInString(text, currentRegion) {
    if (typeof text !== "string") return text;
    const hostRegex = /https:\/\/vantage-(eu|us|au)\.abbyy\.com/gi;
    const tokenRegex = /https:\/\/vantage-\[region\]\.abbyy\.com/gi;
    const bareHostRegex = /vantage-(eu|us|au)\.abbyy\.com/gi;
    const bareTokenRegex = /vantage-\[region\]\.abbyy\.com/gi;
    return text.replace(hostRegex, `https://vantage-${currentRegion}.abbyy.com`).replace(tokenRegex, `https://vantage-${currentRegion}.abbyy.com`).replace(bareHostRegex, `vantage-${currentRegion}.abbyy.com`).replace(bareTokenRegex, `vantage-${currentRegion}.abbyy.com`);
  }
  useEffect(() => {
    setRegion(safeGetSavedRegion());
  }, []);
  useEffect(() => {
    const root = containerRef.current;
    if (!root) return;
    const anchors = root.querySelectorAll("a[href]");
    anchors.forEach(a => {
      const href = a.getAttribute("href");
      if (href) {
        const next = replaceRegionInString(href, region);
        if (next !== href) {
          a.setAttribute("href", next);
        }
      }
    });
    const walker = typeof document !== "undefined" ? document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null) : null;
    if (walker) {
      const toUpdate = [];
      let node = walker.nextNode();
      while (node) {
        const updated = replaceRegionInString(node.nodeValue, region);
        if (updated !== node.nodeValue) {
          toUpdate.push([node, updated]);
        }
        node = walker.nextNode();
      }
      toUpdate.forEach(([textNode, value]) => {
        textNode.nodeValue = value;
      });
    }
  }, [region, children]);
  useEffect(() => {
    const root = containerRef.current;
    if (!root) return;
    const anchors = root.querySelectorAll("a[href]");
    anchors.forEach(a => {
      a.style.fontWeight = "600";
      a.style.textDecoration = "underline";
      a.style.textUnderlineOffset = "2px";
    });
  }, [region, children]);
  useEffect(() => {
    const onRegionChanged = evt => {
      const code = evt && evt.detail && evt.detail.code;
      if (!code || code === region) return;
      setRegion(code);
    };
    if (typeof window !== "undefined") {
      window.addEventListener("abbyy:region-changed", onRegionChanged);
    }
    return () => {
      if (typeof window !== "undefined") {
        window.removeEventListener("abbyy:region-changed", onRegionChanged);
      }
    };
  }, [region]);
  useEffect(() => {
    const onClickAway = e => {
      if (!dropdownRef.current) return;
      if (!dropdownRef.current.contains(e.target)) {
        setOpen(false);
      }
    };
    document.addEventListener("click", onClickAway, true);
    return () => document.removeEventListener("click", onClickAway, true);
  }, []);
  const onSelect = code => {
    setRegion(code);
    safeSetSavedRegion(code);
    dispatchRegionChanged(code);
    setOpen(false);
  };
  const current = REGIONS.find(r => r.code === region) || REGIONS[0];
  return <div className="not-prose">
      <div className="mb-4 inline-flex items-center gap-2" ref={dropdownRef}>
        <span className="text-sm text-zinc-950/80 dark:text-white/80">Tenant Region:</span>
        <div className="relative">
          <button type="button" aria-haspopup="listbox" aria-expanded={open ? "true" : "false"} onClick={() => setOpen(v => !v)} className="h-8 px-3 rounded-md bg-zinc-900/5 dark:bg-white/5 border border-zinc-950/20 dark:border-white/20 text-sm inline-flex items-center gap-2">
            <span className="text-zinc-950 dark:text-white">{current.label}</span>
            <svg width="8" height="24" viewBox="0 -9 3 24" className="transition-transform text-gray-400 overflow-visible dark:text-gray-600 ml-auto" style={{
    transform: open ? "rotate(270deg)" : "rotate(90deg)"
  }}>
              <path d="M0 0L3 3L0 6" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round"></path>
            </svg>
          </button>
          {open ? <div role="listbox" className="absolute z-50 left-full top-0 ml-2 w-56 rounded-xl border border-zinc-950/20 dark:border-white/20 bg-white dark:bg-zinc-900 shadow-lg p-2">
              {REGIONS.map(r => {
    const selected = r.code === region;
    return <button key={r.code} type="button" role="option" aria-selected={selected ? "true" : "false"} onClick={() => onSelect(r.code)} className={"w-full flex items-center justify-between px-3 py-2 rounded-lg text-sm hover:bg-zinc-950/5 dark:hover:bg-white/10 text-zinc-950 dark:text-white" + (selected ? " font-medium" : "")}>
                    <span style={selected ? {
      color: "#ff2038"
    } : undefined}>{r.label}</span>
                    <span className={selected ? "ml-3" : "ml-3 invisible"} style={selected ? {
      color: "#ff2038"
    } : undefined}>✓</span>
                  </button>;
  })}
            </div> : null}
        </div>
      </div>
      <div ref={containerRef} className="prose dark:prose-invert max-w-none">{children}</div>
    </div>;
};

単一の API コールを使用してドキュメントを処理する (トランザクションの作成、ファイルのアップロード、およびトランザクションの開始) ための一般的なシナリオは、次の手順で構成されます。

1. [利用可能なすべての Skill の一覧を取得する](#receiving-a-list-of-all-available-skills)
2. [トランザクションを作成して開始する](#creating-and-starting-a-transaction)
3. [トランザクションのステータスを監視する](#monitoring-the-transaction-status)
4. [ソースファイルと結果ファイルをダウンロードする](#downloading-source-files-and-result-files)

サーバーへの各リクエストには、認証情報を含める必要があります。詳細は、[Authentication](/ja/vantage/developer/authentication/authentication) を参照してください。

このシナリオは、サイズが 30 MB 未満のファイルが 1 つだけであり、そのファイル内の画像を編集する必要がない場合に使用してください。

<div id="receiving-a-list-of-all-available-skills">
  ### 利用可能なすべてのSkillの一覧を取得する
</div>

これを行うには、`skills` リソースに `GET` リクエストを送信します。

<VantageRegion>
  ```
  GET https://vantage-us.abbyy.com/api/publicapi/v1/skills
  ```
</VantageRegion>

次のコマンドを実行します。

**Windows の場合:**

<VantageRegion>
  ```bash theme={null}
  curl -X GET "https://vantage-us.abbyy.com/api/publicapi/v1/skills" \
  -H "Authorization: Bearer token"
  ```
</VantageRegion>

**Linux の場合:**

<VantageRegion>
  ```bash theme={null}
  curl -X GET 'https://vantage-us.abbyy.com/api/publicapi/v1/skills' \
  -H 'Authorization: Bearer token'
  ```
</VantageRegion>

レスポンスには、次のような JSON ファイルが含まれます。

**レスポンス:**

```json theme={null}
[
   {
      "id": "Receipt",
      "name": "Receipt",
      "type": "Document"
   },
   {
      "id": "c4b26798-07cb-11eb-adc1-0242ac120002",
      "name": "NewClassifier",
      "type": "Classification"
   },
   {
      "id": "c4b26798-07cb-11eb-adc1-0242ac120002",
      "name": "Invoice",
      "type": "Document"
   }
]
```

使用するSkill識別子を指定します。Skillの詳細な説明は、組み込みSkillに記載されています。

<div id="creating-and-starting-a-transaction">
  ### トランザクションの作成と開始
</div>

指定した Skill でアップロード済みのファイルを処理するトランザクションを作成して開始するには、次の `POST` リクエストを `transactions/launch?skillId=<skill-id>` リソースに送信します。

<VantageRegion>
  ```
  POST https://vantage-us.abbyy.com/api/publicapi/v1/transactions/launch?skillId=skill-id
  ```
</VantageRegion>

これにより、新しいトランザクションが作成され、すぐに開始されます。

次のコマンドを実行します。

**Windows の場合:**

<VantageRegion>
  ```bash theme={null}
  curl -X POST "https://vantage-us.abbyy.com/api/publicapi/v1/transactions/launch?skillId=skill-id" \
  -H "accept: text/plain" \
  -H "Authorization: Bearer token" \
  -H "Content-Type: multipart/form-data" \
  -F "Files=@1page_invoiceUS_86.pdf;type=application/pdf"
  ```
</VantageRegion>

**Linux の場合:**

<VantageRegion>
  ```bash theme={null}
  curl -X POST 'https://vantage-us.abbyy.com/api/publicapi/v1/transactions/launch?skillId=skill-id' \
  -H 'accept: text/plain' \
  -H 'Authorization: Bearer token' \
  -H 'Content-Type: multipart/form-data' \
  -F 'Files=@1page_invoiceUS_86.pdf;type=application/pdf'
  ```
</VantageRegion>

<Info>
  ファイルを Vantage にアップロードする際、ファイル名に含まれる次の文字はすべてアンダースコアに置き換えられます: `:/?#[]@!$&'()*+,;=\`。変更後のファイル名は、Vantage API と Skill Monitor の両方に表示されます。
</Info>

<div id="monitoring-the-transaction-status">
  ### トランザクションのステータスを監視する
</div>

短いタイムアウトを設定したループを使用してトランザクションのステータス監視を開始するには (ステータス確認の頻度は 1 秒に 1 回を超えないことを推奨します) 、リクエスト URI にトランザクション識別子を指定して、`transactions/<transaction_id>` リソースに `GET` リクエストを送信します。

<VantageRegion>
  ```
  GET https://vantage-us.abbyy.com/api/publicapi/v1/transactions/transaction-id
  ```
</VantageRegion>

次のコマンドを実行します。

**Windows の場合:**

<VantageRegion>
  ```bash theme={null}
  curl -X GET "https://vantage-us.abbyy.com/api/publicapi/v1/transactions/transaction-id" \
  -H "Authorization: Bearer token"
  ```
</VantageRegion>

**Linux の場合:**

<VantageRegion>
  ```bash theme={null}
  curl -X GET 'https://vantage-us.abbyy.com/api/publicapi/v1/transactions/transaction-id' \
  -H 'Authorization: Bearer token'
  ```
</VantageRegion>

レスポンスは次のようになります。

**レスポンス:**

<VantageRegion>
  ```json theme={null}
  {
     "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
     "status": "Processing", 
     "manualReviewLink": "https://vantage-us.abbyy.com/api/publicapi/v1/verify?documentIds=9838448d-72ae-4e9a-b071-2bb16f732e46",
     "sourceFiles": [
        {
           "id": "7b2eed6f-3fdd-43b9-a178-7211d0a8d5bb",
           "name": "Invoice07.JPG"
        }
     ]
  }
  ```
</VantageRegion>

レスポンスでは、次の点に注意してください。

* `status` キーの値が `Processing` の場合、結果はまだ準備できていません。トランザクションのステータスが `Processed` に変わると、結果をダウンロードできるようになります。
* `manualReviewLink` キーには、手動確認クライアントの Web インターフェイスへのリンクと、手動確認が必要な場合は Vantage の access token が含まれます。このリンクとトークンを使用すると、特定のトランザクションの分類結果およびフィールド抽出結果を確認して修正できます。確認が完了するまで、`status` キーの値は `Processing` に設定されます。提供されるリンクの有効期間は 168 時間です。期限切れ後は、同じ方法でさらに 168 時間有効な新しいリンクを作成して取得する必要があります。詳細は [手動確認の統合](/ja/vantage/developer/integrating-manual-review) を参照してください。

<Info>
  このリンクを使用して認証されたユーザーは、他のドキュメントやトランザクションを表示または変更できません。
</Info>

Document skill の場合、レスポンスは次のようになります。

**レスポンス:**

<VantageRegion>
  ```json theme={null}
  {
     "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
     "status": "Processed",
     "documents": [
        {
           "id": "9838448d-72ae-4e9a-b071-2bb16f732e46",
           "resultFiles": [
              {
                 "fileId": "3a3e6245-48e1-489a-9fef-a10b5ba28515",
                 "type": "Json"
              }
           ],
           "businessRulesErrors": []
        }
     ],
     "sourceFiles": [
        {
           "id": "7b2eed6f-3fdd-43b9-a178-7211d0a8d5bb",
           "name": "Invoice07.jpg"
        }
     ]
  }
  ```
</VantageRegion>

`documents` array では、各ドキュメントに `resultFiles` array があります。この array を使用して `fileId` の値を取得します。出力ファイルの形式は、使用する skill によって決まります。現在、すべての Skill は [JSON 形式](/ja/vantage/developer/output/json/json-output) で抽出されたフィールドを返します。

分類スキルの場合、ドキュメントの処理後に受信するレスポンスは次のようになります。

**レスポンス:**

<VantageRegion>
  ```json theme={null}
  {
     "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
     "status": "Processed",
     "documents": [
        {
           "id": "9838448d-72ae-4e9a-b071-2bb16f732e46",
           "classification": {
              "isResultClassConfident": true,
              "resultClass": "Invoice",
              "classConfidences": [
                 {
                    "class": "Invoice",
                    "confidence": 89
                 },
                 {
                    "class": "PurchaseOrder",
                    "confidence": 32
                 }
              ]
           }
        }
     ],
     "sourceFiles": [
        {
           "id": "7b2eed6f-3fdd-43b9-a178-7211d0a8d5bb",
           "name": "Invoice07.jpg"
        }
     ]
  }
  ```
</VantageRegion>

`resultClass` キーからドキュメントのクラスを取得し、`confidence` キーで各候補クラスの信頼度を確認します。

Process skill の場合、レスポンスには、Process skill で利用可能なステージに応じて、Document skill および分類スキルで返される情報の全部または一部が含まれることがあります。

<div id="downloading-source-files-and-result-files">
  ### ソースファイルと結果ファイルのダウンロード
</div>

処理の完了後、2 種類のファイルをダウンロードできます。

* **ソースファイル** — アップロードした元のファイルです。元のバイナリ形式で返されます。
* **結果ファイル** — 処理結果です。既定では、抽出データが [JSON 形式](/ja/vantage/developer/output/json/json-output) で返されます (出力形式は Skill で設定されます)。

<Info>
  ソースファイルと結果ファイルでは、それぞれ異なる endpoint と異なるファイル識別子を使用します。

  * **ソースファイル** — `GET transactions/<transaction-id>/documents/<document-id>/sourceFiles/<file-id>/download`。ファイル ID は、`GET transactions/<transaction-id>/documents` のレスポンス (`sourceFiles[].id`) から取得します。
  * **結果ファイル** — `GET transactions/<transaction-id>/files/<file-id>/download`。ファイル ID は、[transaction status](#monitoring-the-transaction-status) のレスポンス内の `resultFiles` 配列 (`documents[].resultFiles[].fileId`) から取得します。
</Info>

識別子付きのドキュメント一覧を取得するには、`transactions/<transaction-id>/documents` リソースに `GET` リクエストを送信し、トランザクション識別子を指定します。

<VantageRegion>
  ```
  GET https://vantage-us.abbyy.com/api/publicapi/v1/transactions/transaction-id/documents
  ```
</VantageRegion>

次のコマンドを実行します。

**Windows の場合:**

<VantageRegion>
  ```bash theme={null}
  curl -X GET "https://vantage-us.abbyy.com/api/publicapi/v1/transactions/transaction-id/documents" \
  -H "Authorization: Bearer token"
  ```
</VantageRegion>

**Linux の場合:**

<VantageRegion>
  ```bash theme={null}
  curl -X GET 'https://vantage-us.abbyy.com/api/publicapi/v1/transactions/transaction-id/documents' \
  -H 'Authorization: Bearer token'
  ```
</VantageRegion>

<div id="source-files">
  #### ソースファイル
</div>

必要なソースファイルをダウンロードするには、`transactions/<transaction-id>/documents/<document-id>/sourceFiles/<file-id>/download` リソースに `GET` リクエストを送信し、トランザクション、ドキュメント、およびファイルの識別子 (直前のレスポンスから取得) を指定します。

<VantageRegion>
  ```
  GET https://vantage-us.abbyy.com/api/publicapi/v1/transactions/transaction-id/documents/document-id/sourceFiles/file-id/download
  ```
</VantageRegion>

次のコマンドを実行します。

**Windows の場合:**

<VantageRegion>
  ```bash theme={null}
  curl -X GET "https://vantage-us.abbyy.com/api/publicapi/v1/transactions/transaction-id/documents/document-id/sourceFiles/file-id/download" \
  -H "Authorization: Bearer token"
  ```
</VantageRegion>

**Linux の場合:**

<VantageRegion>
  ```bash theme={null}
  curl -X GET 'https://vantage-us.abbyy.com/api/publicapi/v1/transactions/transaction-id/documents/document-id/sourceFiles/file-id/download' \
  -H 'Authorization: Bearer token'
  ```
</VantageRegion>

レスポンスにはファイルがバイナリ形式で含まれます。すべてのソースファイルについて、この手順を繰り返します。

<div id="result-files">
  #### 結果ファイル
</div>

結果ファイルをダウンロードするには、`transactions/<transaction-id>/files/<file-id>/download` リソースに `GET` リクエストを送信し、トランザクション識別子と結果ファイルの `fileId` を指定します。`fileId` は、[トランザクションステータスの監視](#monitoring-the-transaction-status) 時に返される `resultFiles` 配列から取得します (各エントリには `fileId` と `type` (`Json` など) が含まれます) 。

<VantageRegion>
  ```
  GET https://vantage-us.abbyy.com/api/publicapi/v1/transactions/transaction-id/files/file-id/download
  ```
</VantageRegion>

次のコマンドを実行します。

**Windows の場合:**

<VantageRegion>
  ```bash theme={null}
  curl -X GET "https://vantage-us.abbyy.com/api/publicapi/v1/transactions/transaction-id/files/file-id/download" \
  -H "Authorization: Bearer token"
  ```
</VantageRegion>

**Linux の場合:**

<VantageRegion>
  ```bash theme={null}
  curl -X GET 'https://vantage-us.abbyy.com/api/publicapi/v1/transactions/transaction-id/files/file-id/download' \
  -H 'Authorization: Bearer token'
  ```
</VantageRegion>
