> ## 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.

# 登録パラメータ の使用

> ABBYY Vantage の登録パラメータ を使用して、API トランザクションとともにキーと値のメタデータを受け渡し、フィルタリング、レポート作成、およびカスタム処理に利用します。

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>;
};

<div id="using-registration-parameters">
  ## 登録パラメータの使用
</div>

トランザクションおよびファイル登録パラメータは、追加のユーザー情報 (例：クライアント名、ドキュメントタイプ、ファイルソース情報) を提供するために設計された、キーと値の文字列ペアで構成されるParameterです。これらはトランザクションまたはトランザクション内のdocumentsと共に処理のために渡されます。これらのParameterはすべてのワーカーで利用可能であり、さまざまな本番環境のシナリオで使用できます：

* ABBYY Vantage を使用するプログラムは、レポート作成やカスタム処理手順の作成 (例: 顧客ごとに取引先データ カタログをフィルタリングするなど) の目的で、各トランザクションにエンドクライアント属性を付与します。
* Scanning Station クライアント (またはトランザクションの別の送信元) は、Document バッチの登録パラメータ (外部相関 ID など) を渡すことができます。

登録パラメータは Vantage API を使用して設定できます。

1. 空のトランザクションを作成する場合や `launch` メソッドを使用してトランザクションを初期化する場合は、以下の例のように `transactions` リソースに POST リクエストを送信します。

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

or

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

リクエストボディで登録パラメータを指定し、次のコマンドを実行します:

<VantageRegion>
  ```bash theme={null}
  curl -X POST "https://vantage-us.abbyy.com/api/publicapi/v1/transactions" \
  -H "Authorization: Bearer token" \
  -H "Content-Type: application/json" \
  -d "{
    \"skillId\": \"123\",
    \"registrationParameters\": [
      {
        \"key\": \"key1\",
        \"value\": \"value1\"
      }
    ]
  }"
  ```
</VantageRegion>

2. トランザクションまたは Document にファイルをアップロードするには、以下の例のように `transactions/<transaction-id>/files` リソースに POST リクエストを送信します。

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

リクエストボディで登録パラメータを指定し、次のコマンドを実行します:

<VantageRegion>
  ```bash theme={null}
  curl -X POST "https://vantage-us.abbyy.com/api/publicapi/v1/transactions/transaction-id/files/" \
  -H "Authorization: Bearer token" \
  -F "Files=@Invoice07.jpg; type=image/jpeg" \
  -F 'Model={
    "files": [
      {
        "index": 0,
        "imageProcessingOptions": {
          "autoCrop": "Default",
          "autoOrientation": "Default"
        },
        "registrationParameters": [
          {
            "key": "key1",
            "value": "value1"
          }
        ]
      }
    ]
  }'
  ```
</VantageRegion>

<Warning>
  key-value 型の Parameter は最大 10 個まで設定でき、key の Parameter には最大 128 文字、value の Parameter には最大 256 文字まで指定できます。これらの Parameter の値は、一度設定すると変更できません。
</Warning>

登録パラメータの値を読み取ることができます:

* カスタム アクティビティ スクリプト内では、
* Output アクティビティの External Export スクリプトで、
* ビジネス ルール内で

Vantage APIを使用して、登録パラメータの値を次のように取得できます:

1. `transactions/<transaction-id>/registrationParameters` リソースの `registrationParameters` メソッドを呼び出すことで：

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

レスポンスは以下のようになります:

```json theme={null}
[
  {
    "key": "key1",
    "value": "value1"
  }
]
```

2. `transactions/<transaction-id>/files/<file-id>/download` リソースに対して `download` メソッド呼び出しを使用し、アップロードされるファイルと共に JSON 形式で値を取得する方法:

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