Introduction
Tableau is one of the most popular Reporting / Visualization tool for BI / Data analytics. It comes with many out-of the box connectors to pull data from some popular data sources but still it seriously lakes capability to consume data from millions of other REST / SOAP data sources out there for which Tableau not going to create native connectors.
In this article we will cover how to import REST API in Tableau, We will also look at various examples to read from Files or any JSON / XML SOAP / CSV API in few clicks. We will use ZappySys API Drivers to read data from Web API or Local XML / JSON / CSV Files without doing any coding or ETL.
ZappySys API drivers are most advanced API drivers available in the market with many options to connect to virtually any REST / SOAP API data source. For demo purpose we will load ODATA API (JSON Format) using ZappySys JSON Driver. Concepts / steps listed in this articles are mostly same for other type of API formats too (e.g. XML API or CSV API).
Requirements
Before we get started for step by step tutorial, make sure following requirements are met.
- You have installed Tableau Desktop
- Make sure SQL Server Instance is installed somewhere. We will use Linked Server to access REST API. You can download FREE SQL Express Version (DB Server) and SSMS from here (Client).
- Download and Install ZappySys ODBC PowerPack (API Drivers) – These drivers must be installed on Windows Machine (Can be different than Tableau Desktop / Server)
Step By Step – Loading REST API data in Tableau
Now let’s get started. To load REST API data in Tableau using ZappySys drivers basically there are two approaches.
Approach#1 You can use direct ODBC Connection to call ZappySys Drivers
Approach#2 Use SQL Server Connection in Tableau to send ZappySys Driver queries to ZappySys Data Gateway (using Linked Server OPENQUERY).
We recommend Approach#2 for any ZappySys driver use case in Tableau. Now you must be wondering why use approach#2 and not #1 ? Tableau doesn’t play well when it comes to 3rd party ODBC drivers because behind the scene Tableau generate complex SQL statements which may not be supported by ODBC driver its trying to call (e.g. JOIN Syntax, CAST functions, Sub queries). See some issues like this and this one. So if we use SQL Server to wrap those complex queries then it becomes much simpler because Tableau has very good support for SQL Server compared to 3rd party ODBC Drivers.
To access REST API in tableau using SQL Server Connection, you have to perform the following high level steps.
- Make sure you have access to Microsoft SQL Server instance. If you don’t have one you can always use lightweight FREE SQL Express Edition (Download). This is free for Production use too.
- Install ZappySys ODBC PowerPack (API Drivers)
- Configure ZappySys Data Gateway (Create API connection) – We will see in depth, later in this article.
- Create Linked Server in Microsoft SQL Server and connect to ZappySys Data Gateway
- Import API data in Tableau using Microsoft SQL Server Connector by calling Linked Server SQL Queries
Assuming you have already done first step lets get started with remaining steps. You can also read this article for other example of calling SQL Server Queries via ZappySys Data Gateway.
Configure ZappySys Data Gateway
Configure Data Gateway User / Port
Now let's look at steps to configure Data Gateway after installation. We will also create a sample data source for ODATA API (i.e. JSON based REST API Service).- Assuming you have installed ZappySys ODBC PowerPack using default options (Which also enables Data Gateway Service)
- Search "Gateway" in your start menu and click ZappySys Data Gateway
- First make sure Gateway Service is running (Verify Start icon is disabled)
- Also verify Port on General Tab
- Now go to Users tab. Click Add icon to add a new user. Check Is admin to give access to all data sources you add in future. If you don't check admin then you have to manually configure user permission for each data source.
Configure Data Source
- After user is added, go to Data Sources tab. Click Add icon to create new data source. Select appropriate driver based on your API / File format. You can choose Generic ODBC option to read data from ODBC DSN or use Native Driver option.
NOTE: Whenever possible use native driver option for better performance / security and ease of use.
- Click on "Edit" under Data source and configure as per your need (e.g. Url, Connection, Request Method, Content Type, Body, Pagination etc.). For this demo we are going to pick simple JSON REST API which doesn't need any authentication. Enter following URL.
https://services.odata.org/V3/Northwind/Northwind.svc/Invoices?$format=json
- You can also view response structure and select default hierarchy (i.e. Filter) like below (Select Array Icon) for data extraction.
Test SQL Query / Preview Data
- Now go to Preview Tab. You can click Preview button to execute default query OR Select Table name from dropdown to generate SQL with column names.
- You can also click Query Builder to generate SQL using different options in WITH clause. ANy setting you specify in WITH clause will override UI settings we applied in previous steps.
- There is another useful option for code generation. Select your Language and quickly copy code snippet. See below Example of XML Driver Query to call SOAP API.
- Click OK to Close Data Source UI
- Once data source is tested and configured you can click Save button in the Gateway UI toolbar and click Yes for Restart Service.
Create Linked Server in SQL Server
Once REST API Data source is configured in ZappySys Data Gateway, we can move forward to creating Linked Server part. At this point, you must be wondering why I have to use SQL Server to call ZappySys ODBC Driver? Why can’t I directly use ZappySys ODBC Driver in Tableau?
Technically, you can use Generic ODBC Connector in Tableau to call ZappySys ODBC Drivers for JSON API / XML API or CSV API but there are many problems with it.
Tableau Generic ODBC Connection option generates many unsupported SQL Syntax (e.g. Temp tables, Subqueries, date functions) which may not be supported by most non-relational ODBC drivers (e.g. ZappySys API drivers). Using SQL Server Linked Server we can bridge between ZappySys Drivers and Tableau to access any REST API. So let’s see how to do this.
- Assuming you have installed SQL Server and SSMS. If not then get both for FREE from here: Get SQL Server Express and Get SSMS
- Open SSMS and connect to SQL Server.
- Go to Root > Server Objects > Linked Servers node. Right click and click New Linked Server...
- Now enter linked server name, select Provider as SQL Native Client
- Enter data source as GatewayServerName,PORT_NUMBER where server name is where ZappySys Gateway is running (Can be same as SQL Server machine or remote machine). Default PORT_NUMBER is 5000 but confirm on Data gateway > General tab incase its different.
- Enter Catalog Name. This must match name from Data gateway Data sources grid > Name column
- Click on Security Tab and select last option "Be made using this security context". Enter your gateway user account here.
-
Optional: Under the Server Options Tab, Enable RPC and RPC Out and Disable Promotion of Distributed Transactions(MSDTC).
You need to enable RPC Out if you plan to use EXEC(...) AT [MY_LINKED_SERVER_NAME] rather than OPENQUERY.
If don't enabled it, you will encounter the 'Server "MY_LINKED_SERVER_NAME" is not configured for RPC' error.Query Example:
EXEC('Select * from Products') AT [MY_LINKED_SERVER_NAME]
If you plan to use 'INSERT INTO...EXEC(....) AT [MY_LINKED_SERVER_NAME]' in that case you need to Disable Promotion of Distributed Transactions(MSDTC).
If don't disabled it, you will encounter the 'The operation could not be performed because OLE DB provider "SQLNCLI11" for linked server "MY_LINKED_SERVER_NAME" was unable to begin a distributed transaction.' error.Query Example:
Insert Into dbo.Products EXEC('Select * from Products') AT [MY_LINKED_SERVER_NAME]
- Click OK to save Linked Server
- In SSMS execute below SQL query to test your connectivity.
SELECT * FROM OPENQUERY( MY_LINKED_SERVER_NAME, 'SELECT * FROM $')
--OR--SELECT * FROM OPENQUERY( MY_LINKED_SERVER_NAME, 'SELECT * FROM $ WITH (Src=''https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json'' ,Filter=''$.value[*]'' ,DataFormat=''OData'' )');
- Here is the preview after you run some REST API query in SQL Server. Notice that you can override default configuration by supplying many parameters in WITH clause (second query example in screenshot).
- You can wrap your queries inside View or wrap inside Stored procedure to parameterize. Here is an example of create view which calls REST API queries. Below View can be consumed like a normal table from any Tools or Programming Language which supports connectivity to SQL Server.
CREATE VIEW dbo.vwApiInvoices AS /*Call REST API inside SQL Server View*/ SELECT * FROM OPENQUERY( LS , 'SELECT * FROM $ WITH (Src=''https://services.odata.org/V3/Northwind/Northwind.svc/Invoices?$format=json'' ,Filter=''$.value[*]'' ,DataFormat=''OData'' )'); GO
- Notice in above approach if you parameterize Stored Procedure then check this article to understand Dynamic Metadata.
- That's it. We are now ready to move forward with more interesting things in next section.
Import REST API data in Tableau using Microsoft SQL Server Connector
Now we are ready to call REST API in Tableau. Perform following steps to Connect REST API to Tableau.
- Open Tableau Desktop and click File > New
- To create new Connection click More > Microsoft SQL Server > Enter your credentials to connect to SQL Server.
- Once connection is created for SQL Server we can read REST API data 3 different ways
- Query View which contains OPENQUERY to Linked Server for REST API data
- Use direct SQL Query using OPENQUERY
- Use Stored Procedure (Mostly useful to parameterize calls
- See below example to pull data from REST API in Tableau using SQL View approach
- Here is how to Create Data Source using direct SQL Query. You can enter following Example Query.
12345SELECT * FROM OPENQUERY( YOUR_LINKED_SERVER ,'SELECT * FROM $WITH (Src=''https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json'',Filter=''$.value[*]'')'); - Once your data sources are created you can click on Sheet1 and drag fields to create visualizations for Tableau Dashboard.
Passing Parameters to REST API calls in Tableau (Dynamic SQL)
Now let’s look at scenario where you have to pass parameters to build Dynamic Dashboard. You can try to insert Parameters in your Direct SQL when you build Dynamic SQL but we found some issues with that so we are going to suggest Stored Procedure approach. For more information on Known issue on Dynamic Metadata Check this post.
- First lets create a stored procedure in SQL Server for Parameter Example. Notice how we added WITH RESULT SETS in the code to describe metadata.
12345678910111213141516171819202122232425262728--DROP PROC dbo.usp_GetInvoicesByCountry--GO/*Purpose: Parameterize REST API call via SQL. Call ZappySys Drivers inside SQL Server.*/CREATE PROC dbo.usp_GetInvoicesByCountry@country varchar(100)ASDECLARE @sql varchar(max)--//Escape single ticks carefullySET @sql = 'SELECT OrderID,CustomerID,Country,Quantity FROM $WITH (Src=''https://services.odata.org/V3/Northwind/Northwind.svc/Invoices?$format=json&filter=Country eq '+ @country +''',Filter=''$.value[*]'',DataFormat=''OData'')'DECLARE @sqlFull varchar(max)SET @sqlFull='SELECT * FROM OPENQUERY( LS , ''' + REPLACE( @sql, '''', '''''' ) + ''' )'PRINT @sqlFull --//For DEBUG purposeEXECUTE (@sqlFull)WITH RESULT SETS ((OrderID int,CustomerID varchar(100),Country varchar(100),Quantity int) --//describe first result. If you don't do this then wont work in Tableau)GO-- Example callEXEC dbo.usp_GetInvoicesByCountry @country='Germany' - Once you create a stored procedure go to Tableau datasource and select Database which contains the stored procedure we just created.
- Now find your stored proc and drag it on the datasource pane. You will see parameters UI as below. You can create new parameter – Select New Parameter under Value Column.
- Thats it now you can reuse your parameterized datasource anywhere in Dashboard.
- If you have need to select Parameters from predefined values rather than free text then edit your parameter and select List option. Define values you like to select from as below.
- When you create Tableau Dashboard you will see Parameter dropdown (If you selected List) elase you may see Textbox to enter custom value.
Read data from JSON Files in Tableau (Single or Multiple)
So far we have seen how to read data from REST API but there will be a time to read data from JSON Files (Single or Multiple). Also files may be compressed (GZip or Zip). Regardless no worries if you are using ZappySys drivers. See below sample query you can submit via SQL Linked Server to read JSON files stored on network share.
Single File Example
1 2 3 4 5 6 |
SELECT * FROM OPENQUERY([MY_LINKED_SERVER] , 'SELECT * FROM $ WITH( Src=''c:\ssis\large_2018.json'' ,Filter=''$.Branches[*]'' )') |
Multiple Files Example
1 2 3 4 5 6 |
SELECT * FROM OPENQUERY([MY_LINKED_SERVER] , 'SELECT * FROM $ WITH( Src=''c:\ssis\large_*.json'' ,Filter=''$.Branches[*]'' )') |
Read Compressed Files (GZip / Zip Format)
1 2 3 4 5 6 7 8 |
SELECT * FROM OPENQUERY([MY_LINKED_SERVER] , 'SELECT * FROM $ WITH( Src=''c:\ssis\large_*.json.gz'' --Src=''https://zappysys.com/downloads/files/test/large_file_10k.json.gz'' ,Filter=''$.Branches[*]'' ,FileCompressionType=''GZip'' --OR-- Zip --OR-- None )') |
Read CSV Files or URL in Tableau
If you like to read data from CSV files or URL then you can use ZappySys CSV Driver same way.
Here is sample query for CSV data.
Reading Compressed CSV Files in Tableau
1 2 3 4 5 6 7 8 |
SELECT * FROM OPENQUERY([MY_API_SERVICE] , 'SELECT * FROM $ WITH( Src=''https://zappysys.com/downloads/files/test/customerdata.csv.gz'' ,FileCompressionType=''GZip'' --OR-- Zip --OR-- None ,ColumnDelimiter=''|'' ,HasColumnHeaderRow=''False'' )') |
Read multiple files (TAB delimited) in Tableau
1 2 3 4 5 6 7 |
SELECT * FROM OPENQUERY([MY_API_SERVICE] , 'SELECT * FROM $ WITH( Src=''''c:\ssis\customerdata_*.csv'''' ,ColumnDelimiter=''{tab}'' --or use \t for tab delimited files ,HasColumnHeaderRow=''True'' )') |
Read XML Files or API in Tableau
If you like to read data from XML files or URL then you can use ZappySys XML Driver same way. See below example to read some data from XML Web API. We have also passed credentials along with it for demo purpose.
1 2 3 4 5 6 7 8 9 10 11 |
SELECT * FROM OPENQUERY([MY_API_SERVICE] , 'SELECT * FROM $ WITH( ElementsToTreatAsArray=''item,slide'' ,Src=''http://httpbin.org/xml'' ,DataConnectionType=''HTTP'' ,UserName=''user1'' ,CredentialType=''Basic'' ,Password=''P@11s#'' ,Filter=''$.slideshow.slide[*]'' )') |
Read local XML files
1 2 3 4 5 6 |
SELECT * FROM OPENQUERY([MY_API_SERVICE] , 'SELECT * FROM $ WITH ( SRC=''C:\Data\CustomerData.xml'' , Filter=''$.Root.Row[*]'' , ElementsToTreatAsArray=''Row'' )') |
Call POST REST API in Tableau
There will be a time when you like to submit API request as POST rather than GET. See below example how to write POST API Request to send Body along with Custom Headers and Method.
POST Body, Set Method, Headers
1 2 3 4 5 6 7 8 9 10 11 |
SELECT * FROM OPENQUERY([MY_API_SERVICE] , 'SELECT * FROM $ WITH (METHOD=''POST'', HEADER=''Content-Type: text/plain || x-hdr1: AAA'' ,SRC=''http://httpbin.org/post'' ,BODY='' { id:1, notes:"Line1\r\nLine2" }'' )') |
Call SOAP API using XML Driver (POST data) – Token based Authentication
Here is another interesting example to call XML SOAP API. It first authenticates and get Token from SOAP Response. Then use that token for API call. To read more about Dynamic Token Method check this article.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
SELECT * FROM OPENQUERY([MY_API_SERVICE] , 'SELECT * FROM $ WITH( ElementsToTreatAsArray=''urn:Row'' ,Src=''https://zappysys.com/downloads/files/test/soap-getdata.aspx'' ,DataConnectionType=''HTTP'' ,AuthScheme=''{none}'' ,TokenUrl=''https://zappysys.com/downloads/files/test/soap-login.aspx'' ,TokenRequestData='' <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com"> <soapenv:Body> <urn:login> <urn:username>[$userid$]</urn:username> <urn:password>[$password$]</urn:password> </urn:login> </soapenv:Body> </soapenv:Envelope>'' ,TokenRequestMethod=''POST'' ,TokenResponseContentFilter=''//*[local-name() = ''''sessionid'''']'' ,TokenRequestHeaders=''Content-Type:text/xml|Accept:*/*|Cache-Control:no-cache'' ,TokenResponseContentType=''Xml'' ,UserName=''MyUser001'' ,Password=''P@$$w0rdAAc12'' ,CredentialType=''TokenDynamic'' ,Filter=''$.soapenv:Envelope.soapenv:Body.urn:Row[*]'' ,RequestData='' <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com"> <soapenv:Body> <urn:sessionid>[$token$]</urn:sessionid> </soapenv:Body> </soapenv:Envelope>'' ,Header=''Content-Type: text/xml;charset=UTF-8 || SOAPAction: "https://zappysys.com/soap-getdata" || Accept: */* || Cache-Control: no-cache'' ,RequestMethod=''POST'' )') |
REST API / XML SOAP Pagination Settings for Tableau
Paginate by Response Attribute
This example shows how to paginate API calls where you need to paginate until the last page detected. In this example, next page is indicated by some attribute called nextlink (found in response). If this attribute is missing or null then it stops fetching the next page.SELECT * FROM $ WITH( SRC=@'https://zappysys.com/downloads/files/test/pagination_nextlink_inarray_1.json' ,NextUrlAttributeOrExpr = '$.nextlink' --keep reading until this attribute is missing. If attribute name contains dot then use brackets like this $.['my.attr.name'] )
Paginate by URL Parameter (Loop until certain StatusCode)
This example shows how to paginate API calls where you need to pass page number via URL. The driver keeps incrementing page number and calls next URL until the last page detected (401 error). There are few ways to indicate the last page (e.g. By status code, By row count, By response size). If you don't specify end detection then it will use the default (i.e. No records found).SELECT * FROM $ WITH ( SRC=@'https://zappysys.com/downloads/files/test/page-xml.aspx?page=1&mode=DetectBasedOnResponseStatusCode' ,PagingMode='ByUrlParameter' ,PagingByUrlAttributeName='page' ,PagingByUrlEndStrategy='DetectBasedOnResponseStatusCode' ,PagingByUrlCheckResponseStatusCode=401 ,IncrementBy=1 )
Paginate by URL Path (Loop until no record)
This example shows how to paginate API calls where you need to pass page number via URL Path. The driver keeps incrementing page number and calls next URL until the last page is detected. There are few ways to indicate the last page (e.g. By status code, By row count, By response size). If you don't specify end detection then it will use the default (i.e. No records found).SELECT * FROM $ WITH ( SRC=@'https://zappysys.com/downloads/files/test/cust-<%page%>.xml' ,PagingMode='ByUrlPath' ,PagingByUrlAttributeName='<%page%>' ,PagingByUrlEndStrategy='DetectBasedOnRecordCount' ,IncrementBy=1 )
Paginate by Header Link (RFC 5988)
API like GitHub / Wordpress use Next link in Headers (RFC 5988)SELECT * FROM $ LIMIT 25 WITH( Src='https://wordpress.org/news/wp-json/wp/v2/categories?per_page=10' ,PagingMode='ByResponseHeaderRfc5988' ,WaitTimeMs='200' --//wait 200 ms after each request )
REST API / SOAP Web Service Connection Settings for Tableau
- HTTP
- OAuth
HTTP Connection
- SOAP WSS (when accessing a SOAP WebService)
- Static Token / API Key (when need to pass an API key in HTTP header)
- Dynamic Token (same as Static Token method except that each time you need to log in and retrieve a fresh API key)
- JWT Token (As per RFC 7519)
OAuth
If you are trying to access REST API resource, it is a huge chance, you will need to use OAuth Connection. Read this article to understand how OAuth authentication and authorization works and how to use it (article originally was written for SSIS PowerPack, but the concepts and UI stay the same): https://zappysys.com/blog/rest-api-authentication-with-oauth-2-0-using-ssisOther settings for REST API / SOAP XML Call in Tableau
API Limit / Throttling
While calling public API or other external web services one important aspect you have to check, how many requests are allowed by your API. Especially when you use API pagination options to pull many records you have to slow down based on API limits. For example, your API may allow you only 5 requests per second. Use Throttling Tab on Driver UI to set delay after each request.2D Array Transformation
If you are using JSON or XML API Driver then possible you may have to transform your data using 2D array transformation feature. Check this link for more information.REST API / XML SOAP Performance Tips for Tableau
Use Server-side filtering if possible in URL or Body Parameters
Many API supports filtering your data by URL parameters or via Body. Whenever possible try to use such features. Here is an example of odata API, In the below query the first query is faster than the second query because in the first query we filter at the server.SELECT * FROM value WITH( Src='https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json&$filter=Country eq ''USA''' ,DataFormat='Odata' ) -- Slow query - Client-side filtering SELECT * FROM value WHERE Country ='USA' WITH( Src='https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json' ,DataFormat='Odata' )
Avoid Special features in SQL Query (e.g. WHERE, Group By, Order By)
ZappySys API engine triggers client-side processing if special features are used in Query. Following SQL Features will trigger Client-Side processing which is several times slower than server-side processing. So always try to use simple query (Select col1, col2 .... from mytable )- WHERE Clause
- GROUP BY Clause
- HAVING Clause
- ORDER BY
- FUNCTIONS (e.g. Math, String, DateTime, Regex... )
Consider using pre-generated Metadata / Cache File
Use META option in WITH Clause to use static metadata (Pre-Generated)There are two more options to speedup query processing time. Check this article for details.-
select * from value WITH( meta='c:\temp\meta.txt' ) --OR-- select * from value WITH( meta='my-meta-name' ) --OR-- select * from value WITH( meta='[ {"Name": "col1", "Type": "String", Length: 100}, {"Name": "col2", "Type": "Int32"} ...... ]' )
- Enable Data Caching Options (Found on Property Grid > Advanced Mode Only )
Consider using Metadata / Data Caching Option
ZappySys API drivers support Caching Metadata and Data rows to speed up query processing. If your data doesn't change often then you can enable this option to speed up processing significantly. Check this article for details how to enable Data cache / metadata cache feature for datasource level or query level. To define cache option at query level you can use like below.SELECT * FROM $ WITH ( SRC='https://myhost.com/some-api' ,CachingMode='All' --cache metadata and data rows both ,CacheStorage='File' --or Memory ,CacheFileLocation='c:\temp\myquery.cache' ,CacheEntryTtl=300 --cache for 300 seconds )
Use --FAST Option to enable Stream Mode
ZappySys JSON / XML drivers support --FAST suffix for Filter. By using this suffix after Filter driver enables Stream Mode, Read this article to understand how this works.SELECT * FROM $ LIMIT 10 --//add this just to test how fast you can get 10 rows WITH( Filter='$.LargeArray[*]--FAST' --//Adding --FAST option turn on STREAM mode (large files) ,SRC='https://zappysys.com/downloads/files/test/large_file_100k_largearray_prop.json.gz' --,SRC='c:\data\large_file.json.gz' ,IncludeParentColumns='False' --//This Must be OFF for STREAM mode (read very large files) ,FileCompressionType='GZip' --Zip or None (Zip format only available for Local files) )
Calling SOAP Web Service in Tableau
What is SOAP Web Service?
If you are new to SOAP Web Service sometimes referred as XML Web Service then please read some concept about SOAP Web service standard from this link There are two important aspects in SOAP Web service.- Getting WSDL file or URL
- Knowing exact Web Service URL
What is WSDL
In very simple term WSDL (often pronounced as whiz-dull) is nothing but a document which describes Service metadata (e.g. Functions you can call, Request parameters, response structure etc). Some service simply give you WSDL as xml file you can download on local machine and then analyze or sometimes you may get direct URL (e.g. http://api.mycompany.com/hr-soap-service/?wsdl )Example SQL Query for SOAP API call using ZappySys XML Driver
Here is an example SQL query you can write to call SOAP API. If you not sure about many details then check next few sections on how to use XML Driver User Interface to build desired SQL query to POST data to XML SOAP Web Service without any coding.SELECT * FROM $ WITH( Src='http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx' ,DataConnectionType='HTTP' ,CredentialType='Basic' --OR SoapWss ,SoapWssPasswordType='PasswordText' ,UserName='myuser' ,Password='pass$$w123' ,Filter='$.soap:Envelope.soap:Body.GetHolidaysAvailableResponse.GetHolidaysAvailableResult.HolidayCode[*]' ,ElementsToTreatAsArray='HolidayCode' ,RequestMethod='POST' ,Header='Content-Type: text/xml;charset=UTF-8 || SOAPAction: "http://www.holidaywebservice.com/HolidayService_v2/GetHolidaysAvailable"' ,RequestData=' <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hol="http://www.holidaywebservice.com/HolidayService_v2/"> <soapenv:Header/> <soapenv:Body> <hol:GetHolidaysAvailable> <!--type: Country - enumeration: [Canada,GreatBritain,IrelandNorthern,IrelandRepublicOf,Scotland,UnitedStates]--> <hol:countryCode>UnitedStates</hol:countryCode> </hol:GetHolidaysAvailable> </soapenv:Body> </soapenv:Envelope>' )Now let's look at steps to create SQL query to call SOAP API. Later we will see how to generate code for your desired programming language (e.g. C# or SQL Server)
Video Tutorial - Introduction to SOAP Web Service and SoapUI tool
Before we dive into details about calling SOAP API using ZappySys XML Driver, lets first understand what is SOAP API and how to create SOAP requests using SoapUI tool. You will learn more about this process in the later section. The video contains some fragment about using SOAP API in SSIS but just ignore that part because we will be calling Soap API using ZappySys ODBC Driver rather than SSIS Components.Using SoapUI to test SOAP API call / Create Request Body XML
Assuming you have downloaded and installed SoapUI from here, now we are ready to use WSDL for your SOAP Web Service Calls. If you do not have WSDL file or URL handy then contact your API provider (sometimes you just have to add ?wsdl at the end of your Service URL to get WSDL so try that. Example: http://mycompany/myservice?wsdl ). If you don't know what is WSDL then in short, WSDL is Web service Description Language (i.e. XML file which describes your SOAP Service). WSDL helps to craft SOAP API request Body for ZappySys XML Driver. So Let's get started.- Open SoapUI and click SOAP button to create new SOAP Project
- Enter WSDL URL or File Path of WSDLFor example WSDL for our sample service can be accessed via this URL
http://www.dneonline.com/calculator.asmx?wsdl
Create new SOAP API Project in SoapUI tool for SOAP API Testing - Once WSDL is loaded you will see possible operations you can call for your SOAP Web Service.
- If your web service requires credentials then you have to configure it. There are two common credential types for public services (SOAP WSS or BASIC )
-
To use SOAP WSS Credentials select request node and enter UserId, Password, and WSS-PasswordType (PasswordText or PasswordHash)Configure SOAP WSS Credentials for SoapUI (SOAP API Testing Tool)
- To use BASIC Auth Credentials select request node and double-click it. At the bottom click on Auth (Basic) and From Authorization dropdown click Add New and Select Basic.
Configure Basic Authorization for SoapUI (SOAP API Testing Tool)
-
- Now you can test your request first Double-click on the request node to open request editor.
- Change necessary parameters, remove optional or unwanted parameters. If you want to regenerate request you can click on Recreate default request toolbar icon.
Create SOAP Request XML (With Optional Parameters)
- Once your SOAP Request XML is ready, Click the Play button in the toolbar to execute SOAP API Request and Response will appear in Right side panel. Test SOAP API using SoapUI Tool (Change Default XML Body / Parameters, Execute and See Response)
Create DSN using ZappySys XML Driver to call SOAP API
Once you have tested your SOAP API in SoapUI tool, we are ready to use ZappySys XML driver to call SOAP API in your preferred BI tool or Programming language.- First open ODBC Data Sources (search ODBC in your start menu or go under ZappySys > ODBC PowerPack > ODBC 64 bit)
- Goto System DSN Tab (or User DSN which is not used by Service account)
- Click Add and Select ZappySys XML Driver ZappySys ODBC Driver for XML / SOAP API
- Configure API URL, Request Method and Request Body as below ZappySys XML Driver - Calling SOAP API - Configure URL, Method, Body
- (This step is Optional) If your SOAP API requires credentials then Select Connection Type to HTTP and configure as below.
ZappySys XML Driver - Configure SOAP WSS Credentials or Basic Authorization (Userid, Password)
- Configure-Request Headers as below (You can get it from Request > Raw tab from SoapUI after you test the request by clicking the Play button) Configure SOAP API Request Headers - ZappySys XML Driver
- Once credentials entered you can select Filter to extract data from the desired node. Make sure to select array node (see special icon) or select the node which contains all necessary columns if you don't have array node. Select Filter - Extract data from nested XML / SOAP API Response (Denormalize Hierarchy)
- If prompted select yes to treat selected node as Array (This is helpful when you expect one or more record for selected node) Treat selected node as XML Array Option for SOAP API Response XML
Preview SOAP API Response / Generate SQL Code for SOAP API Call
Once you configure settings for XML Driver now you can preview data or generate example code for desired language (e.g. C#, Python, Java, SQL Server). Go to Preview tab and you will see default query generated based on settings you entered in previous sections. Attributes listed in WITH clause are optional. If you omit attribute in WITH clause it will use it from Properties tab.Preview Data
Preview SOAP API Response in ZappySys XML DriverGenerate Code Option
Conclusion
Tableau has no out of the box features to consume many Web API / JSON / XML data sources out there. ZappySys has developed most innovative drivers which can connect to virtually any REST API / SOAP data sources in Tableau. These drivers also capable reading local files in JSON / CSV or XML format. Feel free to download ZappySys Drivers here and try yourself . You can always contact ZappySys Support Team here if you need any API integration help.