Introduction
JSON / REST API is becoming more and more popular each day as everyone embrace cloud-centric services. This article is primarily focused on Informatica users who want to do XML SOAP/ JSON / REST API Integration in Informatica. However many tips and techniques described in this article will help you to understand how to integrate XML SOAP / JSON / REST API in other ETL / Reporting apps such as Tableau, Power BI, SSRS, Talend, Excel and many more.
After going through this article you will learn how to Read JSON in Informatica and understand the concept of JSON / REST API. We will go through many screenshots and step-by-step examples to demonstrate JSON File or REST API integration in Informatica PowerCenter.
XML / JSON can come from a local file or REST API service (internal or public) so we will include both examples in this article (i.e. Read JSON files in Informatica, Import REST API in Informatica). So let’s get started. Next article will focus on how to write data to API in Informatica (POST / PUT data)
Requirements
This article assumes that you have full filled following basic requirements.
- Download Install ZappySys ODBC PowerPack (Drivers for JSON and REST API)
- Install Informatica PowerCenter Client Tools (e.g. Workflow and Mapping Designers)
- Access to a Relational database such as SQL Server (or use any of your choice e.g. Oracle, MySQL, DB2 ). If nothing available then you can use flat file target.
How to Import JSON data using Informatica (Read JSON Files or REST API)
Before we dive deep to learn how to load JSON data in Informatica (JSON to SQL Table), Here the summary of high-level steps you need to perform to import JSON Files or REST API in Informatica.
- Download and Install ZappySys JSON ODBC Driver (for JSON Files and REST API)
- Create ODBC DSN using ZappySys JSON driver for your API Service (You can override most of the DSN settings via SQL Query at runtime)
- Create Relational > ODBC Connection in Informatica Workflow designer (Point to JSON DSN we created in the previous step)
- Import JSON Source Definition in the Informatica Mapping Designer > Sources Tab
- Import Target Table Definition in the Informatica Mapping Designer > Targets Tab
- Create source to target mapping in Mappings tab
- Save mapping (name m_API_to_SQL_Load )
- Create Session using the mapping we created in the previous step
- Save Workflow and execute to load JSON data into SQL Table. Verify your data and log.
Video Tutorial – Read JSON in Informatica (Load JSON to SQL Table)
By watching following ~5 min video can learn steps listed in this article to load JSON API data into SQL Server Table using ZappySys JSON Driver. You can go though full article to learn many useful details not covered in this video.
Getting Started – Import JSON to SQL Server in Informatica
Now let’s get started. For example purpose, we will read data from OData JSON based REST API service and load data into SQL Server Table using Informatica Workflow.
Create ODBC DSN using ZappySys JSON Driver
The first step to read from JSON File or REST API Service in Informatica is to create ODBC DSN.
- Search for ODBC in your start menu and open ODBC Data Sources (64bit). You can also find same under ZappySys > ODBC PowerPack > ODBC Data Sources (64bit)
- When ODBC UI shows up, Go to System tab.
- Click on Add
- Select ZappySys JSON Driver from the list and click Finish.
- When Configuration UI enter the following URL for Data source. You can also enter JSON File path here too but for this example, we will use OData REST API (JSON Format). Click Test to confirm its working. This API doesn’t use any credentials but in the real world, you may have credentials (e.g. OAuth creds using Key / Secret or Basic Auth using UserID / Password). Below URL is default URL for your DSN. You can always override URL and other settings from SQL Query using WITH Clause (see examples)
1https://services.odata.org/V3/Northwind/Northwind.svc/Invoices?$format=json - Optionally one more setting you can change is Under Other settings >>> Date data type set option to Convert to DateTime (Timezone lost). If you don’t do this then OrderDate field or any other Date Field will be detected as nstring in Informatica. Later in this section, we will show you how to convert nstring to DateTime using Expression Transform (TO_DATE function).
- Now switch to Preview Tab and try some sample queries to learn more about API driver. For example, you can try some with simple queries like below. For more advanced queries read this help file.Read from root level (include all attributes)
1select * from $
123select * from value--OR--select * from $ WITH (Filter='$.value[*]')
123SELECT * FROM $WITH (SRC='https://api.hubapi.com/contacts/v1/lists/all/contacts/all?hapikey=demo&count=20',Filter='$.contacts[*]') - Click on View Examples to check other example queries
- Click OK to save your DSN Properties.
- Click OK to close ODBC Data SOurces UI.
Create Connection in Informatica Workflow Designer
Once you create DSN using JSON Driver our next step is to define a connection for JSON source in Informatica PowerCenter Workflow designer.
- Open Workflow designer [W] icon
- Goto Connections > Relational
- Click New and select ODBC
- Now on the ODBC connection setup enter connection name, some fake userid / password (this is a required field but its ignored by JSON Driver)
- In the Connection String field enter the exact same name of DSN (Open ODBC Data Sources UI to confirm)
- Click OK to close the connection properties.
That’s it. Now we ready to move to next step (define source and target in Mapping Designer).
Import JSON Source Definition in Informatica Mapping Designer
Now let’s look at steps to import JSON source table definition.
- Open Informatica Mapping Designer (Click [D] icon)
- Click on Source Icon to switch to Sources designer
- From the top menu > Click on Sources > Import from Database …
- Select ODBC data source from the dropdown (Find out DSN we created earlier to use as JSON Source)
- Click Connect button to get a list of tables. Any array node is listed as a table. Also, you will see array node with parent columns (e.g. value_with_parent). You may get some warning like below but they are harmless so just ignore by clicking OK.
DLL name entry missing from C:\Informatica\PowerCenter8.6.1\client\bin\powrmart.ini Section = ODBCDLL Entry = ZappySys JSON Driver
—————————————————-
Using EXTODBC.DLL to support ZappySys JSON Driver. For native support of ZappySys JSON Driver make an entry in the .ini file. - Select Table you wish to get (You can filter rows by custom SQL query. We will see later in this article how to do)
- Optionally once table structure is imported you can rename it
- That’s it, we are now ready to perform similar steps to import Target table structure in the next section.
Import SQL Server Target Definition in Informatica Mapping Designer
Now let’s look at steps to import Target table definition (very similar to the previous section, the only difference is this time we will select DSN which points to SQL Server or any other Target Server). For example purpose, we will use following table structure as our SQL Server Table. If its missing you can create one.
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 |
CREATE TABLE [dbo].[Tbl_Invoices]( [ShipName] [nvarchar](40) NULL, [ShipAddress] [nvarchar](60) NULL, [ShipCity] [nvarchar](15) NULL, [ShipRegion] [nvarchar](15) NULL, [ShipPostalCode] [nvarchar](10) NULL, [ShipCountry] [nvarchar](15) NULL, [CustomerID] [nchar](5) NULL, [CustomerName] [nvarchar](40) NULL, [Address] [nvarchar](60) NULL, [City] [nvarchar](15) NULL, [Region] [nvarchar](15) NULL, [PostalCode] [nvarchar](10) NULL, [Country] [nvarchar](15) NULL, [Salesperson] [nvarchar](31) NULL, [OrderID] [int] NULL, [OrderDate] [datetime] NULL, [RequiredDate] [datetime] NULL, [ShippedDate] [datetime] NULL, [ShipperName] [nvarchar](40) NULL, [ProductID] [int] NULL, [ProductName] [nvarchar](40) NULL, [UnitPrice] [money] NULL, [Quantity] [smallint] NULL, [Discount] [real] NULL, [ExtendedPrice] [money] NULL, [Freight] [money] NULL ) |
Now lets look at steps to import target table definition in Informatica mapping designer.
- In the Mapping Designer, Click on Target Icon to switch to Target designer
- From the top menu > Click on Targets > Import from Database …
- Select DSN for your Target server (if DSN doesn’t exist then create one by opening ODBC Sources just like we created one for JSON API source (see the previous section about creating DSN).
- Enter your userid , password and Schema name and click Connect to see tables
- Select Table name to and click OK import definition.
Create Source to Target Mapping in Informatica (Import JSON to SQL Server)
Once you have imported source and target table definition, we can create mapping and transformation to load data from JSON to SQL Table.
- First open Mapping Designer (Click [D] icon)
- Drag JSON Source from sources folder
- Drag SQL Table from Targets folder
- Map desired columns from Source to target
- For certain columns you may have to do datatype conversion. For example to convert OrderDate form nstring to DataTime you have to use Expression Transform like below and map it to target. In below example, our JSON has date format (e.g. 2018-01-31 12:00:00 AM ). To import this to DateTime field in SQL server we need to convert it using TO_DATE function. Use double quotes around T to make this format working.
1234TO_DATE(OrderDate,'YYYY-MM-DD H12:MI:SS AM')--For ISO use below wayTO_DATE(OrderDate,'YYYY-MM-DD"T"HH24:MI:SS') - Once you done with mapping save your mapping and name it (i.e. m_Api_To_SQL)
- Now lets move to next section to create workflow.
Create Workflow and Session in Informatica
Now the final step is to create a new workflow. Perform following steps to create workflow which with a session task to import JSON data into SQL table.
- Open workflow designer by click [W] icon.
- Launch new workflow creation wizard by click Workflow top menu > Wizard
name your workflow (e.g. wf_Api_Tp_Sql_Table_Import) - Finish the wizard and double-click the Session to edit some default properties.
- First change Error settings so we fail session on error (By default its always green)
- Select JSON connection for Source
- Change default Source query if needed. You can pass parameters to this query to make it dynamic.
- Select Target connection of SQL Target Table
- Save workflow
- That’s it. We ready to run our first workflow to load JSON data to SQL.
Execute Workflow and Validate Log in Informatica
Now once you are done with your workflow, execute it to see the log.
Import JSON Files in Informatica (Single or multiple)
So far we have seen an example of loading JSON REST API in Informatica but loading JSON files are pretty much same process. Rather than URL, you have to specify JSON file path as Data source.
ZappySys JSON Driver is capable of reading from JSON file, REST API, and embedded JSON string.
Reading JSON data from single File Informatica
select * from $ (SRC=’c:\data\customer_2015.json’, Filter=’$.rows[*]’)
Reading JSON data from multiple Files in Informatica
select * from $ (SRC=’c:\data\customer_*.json’, Filter=’$.rows[*]’)
Reading JSON data from embedded string
1 2 3 4 5 6 7 8 9 10 11 12 13 |
SELECT * FROM $ WITH ( Filter='$.rows[*]', DATA=' { rows : [ {id:1, name: "AAA"}, {id:2, name: "BBB"}, {id:3, name: "CCC"} ] }' ) |
Import XML Files in Informatica
Reading from XML files or API can be done using the same way as previous sections except you have to use ZappySys XML Driver. Read help file here to see examples.
POST data to REST API in Informatica
There will be a time when you like to send Source data to REST API or SOAP Web Service. You can use below Query for example. For detailed explanation on how to POST data in Informatica check this article.
1 2 3 4 5 6 7 |
SELECT * FROM $ WITH (METHOD='POST' ,HEADER='Content-Type:text/plain || x-hdr1:AAA' ,SRC='http://httpbin.org/post' ,BODY='{ data of body goes here }' ) |
Video Tutorial – How to POST data to REST API in Informatica
Here is detailed step by step video on REST API POST in informatica PowerCenter
Upload file to REST API in Informatica
Above example was POST data to API URL but what if your Request Body is large and you have saved that to file? Well here is the way to get your request body from a file (Use @ symbol before path and add IsMultiPart=’True’). Refer to this post to learn more about Raw Upload and Multi-Part Upload
1 2 3 4 5 6 7 8 |
SELECT * FROM $ WITH (METHOD='POST' ,HEADER='Content-Type:text/plain || x-hdr1:AAA' ,SRC='http://httpbin.org/post' ,BODY='@c:\files\dump.xml' ,IsMultiPart='True' ) |
Calling XML SOAP Web Service in Informatica
So far we have looked at examples to consume data using JSON driver. Now lets look at an example, to call XML SOAP Web Service in Informatica.
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
REST API Pagination in Informatica
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 )
Error Handling in REST API
METHOD 1 - Using Error Handling Options
When to use?
You may want to use them when your source is a resource located on the Internet; e.g. a file on a website, a file on an FTP server or just a plain API HTTP response. By default, when a remote server returns an error, data retrieval is stopped, an error is raised and no data is given back to you. This might not be always desirable.Scenario 1
Imagine a scenario, that there is a web server which each day at 12 AM releases a new JSON file with that day's date as filename, e.g. http://www.some-server.com/data/2018-06-20.json. And, of course, you want to download it and use it daily in your Power BI report. But you have a problem: Power BI report data sources are refreshed each hour and you may get HTTP 404 status code (no file was found) when a file is not released yet. Which consequentially means other data sources won't be updated as well and you will see old and cached data on the report. That's where you could use Continue on any error or Continue when Url is invalid or missing (404 Errors) to avoid an error being raised and let other data sources to be updated.Scenario 2
Another scenario is when you expect a web server to raise some kind of HTTP error when accessing a URL. You don't want ODBC Data Source to raise an error but instead, you want to get response data. That's where you can use Continue on any error or alike together with Get response data on error to continue on an error and get the data:METHOD 2 - Using Connection [Retry Settings]
Another scenario you may run into is a buggy web server. You ask it to give you some file or data and it, like a snotty kid, just doesn't give it to you! You have to ask twice or thrice before it does its job. If that's the case, you have to retry HTTP requests using Connection:Performance consideration for REST API
Coming soon…
Security consideration for REST API
- 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-ssisConclusion
Consuming data from JSON files or REST API in Informatica can be challenging but not to worry anymore. Using ZappySys JSON Driver you get most innovative JSON processing engine which not only processes/denormalizes nested JSON but also gives you 100+ Options to cover almost any API processing scenario. You can use this driver to consume data in any ODBC compliant app (i.e. Tableau, Power BI, Excel) and Programming Languages (i.e. C#, Java, Python, PHP). Click here to Download a FREE trial of ZappySys ODBC PowerPack and learn how to perform JSON / API integration in Informatica without any coding.
Keywords
how to import json file in informatica | how to read json file in informatica powercenter | how to test json from informatica | how to use jsaon file as source in informatica power center | how to use json in informatica 10 | informatica how to import data from rest api | informatica jtx to import json file (use of java transformation) | informatica plugin for restful api using json | informatica power center and json support | informatica read json files | informatica rest api | informatica rest api connector | json parser import informatica