使用例
Version 22.0.8473
Version 22.0.8473
使用例
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:
POST http://mydomain.com:8001.com/api.rsc/files
{
"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:
POST http://mydomain.com:8001/api.rsc/sendFile
{
"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:
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:
POST http://mydomain.com:8001/api.rsc/getTransactionLogs
{
"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 ArcScript
You can use ArcScript 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 arccall command used to retrieve the connectors resource:
<arccall op="api.rsc/connectors" httpmethod="get" authtoken="6o6B3m4r3F8z6m4R3d1k" out="o">
This command consists of the following components:
- op=”api.rsc/connectors” Sets the op (operation) parameter 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 ArcScript code uses this arccall command to create a list of all existing connectors:
<!-- Define an empty attribute to store a comma separated list of connectors and their types -->
<arcset attr="result.connectors" value=""/>
<!-- List all existing connectors -->
<arccall op="api.rsc/connectors" httpmethod="get" authtoken="test0:8s9T7b7m5Y5k3i5P2s6x" out="o">
<arcset attr="result.connectors" value="[o.connectorid]([o.connectortype]),[result.connectors]"/>
</arccall>
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:
<arcset attr="new.connectorid" value="Script1"/>
<arcset attr="new.connectortype" value="Script"/>
<arccall op="api.rsc/connectors" httpmethod="post" authtoken="test0:8s9T7b7m5Y5k3i5P2s6x" in="new">
</arccall>
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:
<arcset attr="read.connectorid" value="Script1"/>
<arccall op="api.rsc/connectors" httpmethod="get" authtoken="test0:8s9T7b7m5Y5k3i5P2s6x" in="read" out="o">
<arcset attr="result.new:old_loglevel" value="[o.loglevel]" />
</arccall>
You can also update the LogLevel of the Script connector with a PUT command:
<arcset attr="update.connectorid" value="Script1"/>
<arcset attr="update.loglevel" value="Debug"/>
<arccall op="api.rsc/connectors" httpmethod="put" authtoken="test0:8s9T7b7m5Y5k3i5P2s6x" in="update" out="o">
</arccall>