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

# Example Use Cases

> Common Admin API use cases in CData Arc that combine multiple API requests, including ArcScript integration.

export const siteNameShort = "Arc";

This section outlines common use cases that require a combination of API requests to accomplish.

## Insert a File into the Workflow

POSTing to the **Files** Resource adds a file to the Send, Receive, or Sent folders for a particular connector. To insert a file into the workflow, POST the file to the **Send** folder for the first connector that should process the file. For example:

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

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

Note that the **Content** parameter includes the base64-encoded content of the file.

If the target connector has **Send Automation** enabled, the file will automatically be processed. Otherwise, an additional call to the **sendFile** Action is required to instruct the connector to process the file. For example:

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

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

## Retrieve the Log File for a Specific Transaction

The **getTransactionLogs** Action retrieves the log file for a specific action. Invoking this Action requires knowing the MessageId for the relevant transaction. The MessageId can be found by querying the **Transactions** Resource first (the Transactions Resource returns metadata about the transaction, but not the transaction log file itself).

The GET query to the **Transactions** Resource should include any filters necessary to identify the specific transaction unless the result set can be parsed by some other process to find the MessageId for the desired transaction. For example:

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

The JSON body of the response will include the MessageId for the specific transaction. Use this MessageId in the **getTransactionLogs** call along with the other required parameters **ConnectorId** and **Direction** (*Send* or *Receive*). The **IncludeContent** parameter should be set to *True* to include the contents of the log file in the response. For example:

```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"
}
```

The **Content** parameter of the response will hold the base64-encoded log file contents.

## Call Admin API from {siteNameShort}Script

You can use {siteNameShort}Script to send **arc:call** commands to the Admin API. Each call must start with `api.rsc/`.

The following limitations apply to this feature:

* OData query syntax is not supported.
* Rate limiters are not applied.
* If the script is executed from the Admin Console directly, the user will be the currently logged-in user.
* If the script is executed by an automation service, the IP address in an audit will be 127.0.0.1.

### Retrieve Connectors

The following example is an isolated **arc:call** command used to retrieve the **connectors** [resource](./admin-api-resources):

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

This command consists of the following components:

| Component                            | Description                                                                                                                                                                       |
| ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **op="api.rsc/connectors"**          | Sets the **op** (operation) [parameter](../scripting/keyword-reference/op-arc-call#parameters) to call the Admin API (using `api.rsc/`) and retrieve the **connectors** resource. |
| **httpmethod="get"**                 | Designates the command as a **GET** command.                                                                                                                                      |
| **authtoken="6o6B3m4r3F8z6m4R3d1k"** | Passes the specified token to the **authtoken** parameter. This can be obtained on the **Settings** page under the **Users** section.                                             |
| **out="o"**                          | Assigns the connector returned by the command to **o**.                                                                                                                           |

The following {siteNameShort}Script code uses this **arc:call** command to create a list of all existing connectors:

```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"/>
```

### Create and Modify a Connector

The following example issues a **POST** command to the Admin API to create a new **Script** connector in the flow:

```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>
```

After this new connector is created, you can issue a command to the Admin API to get the **LogLevel** value of the newly-created Script connector:

```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>
```

You can also update the **LogLevel** of the Script connector with a **PUT** command:

```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>
```
