Send to REST Service Action
Infiniti includes the ability to send form data to a REST service, via the "Send to REST Service" action. The action allows you to specify:
- Endpoint URL
- HTTP method (defaults to POST)
- Basic Auth username and password
- Custom Headers
- Access token
- Send as multi-part (true/false)
- Body document (JSON or XML)
The action provides two outputs:
- Status (the HTTP response such as "OK", "CREATED")
- Response (the HTTP response body, if any)
1. Basic Action configuration
The Send to REST Service action can be added to a project in Design, either on the Finish page or as part of a Workflow transition.
The input parameters for the action are as follows:
Input Name | Description | Required? |
---|---|---|
URL | The endpoint of the service | Yes |
HTTP Method | The HTTP method to use for the request. Supported values are "GET", "POST", "PUT", and "PATCH". Defaults to "POST" if not specified. | No |
Basic Auth Username | The username to supply for HTTP Basic Auth, if required by the service. | No |
Basic Auth Password | The password to supply for HTTP Basic Auth, if required by the service. | No |
Custom Headers | Any custom headers (such as an authorisation token or other special data) to supply as part of the request. Multiple headers can be specified if necessary. | No |
Send Access Token | True/false representing whether to send the user's SSO access token (from e.g. a SAML identity) as an Authorization header for the request. | No |
Send as Multipart | Whether to construct a multi-part request (for example, if the body document will exceed the service's maximum request length). | No |
2. Sending a body document
The action accepts an optional body document to be sent as the content of the request. If required by the service, this should be included as a template within the project and attached as a Action Document.
Document type
The Action will automatically detect the type of document supplied (JSON or XML) and configure the request headers appropriately.
Document counts
Only a single JSON or XML body document can be supplied. If more than one is supplied, either explicitly through "Custom" action document settings, or implicitly through multiple templates being present in the project and not deactivated by conditions, the REST Service action will throw an error.
3. Custom headers
Custom headers, if required by the service, can be supplied using the Custom Header action parameter. Zero or more headers may be specified as a key-value pair, and will be sent as part of the REST request.
4. Using the Status and Response outputs
The Status and Response outputs can be referenced by subsequent Actions, for example to drive the display of a message to the user, or to store the response body in a database for later reference.
5. Sample project
The following section will walk through constructing a project to send some REST data to the https://jsonplaceholder.typicode.com/ test service.
Sample JSON schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {},
"id": "http://example.com/example.json",
"properties": {
"body": {
"description": "An explanation about the purpose of this instance.",
"id": "/properties/body",
"type": "string"
},
"title": {
"description": "An explanation about the purpose of this instance.",
"id": "/properties/title",
"type": "string"
},
"userId": {
"description": "An explanation about the purpose of this instance.",
"id": "/properties/userId",
"type": "integer"
}
},
"type": "object"
}
Project setup
- Create a new project in Design
- Import the
example.schema.json
document as a project template - Create some Text Input questions and map their Answers to the template placeholders
- Add a "Send to REST Service" action to the project's Finish page
- Supply parameters for the action as follows:
- URL: https://jsonplaceholder.typicode.com/posts
- HTTP Method: POST
- Optionally, set up the Action Documents to pass only the correct document to the Action. If there are no other JSON or XML templates in the project this step is unnecessary, as the default "All" setting will work fine
Updated about 7 years ago
Take a look at the REST Data Source type, to retrieve data posted in a previous form session.