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

# サンプルユースケース

> ArcScript 連携を含む、複数のAPI リクエストを組み合わせたCData Arc の一般的な管理API のユースケース。

export const siteNameShort = "Arc";

このセクションでは、複数のAPI リクエストを組み合わせて実現する一般的なユースケースについて説明します。

## ファイルをワークフローに挿入する

**Files** リソースにPOST すると、特定のコネクタのSend、Receive、Sent フォルダにファイルが追加されます。ファイルをワークフローに挿入するには、そのファイルを最初に処理すべきコネクタの**Send** フォルダにPOST します。次に例を示します：

```xml theme={null}
POST http://mydomain.com:8001.com/api.rsc/files
```

```json theme={null}
{
    "ConnectorId":"myConnector",
    "Folder":"Send",
    "Filename":"test.txt",
    "Content":"VGhpcyBpcyBhIHRlc3Qu"
}
```

**Content** パラメータには、ファイルのbase64 エンコードされた内容が含まれることに注意してください。

対象のコネクタで**Send オートメーション**が有効になっている場合、ファイルは自動的に処理されます。そうでない場合は、コネクタにファイルの処理を指示するために、**sendFile** アクションへの追加の呼び出しが必要です。次に例を示します：

```xml theme={null}
POST http://mydomain.com:8001/api.rsc/sendFile
```

```json theme={null}
{
  "ConnectorId":"myConnector",
  "File":"test.txt"
}
```

## 特定のトランザクションのログファイルを取得する

**getTransactionLogs** アクションは、特定のアクションのログファイルを取得します。このアクションを呼び出すには、対象のトランザクションのMessageId を知っておく必要があります。MessageId は、まず**Transactions** リソースをクエリすることで見つけられます（Transactions リソースはトランザクションに関するメタデータを返しますが、トランザクションのログファイル自体は返しません）。

**Transactions** リソースへのGET クエリには、特定のトランザクションを識別するために必要なフィルタをすべて含める必要があります。ただし、結果セットを他のプロセスで解析して目的のトランザクションのMessageId を見つけられる場合はこの限りではありません。次に例を示します：

```xml theme={null}
GET http://mydomain.com:8001/api.rsc/transactions(connectorId='myAS2Connector',Filename='myFile.edi')
```

レスポンスのJSON ボディには、特定のトランザクションのMessageId が含まれます。このMessageId を、他の必須パラメータである**ConnectorId** および**Direction**（*Send* または*Receive*）とともに**getTransactionLogs** の呼び出しで使用します。レスポンスにログファイルの内容を含めるには、**IncludeContent** パラメータを*True* に設定してください。次に例を示します：

```xml theme={null}
POST http://mydomain.com:8001/api.rsc/getTransactionLogs
```

```json theme={null}
{
	"ConnectorId":"myConnector",
	"Direction":"Send",
	"MessageId":"message_id_from_earlier",
	"IncludeContent":"True"
}
```

レスポンスの**Content** パラメータには、base64 エンコードされたログファイルの内容が保持されます。

## {siteNameShort}Script から管理API を呼び出す

{siteNameShort}Script を使用して、管理API に**arc:call** コマンドを送信できます。各呼び出しは`api.rsc/` で始める必要があります。

この機能には次の制限が適用されます：

* OData クエリ構文はサポートされていません。
* レートリミッターは適用されません。
* スクリプトがAdmin Console から直接実行される場合、ユーザーは現在ログインしているユーザーになります。
* スクリプトがオートメーションサービスによって実行される場合、監査内のIP アドレスは127.0.0.1 になります。

### コネクタを取得する

次の例は、**connectors** [リソース](./admin-api-resources)を取得するために使用する単独の**arc:call** コマンドです：

```xml theme={null}
<arc:call op="api.rsc/connectors" httpmethod="get" authtoken="6o6B3m4r3F8z6m4R3d1k" out="o">
```

このコマンドは次の要素で構成されています：

| 要素                                   | 説明                                                                                                                              |
| ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------- |
| **op="api.rsc/connectors"**          | **op**（操作）[パラメータ](../scripting/keyword-reference/op-arc-call#パラメータ)を設定して、管理API を呼び出し（`api.rsc/` を使用）、**connectors** リソースを取得します。 |
| **httpmethod="get"**                 | コマンドを**GET** コマンドとして指定します。                                                                                                      |
| **authtoken="6o6B3m4r3F8z6m4R3d1k"** | 指定したトークンを**authtoken** パラメータに渡します。これは、**設定**ページの**ユーザー**セクションで取得できます。                                                           |
| **out="o"**                          | コマンドによって返されたコネクタを**o** に割り当てます。                                                                                                 |

次の{siteNameShort}Script コードは、この**arc:call** コマンドを使用して、既存のすべてのコネクタのリストを作成します：

```xml theme={null}
<!--Initialize item for output and filename-->
<arc:set attr="result.data" value=""/>
<arc:set attr="result.filename" value="connectors.txt"/>

<!--Empty 'in' attribute to allow global scope for connectors-->
<arc:set attr="in.in" value=""/>

<!-- List all existing connectors -->
<arc:call op="api.rsc/connectors" httpmethod="get" authtoken="YourUser:YourAdminAPIToken" out="o" in="in">
  <arc:set attr="result.data" value="[o.connectorid]([o.connectortype])\n[result.data]"/>
</arc:call>

<!--Push to output-->
<arc:push item="result"/>
```

### コネクタを作成および変更する

次の例は、フロー内に新しい**Script** コネクタを作成するために、管理API に**POST** コマンドを発行します：

```xml theme={null}
<arc:set attr="new.connectorid" value="Script1"/>
<arc:set attr="new.connectortype" value="Script"/>
<arc:call op="api.rsc/connectors" httpmethod="post" authtoken="test0:8s9T7b7m5Y5k3i5P2s6x" in="new">
</arc:call>
```

この新しいコネクタが作成された後、管理API にコマンドを発行して、新しく作成されたScript コネクタの**LogLevel** 値を取得できます：

```xml theme={null}
<arc:set attr="read.connectorid" value="Script1"/>
<arc:call op="api.rsc/connectors" httpmethod="get" authtoken="test0:8s9T7b7m5Y5k3i5P2s6x" in="read" out="o">
  <arc:set attr="result.new:old_loglevel" value="[o.loglevel]" />
</arc:call>
```

また、**PUT** コマンドでScript コネクタの**LogLevel** を更新することもできます：

```xml theme={null}
<arc:set attr="update.connectorid" value="Script1"/>
<arc:set attr="update.loglevel" value="Debug"/>

<arc:call op="api.rsc/connectors" httpmethod="put" authtoken="test0:8s9T7b7m5Y5k3i5P2s6x" in="update" out="o">
</arc:call>
```
