Jump to content
  • Calling REST API using Spotfire® and Advanced Data Services


    In this article, we will go through the procedure to use external REST API (JSON Format) in a Spotfire® analysis. The API takes as an input an API Key that the user, in Spotfire, will have to provide.

     

    Introduction

    In this page, we will go through the procedure to use external REST API (JSON Format) in a Spotfire® analysis. The API takes as input an API Key that the user, in Spotfire, will have to provide.

    Topics covered will be:

    1. Add a Data Source in Advanced Data Services (ADS)
    2. Define the XSD of the API response / Transform Json output to XML
    3. Transform the XML output to tabular data
    4. Make this tabular data visible in ADS
    5. Publish the data in ADS
    6. Import the data in Spotfire
    7. Manage parameters in Spotfire

    For this purpose, we will use the publicly available API from Transport for New South Wales. (https://opendata.transport.nsw.gov.au/)

    The documentation of the API is really good and they are usually easy to use.

    Use case

    "I want to have a map with the up-to-date list of road cameras in New South Wales, but I want the users who use this map to provide their own API Key."

    Based on the same elements, you could also ask for a user to input an address and put a marker on a map using Google Maps API or, even better, Spotfire GeoAnalytics API!

    Traffic Camera Data API

    For this use case, I will use this API:

    https://opendata.transport.nsw.gov.au/node/340/exploreapi

    This API needs two parameters:
     

    Parameter name Where What Example
    Accept HTTP Header Response content type

    Accept: application/json

    (Well, this is not an example, this is the only valid value)

    Authorization HTTP Header API Key

    Authorization: apikey k6V4faosxxThDyxIZnjdJgQZJAcGE8l1hdt0

    (This is obviously not my API key, so don't bother trying with this one)


    As a result, a JSON Structure is returned with information about cameras like their coordinates, a link to a picture taken by the camera, its direction, etc.

    Example (Only 3 cameras here to shorten the text):

    {
      "type": "FeatureCollection",
      "rights": {
        "copyright": "Transport for NSW",
        "licence": "http://livetraffic.com/#dev"
      },
      "features": [
        {
          "type": "Feature",
          "id": "d2e386",
          "geometry": {
            "type": "Point",
            "coordinates": [
              151.10533,
              -34.02977
            ]
          },
          "properties": {
            "region": "SYD_SOUTH",
            "title": "5 Ways (Miranda)",
            "view": "5 ways at The Boulevarde looking west towards Sutherland.",
            "direction": "W",
            "href": "http://www.rms.nsw.gov.au/trafficreports/cameras/camera_images/5ways.jpg"
          }
        },
        {
          "type": "Feature",
          "id": "d2e5699",
          "geometry": {
            "type": "Point",
            "coordinates": [
              151.23122,
              -33.90641
            ]
          },
          "properties": {
            "region": "SYD_MET",
            "title": "Alison Road (Randwick)",
            "view": "Alison Road at Darley Road looking north-west towards Anzac Parade.",
            "direction": "N-W",
            "href": "http://www.rms.nsw.gov.au/trafficreports/cameras/camera_images/alisonrd_randwick.jpg"
          }
        },
        {
          "type": "Feature",
          "id": "d2e649",
          "geometry": {
            "type": "Point",
            "coordinates": [
              151.18022,
              -33.86789
            ]
          },
          "properties": {
            "region": "SYD_MET",
            "title": "Anzac Bridge",
            "view": "Intersection of Victoria Road and Anzac Bridge looking east towards the Sydney CBD.",
            "direction": "E",
            "href": "http://www.rms.nsw.gov.au/trafficreports/cameras/camera_images/anzacbr.jpg"
          }
        }
      ]
    }
     

     

    The goal is to have one "row" in Spotfire per "feature" in JSON response.

    Advanced Data Services

    First, a quick explanation about Advanced Data Services:

    Spotfire Advanced Data Services allows Spotfire users to connect and analyze data available through Composite Information Server.

    Basically, Spotfire will connect to Composite Information Server which acts as a virtual connector to different external sources (REST, SOAP, SAP, etc.)

    We will use Advanced Data Services to connect to the TfNSW REST API.
     

    Connect to REST API: Advanced Data Services

    Add the Data Source

    To keep a neat project, let's create one folder for this new API.

    image1.png.3faf57ebc23d1d89c628b976a18c0d73.png

    And name it "NSWCameras":

    image2.png.87620941df43a014610e9aa09dec1c5a.png


    Let's create the Data Source. Right-click on the new folder and select "New Data Source":
     

    image3.png.02e4ca3a04b7c099acc0b0387a54c5a0.png

    In the list of adapters, choose "REST":

    image4.thumb.png.be7ffe11785e27a96b4c6588b904ac65.png

    A new dialog appears. Give a name to your data source and provide the base URL of the API.

    image5.thumb.png.659ec0d5dd0b99e92f33307be574e98b.png

    The base URL is given on the TfNSW website:

    image6.thumb.png.8c20e63c06db8eef04346c7469414ffc.png

     https://api.transport.nsw.gov.au/v1/live/
     

    The API will return a JSON structure, therefore we need to tell ADS that it needs to parse a JSON string. For this, tick the "JSON Format" check box. We also need to give a name for the root element of the JSON String. This element will encapsulate the result provided by the API. For this, give a name in the field "Wrapper of JSON Bare Response":
     

    image7.thumb.png.ba119ad3d1a061fdb34c2063f6d98849.png


    We now need to add an operation for the API. There is only one operation available for this API:

    image8.thumb.png.cfab4deeec8986e8db64572cda975404.png

    URL path is "cameras" and the operation is "GET", so let's add this to our Data Source. Click on the + icon and give a name to the operation:

    image9.thumb.png.6a4b3ea7bac32be9bf48c06644b8ff76.png

    Specify the path of the operation and the name of the method:
     

    image10.png.1582155ec3566bdb14eaaa7c0a5a126e.png

    In the lower part, we now need to add the parameters we want to pass to the API, and what is expected from the API as a result. This can be achieved in the lower part, in the "Header/Body Parameters" part:

    image11.thumb.png.130f7a542c9e9897a6e2da380eeeeb61.png

     

    Param name Location Data Type In/Out
    Accept HTTP Header VARCHAR IN (This will be passed to the API)
    Authorization HTTP Header VARCHAR IN (This will be passed to the API)
    response Body Complex > XML OUT (This will be the result of the API call)


    Then, tick the "XML<->JSON" checkbox, it will translate the JSON response to XML which will be easier to parse later on.

    If you are lucky, you can try to click on the "Design by example" button to trigger the execution of the API call and let ADS try to identify the format of the response (And create the XSD accordingly). Unfortunately, it didn't work for this API.
     

    image12.png.248e932515838096da3fde418859db6b.png

    However, the response is correctly parsed and an XML structure is created. Good thing! We will return to the creation of the XML structure in a while, but for the moment, let's just create the Data Source by clicking on the "Create" button.

    We now need to introspect the Data Source. Select the operation and click on Next. (In case you later need to add new operations to this Data Source, the introspection will have to be performed again).
     

    image13.thumb.png.e3bfcb61e7402eb715e75f11204b7087.png

    Click on Finish. The introspection starts

    image14.thumb.png.89ce96c8774e6d2ceea4b75d47d8fc95.png

    Once finished, click on OK.

    And click on "Save and Close" on the main dialog.
    image15.png.68cbc4081495711777749a2e5c11647d.png

    Create the XSD of the API response

    This step is not necessary in case you've been lucky in the "Design by example". We will create an XML schema defining the format of the response of the API call.

    Open the file with the result of the first API call or paste the content into a text editor. Format the XML to make it more readable.
     

    image16.thumb.png.fe1613c0a1417e64f3532753b3432141.png


    Note: As mentioned by ADS, the response provided during the test call may have been truncated, so ensure that the tags are closed correctly.

    In this example, there are:

    • The root node called cameras (Remember, that is the name we set in field "Wrapper of JSON Bare Response")
    • A element "type"
    • A node "rights"
    • And several nodes "features" that are the actual cameras

    My example was truncated in the middle of a node "features". So I simply removed this node and closed the main node "cameras".

    Now let's create an XSD file from the XML content. For this, I used an online tool called XMLGrid.
     

    image17.thumb.png.820e38e414a479119c5a88370f81bb68.png

    And I saved the generated XSD file.

    imagem2.thumb.png.59bc7d0314d3f8dc75c6da382746e091.png


    This is a good starting point but it needed some tweaks to make it fit the exact output from our API call. For example:

    • Set the maxOccurs of geometry
    • Set the minOccurs and maxOccurs of coordinates
      • As in the API response, there will always be two coordinate fields: longitude and latitude.

    Final XSD:

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
      <xs:element name="cameras">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="type" type="xs:string"/>
            <xs:element name="rights">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="copyright" type="xs:string"/>
                  <xs:element name="licence" type="xs:string"/>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
            <xs:element name="features" maxOccurs="unbounded">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="type" type="xs:string"/>
                  <xs:element name="id" type="xs:string"/>
                  <xs:element name="geometry" maxOccurs="1">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element name="type" type="xs:string"/>
                        <xs:element name="coordinates" minOccurs="2" maxOccurs="2" type="xs:double"/>
                      </xs:sequence>
                    </xs:complexType>
                  </xs:element>
                  <xs:element name="properties" maxOccurs="1">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element name="region" type="xs:string"/>
                        <xs:element name="title" type="xs:string"/>
                        <xs:element name="view" type="xs:string"/>
                        <xs:element name="direction" type="xs:string"/>
                        <xs:element name="href" type="xs:string"/>
                      </xs:sequence>
                    </xs:complexType>
                  </xs:element>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>
     

    Let's save this in our project. Right-click on the NSWCameras folder and select "New Definition Set":
     

    image18.png.d73d00db1c5bd671530924cef4d4e916.png

    Give a name to your file and choose XML as the type. (We want to create an XSD file)

    image19.png.93f46660bcf09b956b6c99180190c135.png

    Save the content of the XSD in this file.

    image20.thumb.png.05491b1471b3ca3dc72f36895888ebc7.png
     

    Edit the Data Source

    Now that the XSD has been generated, we want it to be applied to the response of the API call.

    Re-open your Data Source and go to Header/Body parameters. Then, as the data type of the response, choose the XSD structure that we've created in the previous step.

    imagem.thumb.png.d5f4ae09a586652e2aa8a62835aba4b4.png

    The result should be:

    image21.thumb.png.85ec927322efe0c46ca77e837bd208d0.png

    If you now go back to the operation, you can see the full structure of the output:

    image22.thumb.png.fead9fa73ad8354b3fc36a5fd58d8664.png

    Great, now the Data Source is done and correctly configured! But still in XML format... We need to show it in a tabular format. That's what we are going to do in the next step.

    Transform XML structure to tabular data

    Let's make our XML structure into a tab structure. For this, let's create an XSLT Transformation. Right-click on the project folder and choose "Transformation":

    image23.thumb.png.63cf6ab84f85f89bd7706938ffbfa130.png

     

    Then select "XSLT Transformation":
     

    image24.thumb.png.68872e68a1a3a8f0f6f01e5374bbd371.png

    Click Next, give a name to your transformation file, and select the operation of the Data Source you want to apply the transformation to:

    image26.thumb.png.a078106591213c461dc0c80ab4be6283.png

    Click Finish.

    A new tab opens with the transformation mapping screen:
     

    image27.thumb.png.9372ed70db77bc68beb74e14a5f008e0.png

    Expand the camera node up to the nodes that you want to export.

    In our case, one "feature" will become one row.

    image28.png.9300de6c4f317d5d6ccc973b097098b7.png


    We now need to map the XML elements to table columns.

    Select the element you want to have as a column and click on "Create Link And Target"

    image29.png.8bbc06ab129a5f4314d07203d4cb7193.png

    This is the easiest way to create output columns.

    You can do that for all the elements at once (But you need to unselect the nodes first):
     

    image30.png.12e3d48d5ccb20187b1fb232a60ec8bf.png


    Mapping is created:
     

    image31.thumb.png.7ceea38ec2595c1e4258ea373ed70d96.png

    But the column's order is weird. To reorganize that, click on the output field you want to move and move it with the blue arrows:

     

    image32.thumb.png.c851ae3e5c2d975778f459db3c416072.png


    Result:
     

    image34.thumb.png.3e69f081fafd2ea1a38d27e31d51c1e5.png


    You can rename columns by right-clicking on the name and selecting "Rename":
     

    image35.png.db623e5efed6973301b2eed07d911198.png


    You can also change the data type from here if needed.

    Once done, you can try the mapping:
     

    image36.png.04019dd247691cef58ad4a68f95c9503.png

    And see the results below:

    image37.thumb.png.985124aba4796a53df7a756cc0c370e2.png

    Good but not done yet.

    Two issues:

    • Several rows per node
    • Coordinates are not split into two columns (long/lat) (One value per node)

    Let's review the XSLT code (Click on tab XSLT).
     

    image38.thumb.png.9b996e7a7fd141d43d9305406a9bc5c8.png

    The default XSLT does a loop for every complex node. This is why we have multiple rows for the same "features" nodes. This need to be corrected.

    Another issue is that the coordinates are stored in one column but on two rows. We should rather have two columns, one for longitude and one for latitude.

    Let's create those two columns: go back to the Data Map tab and click on the Add button:
    image39.png.db5381a14426e4c7b0c0bb7ce755657c.png

    Select the Data type of the new attribute (longitude and latitude are real often stored as double):
     

    image40.png.177bcd272181911401367ca98d757174.png

    The two new fields appear in the last positions:

    image41.png.beed220035977204d5f7042b2deafde5.png

    Move them next to the coordinates and delete the coordinates:

    image42.png.5f1f04a15ab9ddea17f293d2eb841723.png


    Note that those fields are not mapped yet but all the output fields are created.

    Let's now get rid of duplicate rows. For this, let's go in the XSLT view.

    For example, we know that there will be only one "geometry" node by the camera, so no need to loop on it.

    image43.png.1ad13003f0fa3b9e50c281647b9f9911.png

    And we know that there will be exactly two "coordinate" nodes (One for longitude, one for latitude), then let's simplify the code.

    Note: Once you edit the XSLT file, the Data Map will no longer be available!
     

    image44.thumb.png.1461ec4a31d0fd5c6ae3cceb2fcbf982.png


    Removing unnecessary loop:

    imagem3.thumb.png.0b8fb2ff835e6515cc000be47cd87831.png

     

    Let's also map the coordinates:

    imagem4.thumb.png.d6f8abdcffc09424ccb43d69c6f90839.png

     

    You can do all the XSL transformations you need. The things to remember are the following:

    • At the top of the XSLT file, the variables:

    imagem5.thumb.png.e869efb58aef1a82962208b88f5559a4.png

    That's for internal use only.

    • The columns that need to be exported must be mapped in the XSLT.

    Example:

    imagem6.png.b25e9056f7b4645d8d895ca290d2502d.png


    Column "latitude" will be exported and its value will come from variable "_latitude".

    But for the column "latitude" to be exported, it must have been defined in the tab "Outputs":
     

    image45.thumb.png.12280c9ea1f8599746ae1cd0962e07df.png


    All the other variables that are not in this tab, even if mapped in the XSLT, will NOT BE exported.

    Ok... now I won't get into all the details of the XSLT... Here is the simplified file:

    <xslt:stylesheet xmlns:xslt="http://www.w3.org/1999/XSL/Transform" xmlns:csw-xform="http://www.compositesw.com/2003/xform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0">
      <xslt:template match="cameras">
        <xslt:element name="results">
          <xslt:for-each select="features">
            <xslt:variable name="_typefeature" select="type"/>
            <xslt:variable name="_id" select="id"/>
            <xslt:variable name="_typegeometry" select="geometry/type"/>
            <xslt:variable name="_longitude" select="geometry/coordinates[1]"/>
            <xslt:variable name="_latitude" select="geometry/coordinates[2]"/>
            <xslt:variable name="_region" select="properties/region"/>
            <xslt:variable name="_title" select="properties/title"/>
            <xslt:variable name="_view" select="properties/view"/>
            <xslt:variable name="_direction" select="properties/direction"/>
            <xslt:variable name="_href" select="properties/href"/>
            <xslt:element name="result">
              <xslt:element name="typefeature">
                <xslt:value-of select="$_typefeature"/>
              </xslt:element>
              <xslt:element name="id">
                <xslt:value-of select="$_id"/>
              </xslt:element>
              <xslt:element name="geometry_type">
                <xslt:value-of select="$_typegeometry"/>
              </xslt:element>
              <xslt:element name="latitude">
                <xslt:value-of select="$_latitude"/>
              </xslt:element>
              <xslt:element name="longitude">
                <xslt:value-of select="$_longitude"/>
              </xslt:element>
              <xslt:element name="region">
                <xslt:value-of select="$_region"/>
              </xslt:element>
              <xslt:element name="title">
                <xslt:value-of select="$_title"/>
              </xslt:element>
              <xslt:element name="view">
                <xslt:value-of select="$_view"/>
              </xslt:element>
              <xslt:element name="direction">
                <xslt:value-of select="$_direction"/>
              </xslt:element>
              <xslt:element name="href">
                <xslt:value-of select="$_href"/>
              </xslt:element>
            </xslt:element>
          </xslt:for-each>
        </xslt:element>
      </xslt:template>
    </xslt:stylesheet>
     

    We can now try the transformation:
     

    image46.png.bf3d3b968b3ca1a6bd0c4b220f56dcda.png

    When trying now, the export is correct:
     

    image47.thumb.png.e4c78e59fa956fd2be9cf43dc6626873.png

    Great, now we've got the data as a table! Awesome!

    But... you'll have remarked that during this implementation, each time you need to test the execution, you need to provide the full inputs declared in the operation. (The two headers).

    We will now create a parameterized query to call the operations with the correct inputs.

    Create parameterized query

    We are almost done with ADS. We could make the data available right now, but all the input parameters would need to be hardcoded. In this case, it's only an authentication header, so it could be fine, but remember my use case: the users of this report need to provide their own API key. Let's, therefore, add a query in which we expect, as an argument, their API Key.

    Right-click on your project and select "New Parameterized Query":
     

    image48.thumb.png.51bfb64e789902c12d89b06d188adf0b.png

    Give it a name and click on "OK":
     

    image49.png.0d1f69d75a0f7df737494f375c55f075.png

    A new tab opens. Drag and drop the transformation previously created in the blank area:
     

    image50.png.7035964c71fc8e672316adb80bf390d7.png

    A dialog with the two input parameters appears:

    image51.thumb.png.770e1301799d087a87ae670346998903.png

    Remember the input needed by the API:

    • One header to set the accepted content type (Accept)
      • Which has only one possible value "Accept: application/json"
        • So this value can be hardcoded as it will never change
    • One header to set the API Key (Authorization):
      • Which is composed of "apikey" and the API key itself
        • So this value will be given as a parameter (Note the "Query Parameter" under the name of the field "Authorization"

    Click on OK. The SQL is generated for you. Go to the SQL tab to see it:
     

    image52.thumb.png.f93d096ed14d9ee87f5a5456e55767a4.png

     

    As you can see in the previous screenshot:

    • The first parameter is hardcoded: 'application/json'
    • Second parameter is replaced by a variable: apikey

    That's cool, but here, that means that the user needs to provide the full header value of the API Key, i.e.; "apikey XXXXXXXXXXXX"

    It would be better to ask for the API Key only, not the full header, right?

    Let's edit the SQL query to add the prefix "apikey " to the second parameter. But, as for the previous mapping, the GUI mode will not be visible anymore once the SQL query is edited:
     

    image53.thumb.png.2dff854ad67a53ec117b1ddc0eedf9c9.png

    SQL query updated:
     

    image54.thumb.png.b73ac32b19e7a14f6ef96702236c22f8.png

    Note the double pipe for the concatenation of the string "apikey " and the value of the variable apikey.

    Now, when testing:
     

    image55.png.7c30a71f386645f4f03e6c3ac1426d08.png

     

    Only the API key is requested!
     

    image56.thumb.png.ef1ab2a15b11d330c6e88cffeef60a60.png

    And the result shows the lines:

    image57.thumb.png.16db5977f690a66318433623d989a33e.png

    Ok, now, we can have a parameter for our API, through this parameterized query. Awesome! But I feel a little bit of impatience now... Almost done! Next step, is the creation of a view.

    Creation of view

    Right-click on your project folder and select "New View":
     

    image58.thumb.png.96720f616490fab552b068807de6bfcf.png
     


    Give a name to your view. This name will be visible in Spotfire when querying the data.
     

    image59.png.e2793ff52fecfa2dbcebb5450785cc9f.png

    In the opened tab, drag and drop the parameterized query:

    image60.thumb.png.f54a68705e12c5832fd0e3a9a890d32d.png

     

    A dialog appears asking for the input:

    image61.thumb.png.e870f12d5d692b98e52a4a336951cc92.png

    Change the drop-down to Declaration but do not enter any value in the input field and click on OK.

    Open the Grid tab and change the "Alias" (by default Expr1) name to make it more understandable. This is the name of the variable that will be prompted in Spotfire:

     

    image62.png.2418a1bbd85d25825f7276c4ebd28c15.png
     

    When going to the SQL Tab, the SQL Query is using the variable we've just declared:

    image63.thumb.png.7f7002c3d9a868d92a9ca1123f220a54.png

    Publishing the view

    I promise this is the last step with ADS! :)

    To publish the view, start by creating a new Composite Data Source. Right-click on "Databases" in "Composite Data Services" and select "New Composite Database Service..."
     

    image64.png.52c9adc5d0d8bfb1188a396d7e048514.png

    Name your database (This name will be visible in Spotfire) and click on OK:
     

    image65.png.a0cf8d8903a6c5980474374eda307119.png

     

    Now right-click on your view and publish it:


    image66.png.b8bc9d19b9baef08da87ce5f15ee32e1.png

     

    Select the database previously created:
     

    image67.thumb.png.5ce873c93eecd58998a018baa4c05d87.png


    And click on OK. Your view is now created!
     

    image68.png.27b2fc68233a34fc4f26fdeec980db09.png

    All done for ADS configuration!

    Configure Spotfire

    Ok, now we're done with Advanced Data Services. We need now to connect with Spotfire to ADS new Data Source. But for this, you have several choices:

    1. Advanced Data Services authentication
      • Take this as a connection to a Data Base: When opening a report, would you like the users to authenticate on the database server (In addition to the Spotfire Server)
        1. Choice 1: The user that connects to the report needs to authenticate on the Advanced Data Services server (Not user-friendly)
        2. Choice 2: The credentials to connect to Advanced Data Services are stored on the Spotfire Server
    2. Parameterization of query
      • As we added a parameter in the query, we need to fill in this parameter. For this, you have two choices.
        1. Choice 1: The user will be prompted to enter a parameter. This parameter can then be used every time he refreshes the data or can be set once and for all
        2. Choice 2: The user can input his parameter in an input field. When updating the value of the input field, the data will be refreshed based on the input value.

    Advanced Data Services authentication

    User authentication

    When having a report using ADS, you can ask the user to authenticate on the ADS server. For this, you simply need to add the connection to the Spotfire report without any additional configuration:
     

    image69.thumb.png.8fc24b6e48865492182c803b51bd84f0.png


    Fill in the ADS credentials, click Connect, and chose the Database we've just created (NSWCamerasDB)


    image70.thumb.png.dfd7917dd9d5643bb55590e073b01d48.png

    Then click OK.

    The next dialog is to select the tables/view we want to use. But, depending on the parameter input method we chose, the method will be different:

    • If you want the user to be prompted for the parameter value (Every time the data is refreshed), click here
    • If you want the user to use an input text and have a more dynamic experience, click here

    Saved credentials

    You also have the possibility to store the ADS credentials to be authenticated once and for all, and, above all, avoid the user needing to input ADS credentials.

    For this, you need to store the Data Connection in the Spotfire library and save the credentials: Tools > Manage Data Connections...
     

    image71.png.d70e7c9b3fb0f174d71b7764efd13292.png


    Add New > Data Source > Cisco Information Server
     

    image72.png.b4e751e743215bd36876b248ab460e85.png

    Fill in the ADS credentials, click Connect, and chose the Database we've just created (NSWCamerasDB)

    image73.thumb.png.49d0368716998b0385b3d155ba74aef8.png

    In the new dialog, click on the "Credentials" tab and choose to save the credentials:
     

    image74.png.9971e3375202eeabe5f034ef7ca54cd0.png
    Note: As written, it may be considered a security risk to store the credentials with the Data Source...

    Finish by saving your Data Source in the library by clicking on "Save As...". Select the folder where you want to save the connection and click on save.
     

    image75.png.e05f54b33ee4f84a4b578f2ee3fa50b9.png
    Now, you can add Data Tables using this Data Source:

    image76.thumb.png.c4299238960f1e0b0ad67c0798855d96.png

    And the user will not be prompted anymore for the ADS credentials.
     

    Parameterization of query


    Remember that our query expects one argument: The API Key that is necessary for the REST API. Spotfire, therefore, needs to provide this API key to ADS. And... The user needs to provide this API Key to Spotfire. :)

    You have two choices for this:

    1. Prompt the user so he inputs the API Key when reloading the data
      1. Which, in the case of an API Key would be sufficient
    2. Use an input field as the source of the parameter
      1. In case for example you need more dynamic input from the user. (i.e: When the API call needs additional input from the user like, for example, for Google Maps API, the address to locate)

    User prompt

    This method is to prompt the user to input a parameter (Here, an API key) when refreshing the data. As a pre-requisite, you need the Connection to ADS to have been done (Here or here)

    Select the view/table that you want to use and click on "Add >":
     

    image77.thumb.png.76bdd3f5833213c5e0630119ad6cfe11.png

    The columns of this table appear in the right panel. Note that an additional column has been added: "API_KEY":
    image78.thumb.png.5d1a38a183f8e4e5185bd21b7e1fd325.png

    Click on the "Define Prompting..." button to define what fields should be prompted to the user. In the new dialog, click on "New...".

    Select the API_KEY column and chose "Manual input" as the prompt type:
     

    image79.thumb.png.430d19a7f7c21f929a6128087bc1f589.png
    Click OK to close this dialog, OK to close the "Define Prompting" dialog, and "OK" to close the "Views in Connection" dialog.

    Click "OK" to add the data table.

    image80.thumb.png.b167036eca510022c96fdffc9fbf1588.png

    You will be prompted for the API Key:

    image81.thumb.png.27fd45ec5c39a3a3548a32688459183b.png

    Then, if the API key is correct, you should be able to see the data:

    image82.thumb.png.6da6283439847ad9c3b87b53883fd13d.png

    Input value

    Now another solution: adding an input text that the user will use to enter his API Key. As a pre-requisite, you need the Connection to ADS to have been done (Here or here).

    When adding the table and choosing the ADS connection, you will see:
    image83.thumb.png.a0ad2fd05a16622772458095927b3a50.png

    Chose "Custom Query" > "New Custom Query...":

    image84.png.f3887672d0fbe3da0ed2024c0360ec47.png

    Give a name to this custom query and enter the SQL statement. 


    image85.thumb.png.433bdaaf275cd03651b503136495a24b.png

    • The name of the view/table is the name of the view you have created in ADS.
    • For the columns to select, you can set a "SELECT *" for the moment as, when clicking on "Verify", you will be able to see the retrieved columns and remove the unnecessary ones.
    • To create a parameter, you need to prefix it with a question mark in the SQL query and create it in the "Parameters" tab.
    • Once the SQL query is filled in and parameters are created, click on Verify to check everything is good. You should see a green mark as on the screenshot above.

    Click on OK to save the query and go back to the main view selection:
     

    image86.thumb.png.d585cda8673c02560df16791588d4b7e.png

    Click OK to close this dialog and return to the "Add Data Tables":

    image87.thumb.png.c56eac7acf18e735465c3ff3aa671fb8.png

    Select "Load on demand" if not already selected and click on "Settings..."

    In the opened dialog, select the API_KEY column and click on "Define Input...":
     

    image88.thumb.png.95c8a5930e55be804834f193837fc11b.png

    (Here the input is set as "Prompt in connection")

    In the Define Input dialog, change the following:

    • Input for the selected parameter:
      • Values (fixed/properties/expression)
    • Input from:
      • Property (And click on "Select..." to select the property that will store the API Key)

    In the "Select Property" dialog, create a new property:


    image89.thumb.png.7a86d5fcd6bf812d02eaa7f211e857d0.png

    Then click OK to close these dialogs and to return the "On-Demand Settings":


    image90.thumb.png.f574232f7e56e3beeb669ec69c7012ea.png

    Note here that the input comes from a Document property.

    If, when creating the property, you set the value of the API Key, then you should see the data.

    From now, you can add an input field to a text area and link it to the property that stores your API Key:


    image91.thumb.png.ea7694a74ff147bf1597adb104830102.png

    Then, if the user leaves the API key blank or enters an incorrect key:


    image92.thumb.png.bb69e6f6547533652128c54311dbcd8b.png

    Final result

    Well, I will not go into all the details on how to set up markers on a map and so on. But I guess that you would like to see the end result, right?

    Here it is:
     

    image93.thumb.png.42a4d6c148687fcb718815c5cd360cf3.png

    Troubleshooting

    The CustomQuery: 'QueryWithUserInput' was not allowed to execute because it is not trusted.

    • Ensure the user has the correct rights and is in the "Custom Query Author" group.

    image94.thumb.png.49f77f9bd041f924f17ed52c4771bac6.png

    If the query is still not trusted:

    • In Spotfire, chose "Edit" > "Data Connection" properties
    • Select the connection and click on the "Settings" button.
    • Click the "Edit" button to edit the query
    • Select the custom query on the left-hand side and click on "Edit custom query"
    • Click the "Verify" button and check that the query is still valid
    • Click on OK on all opened windows to close them
    • Save the report in the Spotfire library

    The query should now work

    See Also: Accessing a Web Service via IronPython
     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...