Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Insert excerpt
_Banners
_Banners
nameanalysis
nopaneltrue

Introduction

Overview

PhixFlow allows you to integrate with various APIs to export data. To achieve this you will require three elements.

  1. Table: Contains the data which the HTTP Exporter will provide to the API.
  2. HTTP Exporter: Uses the HTTP Datasource the data from the HTTP Datasource.
  3. HTTP Datasourceprovide the information needed to connect to an external source of data via HTTP. 

Image RemovedImage AddedExample

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

  • Drag a HTTP Datasource from the toolbar and drop it on the analysis canvas.
  • In the properties window set the following:
  • Name, Set a name indicative of the API.
  • Enabled, Tick this option. 
  • Connection Type, Set this to that of the API, in our example we will use HTTPS.
  • 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. For the Gov Bank Holiday API we set this to: www.gov.uk/bank-holidays.json
  • Click 

    APIs will have different specifications, therefore we will walk though a generic solution which writes data back to an API.

    Solution

    Insert excerpt
    _

    finish

    tableOnly
    _

    finishnopaneltrue.Click  Insert excerpt_finish_finish

    tableOnly
    nopaneltrue

    .

    HTTP Collector

    1. Hover your mouse over the HTTP Datasource created in the stage abovetable contain the data you wish to export.
    2. From the popup menu select 
      Insert excerpt
      _http_collectorexporter
      _http_collectorexporter
      nopaneltrue
      . This adds a new HTTP Collector and sets it up to use our HTTP Datasource. 
      1. You can drag a new HTTP Collector Exporter from the toolbar, but you will need to connect it to the HTTP Datasource.
      In the properties window that
      1. table.

    Insert excerpt
    _http_exporter
    _http_exporter
    nopaneltrue

    1. In properties window which opens on the right set the following:
    2. Hover your mouse over the HTTP Collector created in the stage above.
    3. From the popup menu select  Insert excerpt_table_new_table_newnopaneltrue 
      1. You can drag a new Table from the toolbar, but you will need to connect it to the HTTP collector.
      In the properties window that opens on the right
      1. Basic Setting
        1. Name, Set a name indicative of the data being
        collected
        1. exported
        2. Enabled, Tick this to use the
        collector
        1. exporter.
      2. Send Message
        1. HTTP Request Method, This defaults to GET or POST. For our example that is
        correct
        1. suitable. However see  HTTP
        Collector
        1. Exporter for more information, if your API requires something different.
        2. URL Expression, we set the URL of the API we will be communicating with, omitting the http: prefix:
          1. 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
          To reference any of the attributes
          1. We can also reference a value from the table
          calling the http collector we use
          1. using ${
          _out.attributeName}. We encapsulate the attributes with ${}.For example, ${_out.token} 
          1. pipeName.Attribute e.g. ${in.URL}.
        3. Statement Expression,
        this is not required by our example. If your API requires interaction such as when we are requesting a session token, it can be carried our in this statement expression.
        1. 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:

        2. 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>


      3. HTTP Headers
        1. HTTP Headers, contains information about the request being sent to the API.
        This is not required for our example.
        1. An example header setup is illustrated below, for full details see HTTP Header
        2. Image Removed
      4. Response → Return Type, In the response section set Return Type to JSON. Other types of data can be returned, see HTTP Collector.
      5. ResponsePath, 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
        1. In our example we only want the bank holidays for each country so we set the value to: $..events
        2. This gives us all countries as we have specified ..
        3. If we want just England and Wales we would specify: $.england-and-wales.events

    Table

        1. Image Added
      1. Advanced
        1. Datasource, 
          1. Existing
            1. A datasource can be selected from the dropdown list or click the Datasource icon to display a complete list.
          2. New 
            1. Create the datasource as described in the next section and select it as outlined in item 1 above.

    Insert excerpt
    _http_datasource
    _http_datasource
    nopaneltrue

    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.

    1. Move you mouse over the HTTP Exporter created above and click
      Insert excerpt
      _http_datasource
      _http_datasource
      .
      1. Alternatively you can drag a HTTP Datasource from the toolbar and drop it on the canvas, but this will require a you to manually connect the items together.
    2. In the properties window for the HTTP Datasource set the following:
      1. Name,  Set Set a name indicative of the data being collectedAPI.
      2. Enabled, Tick this option
      3. Attributes, Add the attributes you require from your collected data:
        1. Name to Country. Expression to in.^.^.division 
        2. Name to Title. Expression to in.title
        3. Name to Date. Expression to toDate(in.date, "yyyy-MM-dd")
      4. You can navigate up the JSON nodes using the hat symbol ^. This is seen in the Country attribute above: in.^.^.division
      5. 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
        1. 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

    1. Open the System Console
    2. In the Completed Tasks, click on the table that ran
    3. In the Messages section,  double-click the line with the message "Response from URL:..."
    4. In the window that opens, click the Message Details tab
    5. The raw data is displayed that is returned from the API.
      1. Ensure your Response Path is set correctly to traverse to the required dataConnection Type, Set this to that of the API.
      2. HTTP Datasource Instances, Set the instance connection details. Add a new HTTP Datasource Instance and complete the details as follows:
        1. Name, Indicative of the use of the instance.
        2. Enabled, Tick to use the instance.
        3. Login details can be set if required. see HTTP Datasource for more information.
        4. URL, The URL where the API can be found.
        5. Click 
          Insert excerpt
          _finish
          _finish
          nopaneltrue
          .
      3. Click 
        Insert excerpt
        _finish
        _finish
        nopaneltrue
        .

    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

    1. Open the HTTP Datasource properties,
    2. Navigate to the Secret Keys section,
    3. Add your sensitive information,
      1. Name, name the secret key will be referenced by. For example clientSecret.
      2. Secret, the secret information to be stored in an encrypted format.
    4. Save all of your changes.
    5. 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.
    6. To reference the secret key use the syntax: _datasource.secretname.
    7. For example, _datasource.clientSecretExample Statement Expression:



    Code Block
    client_id=client_secret=${_datasource.clientSecret}&resource=phixflow.com&grant_type=client_credentials


    Troubleshooting

    PhixFlow can log the traffic sent to and from an API, this can be helpful as it lets you see the actual communication data such as the Statement Expression values or the Responses from the API.

    To enable logging:

    1. Click Administration Menu → System → Logging,
    2. Navigate down to Collector/Exporter Logging and tick
      1. Log HTTP Collector Connection Details
      2. Log HTTP Exporter Connection Details
    3. This is illustrated below:
    4. Image Added
    5. Once you have resolved your issue, turn these settings back off to avoid filling your logs with unnecessary information.
    6. To view the results open the System Console from the top right corner of PhixFlow (
      Insert excerpt
      _console
      _console
      ).
    7. In the Completed Task section, click on your Task.
    8. The Messages section on the right will now contain the logging for your activity.
    9. Double-click the messages to open them, in the window that opens also click on the Message Detail tab to see detailed information. Below is an example, here we see the response form the JSON response from the API:
    10. Image Added

    More Information

    For more information about the configuration options surrounding HTTP Datasources and Collectors see the following pages: