An API is an application programming interface. It is a set of rules and definitions that let programs communicate with each other. REST stands for representational state transfer; this describes the architectural style and rules according to which the API is built. The developer builds the API on the server, according tot he REST rules, and lets the client talk to the API.
When you link to a specific URL, you'll get a piece of data. The URL is referred to as a request, while the data sent to you is referred to as a response.
From the Master Flow, you can use the REST API node to call a REST API and have the data returned to the node or injected into a variable.
REST API Properties
The name of the REST API node. By default, the node will be called 'REST API 1', 'REST API 2', and so on. You can change the node name from this field.
You can add a description to the node; this can be a useful way of documenting the node for yourself and other users.
Choose the required REST API method.
Paste the relevant URL.
Choose this option to enable the PQL editor; the PQL icon will appear in the URL field. Click the icon to open the PQL editor, where you can write a PQL expression to
make the URL dynamic rather than static.
- Click here to review documentation of the PQL Common functions.
- Click here to learn more about the PQL editor.
- Click here to learn about PQL syntax.
Choose the required method of authentication.
Custom HTTP Request Fields
You can add HTTP request fields. For instance, if you want to call an API that requires authorization, add Authorization to the request fields. Or if you want to return only json content, select Content-Type and then write 'json' in the Expression field. Configure complex expressions using variables by opening the Expression Editor.
The Content window appears if the POST or PUT method is chosen from the Method drop-down (green highlight below). Enter the content that you want to send to the URL. The content can be static or based on a PQL expression.
Set Variable Values
Reference a variable to have the API return a value to the variable; you may opt to have the HTTP status code returned, and/ or the content. The values will be returned in the Current Value column of the given variable in the Variables panel.
In this example, the REST API node is used to call a URL with the GET method. The Execute Process node is used to ping Google, and then load the result into a variable called PingResult:
Next, the another variable called IpValue is loaded into the Set Variable node, and its value is set to a PQL expression that will return the IP address of the URL that was pinged:
SubString(@PingResult,IndexOf(@PingResult, "[") + 1, IndexOf(@PingResult, "]"))
Next, the Rest API node is used to send a GET request to the given URL. The URL is made dynamic by adding PQL to it, to add the value of the IpValue variable (previous step) into the URL:
The content retrieved from the request is then loaded into the variable called ipInfo:
Next, an email is sent out with the results that were loaded into the ipInfo variable (the content returned by the GET request):
Once the flow is executed, we see that the variable results. The PingResult variable stores the value from the Execute Process node which was used to ping Google. The IpValue variable was injected into the Set Variable node and stores the IP address of the URL that was pinged. And the ipInfo stores the content retrieved by the GET request.