Insert excerpt | ||||||||
---|---|---|---|---|---|---|---|---|
|
Introduction
PhixFlow allows you to integrate with various APIs to export data. To achieve this you will require three elements.
- Table: Contains the data which the HTTP Exporter will provide to the API.
- HTTP Exporter: Uses the HTTP Datasource the data from the HTTP Datasource.
- HTTP Datasource: provide the information needed to connect to an external source of data via HTTP.
Example
We will connect to the UK Government bank holiday API and return the bank holiday dates for each country. See Bank Holidays for more detail on the API.
Solution
HTTP Datasource
HTTPS
.HTTP Collector
Hover your mouse over the HTTP Datasource created in the stage aboveNo specific example is provided as APIs will have different specifications. Instead here we will walk though a generic solution which writes data back to an API.
Solution
Table
- Hover your mouse over the table contain the data you wish to export.
- From the popup menu select
. This adds a new HTTP Collector and sets it up to use our HTTP Datasource.Insert excerpt _http_collectorexporter _http_collectorexporter nopanel true - You can drag a new HTTP Collector Exporter from the toolbar, but you will need to connect it to the table.
HTTP
Datasource.Exporter
- In the properties window that which opens on the right set the following:
- Hover your mouse over the HTTP Collector created in the stage above.
- From the popup menu select
- Basic Setting
- Name, Set a name indicative of the data being
- exported.
- Enabled, Tick this to use the
- exporter.
- Send Message
- HTTP Request Method, This defaults to GET or POST. For our example that is
- suitable. However see HTTP
- Exporter for more information, if your API requires something different.
- URL Expression, we set the URL of the API we will be communicating with, omitting the http: prefix:
- we can reference the URL from the http datasource using the syntax ${_url} (once connected). This can be useful if you have a base url in your HTTP datasource, e.g. www.phixflow.com, and you want to append to it in different collectors e.g.
${_url}/myPage1
- We can also reference a value from the table
- using ${
${_out.token}
- pipeName.Attribute e.g. ${in.URL}.
- we can reference the URL from the http datasource using the syntax ${_url} (once connected). This can be useful if you have a base url in your HTTP datasource, e.g. www.phixflow.com, and you want to append to it in different collectors e.g.
- Statement Expression,
- is the statement that will be sent to the API through the datasource. Check the specifications of your API for the structure of the statement. Below is an example if a SOAP XML statement sent to Salesforce:
Code Block <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com" xmlns:urn1="urn:sobject.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Header> <urn:SessionHeader> <urn:sessionId>${in.SessionID}</urn:sessionId> </urn:SessionHeader> </soapenv:Header> <soapenv:Body> <urn:create> <urn:sObjects xsi:type="urn1:Account"> <Name> ${= removeNull(acc.Name) } </Name> <AccountNumber> ${acc.AccountNumber} </AccountNumber> <Industry>{(acc.Industry) }</Industry> <AnnualRevenue> ${acc.AnnualRevenue} </AnnualRevenue> <Phone>{(acc.Phone) }</Phone> <Website>{(acc.Website) }</Website> </urn:sObjects> </urn:create> </soapenv:Body> </soapenv:Envelope>
- HTTP Headers
- HTTP Headers, contains information about the request being sent to the API.
- An example header setup is illustrated below, for full details see HTTP Header:
- Response → Return Type, In the response section set Return Type to JSON. Other types of data can be returned, see HTTP Collector.
- Response → Path, specifies the data in the JSON you with to return. Most APIs will specify the structure of the data returned, the path is used to filter what is returned. The response utilises xPath Syntax
- In our example we only want the bank holidays for each country so we set the value to:
$..events
- This gives us all countries as we have specified ..
- If we want just England and Wales we would specify:
$.england-and-wales.events
- In our example we only want the bank holidays for each country so we set the value to:
- Basic Setting
Table
- Advanced
- Datasource,
- Existing
- A datasource can be selected from the dropdown list or click the Datasource icon to display a complete list.
- New
- Create the datasource as described in the next section and select it as outlined in item 1 above.
- Existing
- Datasource,
HTTP Datasource
This step is only require if you need a new datasource. Often a single HTTP Datasource will facilitate both the connection to and from an API.
- Move you mouse over the HTTP Exporter created above and click
You .Insert excerpt _tablehttp_newdatasource _tablehttp_newdatasource nopanel true - Alternatively you can drag a new Table HTTP Datasource from the toolbar and drop it on the canvas, but this will require a you will need to manually connect it to the HTTP collectoritems together.
- In the properties window that opens on the right for the HTTP Datasource set the following:
- Name, Set Set a name indicative of the data being collectedAPI.
- Enabled, Tick this option.
- Attributes, Add the attributes you require from your collected data:
- Name to
Country. Expression to in.^.^.division
- Name to
Title.
Expression to in.title
- Name to
Date
. Expression totoDate(in.date, "yyyy-MM-dd")
- Name to
- You can navigate up the JSON nodes using the hat symbol ^. This is seen in the Country attribute above:
in.^.^.division
- You can descend the JSON nodes using .. as a wild card to include all nodes at that level. This is seen in the Response Path of the HTTP Collector to include all countries:
$..events
- It is also possible to use the specific node name to descend into a specific node in the JSON.
Trouble Shooting
If you return 0 records
- Open the System Console
- In the Completed Tasks, click on the table that ran
- In the Messages section, double-click the line with the message "Response from URL:..."
- In the window that opens, click the Message Details tab
- The raw data is displayed that is returned from the API.
- Ensure your Response Path is set correctly to traverse to the required data.Connection Type, Set this to that of the API.
- HTTP Datasource Instances, Set the instance connection details. Add a new HTTP Datasource Instance and complete the details as follows:
- Name, Indicative of the use of the instance.
- Enabled, Tick to use the instance.
- Login details can be set if required. see HTTP Datasource for more information.
- URL, The URL where the API can be found.
- Click
.Insert excerpt _finish _finish nopanel true
- Click
.Insert excerpt _finish _finish nopanel true
Trouble Shooting
Secured Example
Where we need to use sensitive information, such as a password or token, these can be held in Secret Keys and access using the prefix _datasource.
Secret Key Setup
- Open the HTTP Datasource properties,
- Navigate to the Secret Keys section,
- Add your sensitive information,
- Name, name the secret key will be referenced by. For example
clientSecret
. - Secret, the secret information to be stored in an encrypted format.
- Name, name the secret key will be referenced by. For example
- Save all of your changes.
- The secret key can now be referenced by HTTP CollectorsExporters attached to the HTTP Datasource. It is available to use in the URL Expression and Statement Expression.
- To reference the secret key use the syntax:
_datasource.secretname
.- For example,
_datasource.clientSecret
- Example Statement Expression:
client_id=client_secret=${_datasource.clientSecret}&resource=phixflow.com&grant_type=client_credentials
- For example,
More Information
For more information about the configuration options surrounding HTTP Datasources and Collectors see the following pages: