What is an API Endpoint?
API endpoints can be setup to enable external systems to make calls to PhixFlow. API endpoints can be seen in the Repository for your application under API Endpoints and on the Actionflow homepage with the icon.API Endpoint Setup
API endpoints must be made using the specific option on the Actionflow homepage to ensure a URL is generated and a set of predefined input parameters are configured on the incoming connection point.
- Create a new API Endpoint on the Actionflow homepage using the option
- Set a unique name and provide a useful description
- The API Endpoint Properties will open on the right
- In the Basic Settings section, enable Allow Anonymous Connections
- This allows anyone with the URL for the API to call it. The audit trail records the system as running performing the API call.
Adding authorisation is covered on API Authentication and Secret Keys.
- Copy the URL and save it locally, to be used later when calling the API
Example URL: https://app.phixflow.com/phixflow/api/1/action/MyApp/My%20API/trigger
Url Structure
The structure of the URL is as follows:
https://<<Server Name>>/phixflow/api/1/action/<<Application Name>>/<<Actionflow Name>>/trigger
parameter | description |
---|
<<Server Name>> | URL of the server e.g. app.phixflow.com |
phixflow | the name of the instance, typically this is phixflow |
<<Application Name>> | The name of the application where the Actionflow resides. |
<<Actionflow Name>> | The name of the actionflow set in Step 1. Note that if your actionflow has a space in the name this must be replaced with %20. For example "My API" becomes, "My%20API". |
- Set the API Mode:
- Wait for result (Synchronous) (Default): The API waits for the results or the timeout to occur
- Note: If the timeout occurs the command is aborted
- Poll for result (Asynchronous): The API is called and a response is returned immediately including the process ID
- Subsequent API calls can be made using the process ID to fetch the status of the action
- The asynchronous mode can be thought of as “fire and forget”
- Set a Timeout (optional):
Specify a maximum time in milliseconds that the API will wait for before the command is aborted
When a Timeout value is set, it overrides the default timeout, which is 60 seconds where API Mode is Synchronous and 500 milliseconds where API Mode is Asynchronous
However, if a timeout parameter has been provided in the URL calling this API, that will override both this Timeout value and the default value
- Enable Log Request (optional):
- Enable Log Response (optional):
- Apply your changes
- Configure the Actionflow to perform the required tasks, for example return all company data , or pass in a date and return all companies onboarded after this date
- See Worked Example below for an example setup
API Endpoints have fixed input attributes (body, headers, contentType and url), and fixed output attributes (body, headers, contentType and statusCode) which can be mapped to.
API Status Check (Poll for Result)
- If calling a PhixFlow Asynchronous API only, a result will be immediately returned which includes a Process ID for that run
- The Process ID is returned on the path:
$.processId
- This can be accessed in an Output attribute using,
_result.value
- The Process ID can be used to call the following URL which will return the current state of the run:
- https://<<Server Name>>/phixflow/api/1/action/<<Application Name>>/<<Actionflow Name>>/poll/<<processID>>
Calling a PhixFlow API
HTTP Method
This is set on the HTTP action on the Actionflow calling the API.
- To call a PhixFlow API use the HTTP Method GET or POST:
- GET simply calls the API with data passed in the body of the request
- POST calls the URL and sends data in the body of the request. The body data is passed into the body attribute of the API as an Input Connection point
Returned Data JSON Path
If your API has been configured to return data the path will be in the format:
$.data.<<Output Name>>
Where <<Output Name>> is the Output connection point.
Server Console Responses
The item calling the API endpoint will receive the Response from the API endpoint stating whether it has run successfully (Success) or not (Fail). Responses can be customised to return specific messages.
The response recorded in the System Console:
If you are making the call using PhixFlow the Responses can be access as follows:
- Click the Actionflow entry
- In the Messages section which is opened below, double-click the lines that begin Response
- Click the Message Details tab to see the response
API Endpoint Results
To see the results of the API Endpoint processing in the System Console:
- Click the Actionflow entry for the API Endpoint
- In the Messages section which is opened below, double-click any of the Messages to see more details
- If you are using a debug() statement these will appear here
Failures
An API Endpoint will fail if the logic in the Actionflow fails or if the error() function is used to force a failure.
If records are passed to the API Endpoint individually a failure will only impact the specific record being processed.
Error Codes
200
- Occurs if the output of an API Endpoint is not connected
400
Worked Example
Here's a worked example using the Company Data (available from the Learning Centre).
In this example, we are using:Â Â
- A Company Call API screen containing a fixed drop down list of industries, a string fields for the API Status and a multi-line string field for the Results - this screen was created using the Tile with Buttons template
Example 1: Passing Out Data
In this example, we'll configure an API Endpoint that passes out Company ID, Company Name and Industry data from our Companies data.
Create API Endpoint
In this example, we'll set up an API Endpoint to pass out company data.
- Create a new API Endpoint on the Actionflow homepage using the option
- Name:
API Company Data
- Click Create
- The API Endpoint canvas will display, with the Properties open on the right
- In the Basic Settings section, enable Allow Anonymous Connections
- Copy the URL and save it locally, to be used later
- Apply your changes
Construct JSON
- Create a Calculate action
- Name:
GetDataAndConstructJSON
- Connect the input to the Calculate action
From the Calculate action, create a lookup to the Companies data
How?
- Hover over the Calculate action and select Add lookup
- Name:
getCo
- On the Create View window:
- Name:
CompanyData
- Table:
Companies
- Output Attributes Selection: drag CompanyID, CompanyName and Industry into the Output Attributes section of the View Action properties
- Outgoing Mappings: map across CompanyID, CompanyName and Industry
- On the Calculate action, create an attribute where the JSON will be constructed
- Name:
JSON
- Type:
Structured Data
Expression:
Apply and Close
- Drag the output connection node onto the Calculate node
Map the JSON attribute from the Calculate action to the body attribute
Example 2: Passing in Parameters
In this example, we'll retrieve data from our Companies API and pass in an industry parameter (e.g. "Telecoms") to filter the results to just companies in that industry.
API End Point Setup
- On the API End Point, create a JSON action to receive the parameter
- Name:
GetIndustry
- Input Expression:
in.body
- Path:
$
- Create an Output Attribute on the JSON action
- Name:
IndustryReceived
- Type:
String
- Expression:
_result.Industry
- Insert the JSON action between the input and Calculate nodes
- On the Mappings between the input and JSON nodes, map across body, contentType, headers and url
- On the lookup connector, getCo, map the IndustryReceived attribute as an Incoming Mapping
- On the View action, add a filter:
- Name:
ByIndustry
- Filter Details:
Call API Actionflow Setup
- On the screen, Company Call API, add an Actionflow to the Call API button
- If you have completed 2.13 HTTP Action Configuration and 2.14 JSON Action Configuration you will recognise the similar Actionflow setup
- On the input connection point, map in the Industry drop down field
- Create a HTTP action:
- Name:
Call API
- Connect the input to the HTTP action and map across the attribute, Industry
- HTTP Method:
POST
- URL: the URL from the API End Point you copied earlier
Body:
[{
"Industry": "${in.Industry}"
}]
Log Traffic:
Create a JSON action
Name: ReturnedCompanies
- Input Expression:
in.body
Path: $.getCo
Create 2 Output Attributes on the JSON action
- Name:
CoName
- Type:
String
- Expression:
_result.1.CompanyName
- Name:
CompanyID
- Type:
Integer
- Expression:
_result.1.
CompanyID
- Hover over the HTTP action and choose out, then connect it to the JSON action
- On the Mappings between the HTTP action and JSON action, map the attributes:
- body
- status
- Create an output connection point back to the screen
- Connect the JSON action to the output, and configure the following mappings:
-
- Then map the following attributes back to the screen on the output connection point:
Testing
- On the screen, Company Call API, click the Call API button to see the results of the Actionflow
System Console Response
On the HTTP action, Call API, the option to Log Traffic was enabled allowing the API response to be seen in the System Console.
- The results of the API call can also be seen in the System Console via the Administration option
- Navigate to the Completed Tasks tab
- Find the Actionflow calling the API and click on it
- In the Messages tab in the bottom half of the screen, double-click the message, Response from URL
- Click on the Message Detail tab in the Log Message window to see the API output