<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>C# (CSharp) Archives | ZappySys Blog</title>
	<atom:link href="https://zappysys.com/blog/category/odbc-powerpack/odbc-programming/programming-csharp-c/feed/" rel="self" type="application/rss+xml" />
	<link>https://zappysys.com/blog/category/odbc-powerpack/odbc-programming/programming-csharp-c/</link>
	<description>SSIS / ODBC Drivers / API Connectors for JSON, XML, Azure, Amazon AWS, Salesforce, MongoDB and more</description>
	<lastBuildDate>Tue, 06 Feb 2024 12:11:43 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.4</generator>

<image>
	<url>https://zappysys.com/blog/wp-content/uploads/2023/01/cropped-zappysys-symbol-large-32x32.png</url>
	<title>C# (CSharp) Archives | ZappySys Blog</title>
	<link>https://zappysys.com/blog/category/odbc-powerpack/odbc-programming/programming-csharp-c/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to export REST API  to CSV using c# or Python</title>
		<link>https://zappysys.com/blog/how-to-export-rest-api-to-csv/</link>
		
		<dc:creator><![CDATA[ZappySys Team]]></dc:creator>
		<pubDate>Sat, 30 Jun 2018 03:02:59 +0000</pubDate>
				<category><![CDATA[C# (CSharp)]]></category>
		<category><![CDATA[JSON File / REST API Driver]]></category>
		<category><![CDATA[ODBC PowerPack]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[rest api]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=4250</guid>

					<description><![CDATA[<p>Introduction to export REST API to CSV Export REST API to CSV is in some cases necessary to process the data because many tools can handle CSV files. In this new article, we will show different ways to export the data. The first example will do it using C#. The second example with use Python. Let&#8217;s take a [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/how-to-export-rest-api-to-csv/">How to export REST API  to CSV using c# or Python</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction to export REST API to CSV</h2>
<p><a href="https://zappysys.com/blog/wp-content/uploads/2018/06/REST-API-icon.jpg"><img decoding="async" class=" wp-image-4254 alignleft" src="https://zappysys.com/blog/wp-content/uploads/2018/06/REST-API-icon-150x150.jpg" alt="Logo REST API" width="82" height="82" /></a>Export REST API to CSV is in some cases necessary to process the data because many tools can handle CSV files. In this new article, we will show different ways to export the data. The first example will do it using C#. The second example with use Python. Let&#8217;s take a look at these examples.</p>
<h2></h2>
<h2>Requirements to export REST API to CSV</h2>
<ol>
<li>First of all, you will need <a href="https://zappysys.com/products/odbc-powerpack/download/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> installed.</li>
<li>Secondly, you will require Visual Studio installed for the C# example.</li>
<li>Finally, it is necessary Python installed for the Python example.</li>
</ol>
<h3>Export REST API to CSV using C#</h3>
<p>C# is a pretty popular programing language. In the first example, we will show how to display the REST API information to a CSV file named. Let&#8217;s take a look at the code:</p>
<ol>
<li>First of all, we will connect to REST API using a connection to the following Data Path:<br />
<pre class="crayon-plain-tag">https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json</pre>
<pre class="crayon-plain-tag">using (OdbcConnection conn = 
      new OdbcConnection("Driver={ZappySys JSON Driver};DataPath='https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json';"))</pre>
</li>
<li>Secondly, we create a connection using a file stream. We will save the results to a file in the c:\sql\sample.csv:<br />
<pre class="crayon-plain-tag">FileStream fs = new FileStream("C:\\sql\\sample.txt", FileMode.Create);
StreamWriter writer = new StreamWriter(fs);
StringBuilder output = new StringBuilder();</pre>
</li>
<li>Also, we will add a query to REST API. Note that with the ZappySys ODBC PowerPack, you can do a simple SQL query to get REST API data. This is pretty simple and intuitive:<br />
<pre class="crayon-plain-tag">OdbcCommand cmd = new OdbcCommand(
     @"SELECT  CustomerID,CompanyName FROM value", conn);</pre>
</li>
<li>In addition, we will read the data and close the connections:<br />
<pre class="crayon-plain-tag">conn.Close();  
writer.Close(); 
fs.Close();</pre>
</li>
<li>The complete code will be the following:<br />
<pre class="crayon-plain-tag">using System;
using System.IO;
using System.Data.Odbc;

public class Program
{
    public static void Main()
    {
        var outpath = @"C:\temp\sample.txt";

        using (var conn = new OdbcConnection("Driver={ZappySys JSON Driver};DataPath='https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json';"))
        {
            conn.Open();
            var cmd = new OdbcCommand(@"SELECT CustomerID,CompanyName FROM $ WITH(Filter='$.value[*]')", conn);
            
            //Increases the timeout duration from the default 30 seconds, which may be insufficient in certain scenarios.
            cmd.CommandTimeout=600; // 600-seconds
            
            var rdr = cmd.ExecuteReader();

            using (var fs = new FileStream(outpath, FileMode.Create))
            {
                using (var writer = new StreamWriter(fs))
                {
                    //write file header
                    writer.WriteLine("CustomerID,CompanyName");

                    while (rdr.Read())
                    {
                        //write file row
                        writer.WriteLine("{0},{1}", rdr["CustomerID"], rdr["CompanyName"]);
                    }
                    conn.Close(); //close connection
                    writer.Close();
                    fs.Close();
                }
            }
        }

        //Read from file and display the content
        Console.Write(File.ReadAllText(outpath));

        Console.WriteLine("\r\n===== Press any key to end the program =====\r\n");
        Console.Read();
    }
}</pre>
&nbsp;</li>
<li>Finally, you will be able to see the file created:
<div id="attachment_4258" style="width: 160px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/06/REST-API-exported-to-CSV-file.png"><img decoding="async" aria-describedby="caption-attachment-4258" class="size-thumbnail wp-image-4258" src="https://zappysys.com/blog/wp-content/uploads/2018/06/REST-API-exported-to-CSV-file-150x150.png" alt="Export REST API to CSV" width="150" height="150" /></a><p id="caption-attachment-4258" class="wp-caption-text">REST API into CSV</p></div></li>
</ol>
<h3>Export REST API to CSV using Python</h3>
<p>Python is another really popular programming language. The popularity is growing a lot. In this example, we will learn how to Export REST API to CSV using Python.</p>
<ol>
<li>First of all, you will need to install Pip if not included in Python. Pip is Package Installer.<br />
For instructions about the installation, refer to <a href="https://pip.pypa.io/en/stable/installing/" target="_blank" rel="noopener">this link.</a></li>
<li>Secondly, you will also need the pyodbc. The pyodbc allows connecting to ODBC using Python. To install it go to the scripts folder of Python where Python is installed and run this command:pip install pyodbc.</li>
<li>Once that pyodbc is installed, we will run the following code:<strong>Full Code</strong><br />
<pre class="crayon-plain-tag">import csv
import pyodbc

conn = pyodbc.connect(
    r'DRIVER={ZappySys JSON Driver};'
    )
cursor = conn.cursor()	
rows = cursor.execute("SELECT CustomerID,CompanyName FROM value WHERE COUNTRY='Germany' WITH (SRC='https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json')") 
with open(r'C:\sql\cus2.csv', 'w', newline='') as csvfile:
    writer = csv.writer(csvfile)
    writer.writerow([x[0] for x in cursor.description])  
    for row in rows:
        writer.writerow(row)</pre>
</li>
<li>Now lets&#8217;s understand parts of above code. We have used the csv and pyodbc modules in the code:<br />
<pre class="crayon-plain-tag">import csv
import pyodbc</pre>
</li>
<li>Also, we connect to the <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC Driver</a>:<br />
<pre class="crayon-plain-tag">conn = pyodbc.connect(
r'DRIVER={ZappySys JSON Driver};'
)</pre>
</li>
<li>In addition, we have used a cursor to get the rows and send a SQL query to get data from the REST API:<br />
<pre class="crayon-plain-tag">cursor = conn.cursor() 
rows = cursor.execute("SELECT CustomerID,CompanyName FROM value 
WHERE Country='Germany' WITH 
(SRC='https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json')")</pre>
</li>
<li>Following code is to open the CSV file stream:<br />
<pre class="crayon-plain-tag">with open(r'C:\sql\customer.csv', 'w', newline='') as csvfile:</pre>
</li>
<li>Finally, we will write the data from REST API into the CSV file:<br />
<pre class="crayon-plain-tag">writer = csv.writer(csvfile)
writer.writerow([x[0] for x in cursor.description]) 
for row in rows:
writer.writerow(row)</pre>
</li>
<li>To conclude, if everything is OK, you will be able to see the created CSV file:
<div id="attachment_4264" style="width: 160px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/06/CSV-file-created.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4264" class="size-thumbnail wp-image-4264" src="https://zappysys.com/blog/wp-content/uploads/2018/06/CSV-file-created-150x106.png" alt="REST API ODBC Python" width="150" height="106" /></a><p id="caption-attachment-4264" class="wp-caption-text">Python code REST API</p></div>
<div class="mceTemp"></div>
</li>
</ol>
<h2></h2>
<h2>Using ODBC DSN in Connection String</h2>
<p>So far we have seen DSN less connection string approach for ODBC Driver but now lets look at another way to use ODBC Driver in your C# or Python code. You can define many settings on DSN Datasource rather than setting in the ConnectionString.</p>
<h3>Configure DSN for REST API Connection</h3>
<ol>
<li>First of all, we will access the following URL:<br />
<pre class="crayon-plain-tag">https://services.odata.org/V3/Northwind/Northwind.svc/Orders?$format=json</pre>
</li>
<li>Secondly, in the windows start menu, Search for “ODBC” open the ODBC Data Sources.</li>
<li>Also, in the ODBC Administrator, press Add and select the ZappySys JSON<br />
Driver:</p>
<div id="attachment_4421" style="width: 471px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/07/create-new-data-source-zappysys-json-driver.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4421" class="wp-image-4421 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/07/create-new-data-source-zappysys-json-driver.png" alt="REST API ODBC " width="461" height="346" srcset="https://zappysys.com/blog/wp-content/uploads/2018/07/create-new-data-source-zappysys-json-driver.png 461w, https://zappysys.com/blog/wp-content/uploads/2018/07/create-new-data-source-zappysys-json-driver-300x225.png 300w" sizes="(max-width: 461px) 100vw, 461px" /></a><p id="caption-attachment-4421" class="wp-caption-text">Add ODBC JSON</p></div></li>
<li>Finally, specify the URL of step 1 and save the configuration:
<div id="attachment_4422" style="width: 812px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/07/Qlik-odata-url-odbc.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4422" class="size-full wp-image-4422" src="https://zappysys.com/blog/wp-content/uploads/2018/07/Qlik-odata-url-odbc.png" alt="REST API" width="802" height="702" srcset="https://zappysys.com/blog/wp-content/uploads/2018/07/Qlik-odata-url-odbc.png 802w, https://zappysys.com/blog/wp-content/uploads/2018/07/Qlik-odata-url-odbc-300x263.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/07/Qlik-odata-url-odbc-768x672.png 768w" sizes="(max-width: 802px) 100vw, 802px" /></a><p id="caption-attachment-4422" class="wp-caption-text">URL ODBC</p></div></li>
</ol>
<h3>Using ODBC DSN in C# Code</h3>
<p>Now to use ODBC DSN you created simply change our previous C# Code as below (Just one line)</p><pre class="crayon-plain-tag">using (var conn = new OdbcConnection("DSN=Your-DSN-Name-Goes-Here"))
{
    conn.Open();
    ...........
    ...........
    ...........</pre><p>
<div id="attachment_4467" style="width: 883px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/06/call-rest-api-in-csharp-odbc-json-driver.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4467" class="size-full wp-image-4467" src="https://zappysys.com/blog/wp-content/uploads/2018/06/call-rest-api-in-csharp-odbc-json-driver.png" alt="Using ODBC DSN in C# code to call REST API" width="873" height="598" srcset="https://zappysys.com/blog/wp-content/uploads/2018/06/call-rest-api-in-csharp-odbc-json-driver.png 873w, https://zappysys.com/blog/wp-content/uploads/2018/06/call-rest-api-in-csharp-odbc-json-driver-300x205.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/06/call-rest-api-in-csharp-odbc-json-driver-768x526.png 768w" sizes="(max-width: 873px) 100vw, 873px" /></a><p id="caption-attachment-4467" class="wp-caption-text">Using ODBC DSN in C# code to call REST API</p></div>
<h3>Using ODBC DSN in Python Code</h3>
<p>Now to use ODBC DSN you created simply change our previous C# Code as below (Just one line)</p><pre class="crayon-plain-tag">conn = pyodbc.connect(
    r'DSN=Your-DSN-name-Goes-Here;'
    )
	
	...........
	...........
	...........</pre><p>
&nbsp;</p>
<h2><span id="ZappySys_JSON_REST_API_Driver_Query_Examples">ZappySys JSON /REST API Driver Query Examples</span></h2>
<p>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 <a href="https://zappysys.com/onlinehelp/odbc-powerpack/scr/json-odbc-driver-sql-query-examples.htm" target="_blank" rel="noopener">see json query examples</a>.</p>
<h2><span id="ZappySysXML_SOAP_Driver_Query_Examples">ZappySys XML / SOAP Driver Query Examples</span></h2>
<p>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 <a href="https://zappysys.com/onlinehelp/odbc-powerpack/scr/xml-odbc-driver-sql-query-examples.htm" target="_blank" rel="noopener">see xml query examples</a>.</p>
<h2></h2>
<h2>Conclusion</h2>
<p>To conclude, in this article, we show how to access REST API using C# and Python. We used the ZappySys ODBC PowerPack that allows accessing to REST API data and JSON files using SQL queries. It is possible to create simple SQL queries and access the data. It is also possible to access to XML files and Web API with this tool. If you liked this tool you can test the <a href="https://zappysys.com/products/odbc-powerpack/download/" target="_blank" rel="noopener">ZappySys ODBC PowerPack here</a>.</p>
<h2>References</h2>
<p>Finally, if you want to read more about this topic, refer to these links:</p>
<ul>
<li><a href="https://zappysys.com/products/odbc-powerpack/download/" target="_blank" rel="noopener">Download ZappySys ODBC PowerPack Installer</a></li>
<li><a href="https://support.microsoft.com/en-us/help/310988/how-to-use-the-odbc-net-managed-provider-in-visual-c-net-and-connectio" target="_blank" rel="noopener">How To Use the ODBC .NET Managed Provider in Visual C# .NET and Connection Strings</a></li>
<li><a href="https://wiki.python.org/moin/ODBC" target="_blank" rel="noopener">Python ODBC Wiki</a></li>
</ul>
<p>&nbsp;</p>
<p>The post <a href="https://zappysys.com/blog/how-to-export-rest-api-to-csv/">How to export REST API  to CSV using c# or Python</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Calling REST API in C# (Read JSON Data)</title>
		<link>https://zappysys.com/blog/calling-rest-api-in-c/</link>
		
		<dc:creator><![CDATA[ZappySys Team]]></dc:creator>
		<pubDate>Tue, 26 Jun 2018 22:05:51 +0000</pubDate>
				<category><![CDATA[C# (CSharp)]]></category>
		<category><![CDATA[JSON File / REST API Driver]]></category>
		<category><![CDATA[ODBC PowerPack]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=4214</guid>

					<description><![CDATA[<p>Introduction &#8211; REST API using C# In this post, We will use ZappySys ODBC Powerpack for calling REST API in C# (i.e. CSharp). We will create an ODBC connection to REST API and consume it different ways (e..g Bind API data to Data Grid, Combo Box or Write to File). ZappySys ODBC Driver allows to connect [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/calling-rest-api-in-c/">Calling REST API in C# (Read JSON Data)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction &#8211; REST API using C#</h2>
<p>In this post, We will use ZappySys ODBC Powerpack for calling REST API in C# (i.e. CSharp). We will create an ODBC connection to REST API and consume it different ways (e..g Bind API data to Data Grid, Combo Box or Write to File). ZappySys ODBC Driver allows to connect to many other REST API such as Facebook, Google, OneDrive, SharePoint and thousands of other sources that support REST API.</p>
<h2>Requirements</h2>
<ol>
<li>First of all, you will need <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack </a>installed. This driver is a very powerful tool to connect with ODBC to REST API, JSON files, XML files, WEB API, OData and more.</li>
<li>Secondly, you will need Visual Studio Installed.</li>
</ol>
<h2>Getting Started</h2>
<p>Let&#8217;s look at few examples to consume REST API or JSON data in C# applications (WPF, Winform, Console App or even Web Application such as ASP.net MVC or Webforms).</p>
<h3>Calling REST API in C# to show REST API results in the console</h3>
<p>In order to start, we will get the values using REST API. We will use C# to get the values. In this example, we will use the following URL to get data:</p><pre class="crayon-plain-tag">https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json</pre><p>
<ol>
<li>First of all, we will first create a Visual Studio Windows form using C#.</li>
<li>Secondly, we will add the following code to get the values from the API:</p><pre class="crayon-plain-tag">using (OdbcConnection conn = new OdbcConnection("Driver={ZappySys JSON Driver};" 
     + "DataPath = 'https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json';"
     ))
{
    conn.Open();
    OdbcCommand cmd = new OdbcCommand("SELECT CustomerID,CompanyName FROM value", conn);
    
    //Increases the timeout duration from the default 30 seconds, which may be insufficient in certain scenarios.
    cmd.CommandTimeout=600; // 600-seconds
    
    var rdr = cmd.ExecuteReader();
    while (rdr.Read())
    {
        Console.WriteLine("---- Fetching Row -------");
        for (int i = 0; i &lt; rdr.FieldCount; i++)
        {
            Console.Write("Field {0}={1} ", i, rdr[i]);
        }
        Console.WriteLine("");
    }
}</pre><p>
</li>
<li>This code connects to ODBC using the ZappySys JSON Driver and connection the customers URL: Also, we open the connection and send the SQL query.  With this query, you can use a simple SQL Query to REST API. Here you have the lists of sentences in SQL supported by the driver:</p><pre class="crayon-plain-tag">SELECT
[* | [ expression [[AS] column_name_alias] [, ...] ]
[FROM table_name]
[WHERE condition [, ...] ]
[GROUP BY expression [, ...] ]
[HAVING condition [, ...] ]
[ORDER BY expression [ASC | DESC] [, ...] ]
[LIMIT row_count]
[WITH (option_name=option_value] [, ...]) ]</pre><p>
</li>
<li>Finally, we show the information in the console:
<div id="attachment_4222" style="width: 651px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/06/ODBC-Rest-API.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4222" class="size-full wp-image-4222" src="https://zappysys.com/blog/wp-content/uploads/2018/06/ODBC-Rest-API.png" alt="Visual Studio show REST API information" width="641" height="240" srcset="https://zappysys.com/blog/wp-content/uploads/2018/06/ODBC-Rest-API.png 641w, https://zappysys.com/blog/wp-content/uploads/2018/06/ODBC-Rest-API-300x112.png 300w" sizes="(max-width: 641px) 100vw, 641px" /></a><p id="caption-attachment-4222" class="wp-caption-text">C# show rest API information</p></div>
<p>&nbsp;</li>
</ol>
<p>Here is full C# code to read from REST API in C#. Create a new Console Application Project in Visual Studio (<em>File &gt; New &gt; Project &gt; Visual C# &gt; Console Application</em> )</p><pre class="crayon-plain-tag">using System;
using System.IO;
using System.Data.Odbc;

public class Program
{
    public static void Main()
    {
        var outpath = @"C:\temp\sample.txt";
        
        using (var conn = new OdbcConnection("Driver={ZappySys JSON Driver};"
            +"DataPath='https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json';"))
        {
            conn.Open();
            var cmd = new OdbcCommand(@"SELECT CustomerID,CompanyName FROM $ WITH(Filter='$.value[*]')", conn);

            //Increases the timeout duration from the default 30 seconds, which may be insufficient in certain scenarios.
            cmd.CommandTimeout=600; // 600-seconds
            var rdr = cmd.ExecuteReader();

            using (var fs = new FileStream(outpath, FileMode.Create))
            {
                using (var writer = new StreamWriter(fs))
                {
                    //write file header
                    writer.WriteLine("CustomerID,CompanyName");

                    while (rdr.Read())
                    {
                        //write file row
                        writer.WriteLine("{0},{1}", rdr["CustomerID"], rdr["CompanyName"]);
                    }
                    conn.Close(); //close connection
                    writer.Close();
                    fs.Close();
                }
            }
        }

        //Read from file and display the content
        Console.Write(File.ReadAllText(outpath));

        Console.WriteLine("\r\n===== Press any key to end the program =====\r\n");
        Console.Read();
    }
}</pre><p>
&nbsp;</p>
<h3>Calling REST API in C# to show REST API results in a combo box</h3>
<p>In the next example, we will show how to call REST API in C# and load the data in a combo box. To execute this code you need to create a <strong>WinForm Project</strong> in Visual Studio  (File &gt; New &gt; Project &gt; Visual C# &gt; Windows Form Application)</p>
<ol>
<li>First of all, in a C# project, add the following code:<br />
<pre class="crayon-plain-tag">try
{
    using (OdbcConnection conn = new OdbcConnection("Driver={ZappySys JSON Driver};DataPath='https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json';"))
    {
        conn.Open();
        OdbcCommand cmd = new OdbcCommand("SELECT CustomerID FROM value", conn);

        //Increases the timeout duration from the default 30 seconds, which may be insufficient in certain scenarios.
        cmd.CommandTimeout=600; // 600-seconds

        var rdr = cmd.ExecuteReader();
        while (rdr.Read())
        {
            Console.WriteLine("---- Fetching Row -------");
            for (int i = 0; i &lt; rdr.FieldCount; i++)
            {
                comboBox1.Items.Add(rdr[i].ToString());
            }
            Console.WriteLine("");
            conn.Close();
        }
    }
}
catch (Exception ex)
{
    MessageBox.Show(ex.ToString());
}</pre>
</li>
<li>Secondly, you will need to add a combo box in the project.</li>
<li>The code is similar to the previous example, but we are filling a<br />
combo box with the following line of code:<br />
<pre class="crayon-plain-tag">comboBox1.Items.Add(rdr[i].ToString());</pre>
</li>
<li>In addition, the query is different because we are doing a select to just<br />
one column:<br />
<pre class="crayon-plain-tag">OdbcCommand cmd = new OdbcCommand("SELECT CustomerID FROM value", conn);</pre>
</li>
<li>Finally, execute the code to see the results:
<div id="attachment_4225" style="width: 161px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-driver-rest-api-csharp-combobox.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4225" class="size-full wp-image-4225" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-driver-rest-api-csharp-combobox.png" alt="C# load data combobox" width="151" height="327" srcset="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-driver-rest-api-csharp-combobox.png 151w, https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-driver-rest-api-csharp-combobox-139x300.png 139w" sizes="(max-width: 151px) 100vw, 151px" /></a><p id="caption-attachment-4225" class="wp-caption-text">Load combo box c# REST API</p></div></li>
</ol>
<h3>Calling REST API in C# to show REST API in a Data Grid</h3>
<p>The DataGridView is very popular to retrieve data. In this example, we will show how to load REST API in the DataGridView.</p>
<ol>
<li>First of all, add the following code:<br />
<pre class="crayon-plain-tag">try
{
    string Conn = "Driver={ZappySys JSON Driver};DataPath='https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json';";
    string Sql = "select CustomerID,CompanyName from value";

    using (OdbcConnection con = new OdbcConnection(Conn))
    using (OdbcDataAdapter dadapter = new OdbcDataAdapter(Sql, con))
    {
        DataTable table = new DataTable();
        dadapter.Fill(table);

        this.dataGridView1.DataSource = table;
    }
}
catch (Exception ex)
{
    MessageBox.Show(ex.ToString());
}</pre>
</li>
<li>We first create an ODBC connection with the SQL query:<br />
<pre class="crayon-plain-tag">string Conn = "Driver={ZappySys JSON Driver};
DataPath='https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json';";
string Sql = "select CustomerID,CompanyName from value";
using (OdbcConnection con = new OdbcConnection(Conn))</pre>
</li>
<li>Also, we create a Data Table and fill with data:<br />
<pre class="crayon-plain-tag">using (OdbcDataAdapter dadapter = new OdbcDataAdapter(Sql, con))
{
     DataTable table = new DataTable();
     dadapter.Fill(table);</pre>
</li>
<li>In addition, we will add the table to the dataGridView:<br />
<pre class="crayon-plain-tag">this.dataGridView1.DataSource = table;</pre>
</li>
<li>Finally, execute the code to see the results:
<div id="attachment_4228" style="width: 279px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/06/c-rest-api-datagridview.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4228" class="size-full wp-image-4228" src="https://zappysys.com/blog/wp-content/uploads/2018/06/c-rest-api-datagridview.png" alt="Load data REST API Datagridview" width="269" height="203" /></a><p id="caption-attachment-4228" class="wp-caption-text">Datagridview c#</p></div></li>
</ol>
<h3>Read from JSON file in C# (Single or Multiple files)</h3>
<p>The ZappySys ODBC PowerPack allows connecting not only to REST API, WEB API but also to local files. In this example, we will connect to a file named test.json. Let&#8217;s take a look at this example to see how to do it:</p>
<ol>
<li>First of all, we will have a JSON file named test.json with this content:<br />
<pre class="crayon-plain-tag">{
  "value": [
    {
      "CustomerID": "ALFKI",
      "CompanyName": "Alfreds Futterkiste",
      "ContactName": "Maria Anders",
      "ContactTitle": "Sales Representative",
      "Address": "Obere Str. 57",
      "City": "Berlin",
      "Region": null,
      "PostalCode": "12209",
      "Country": "Germany",
      "Phone": "030-0074321",
      "Fax": "030-0076545"
    },
    {
      "CustomerID": "ANATR",
      "CompanyName": "Ana Trujillo Emparedados y helados",
      "ContactName": "Ana Trujillo",
      "ContactTitle": "Owner",
      "Address": "Avda. de la Constitución 2222",
      "City": "México D.F.",
      "Region": null,
      "PostalCode": "05021",
      "Country": "Mexico",
      "Phone": "(5) 555-4729",
      "Fax": "(5) 555-3745"
    },
    {
      "CustomerID": "ANTON",
      "CompanyName": "Antonio Moreno Taquería",
      "ContactName": "Antonio Moreno",
      "ContactTitle": "Owner",
      "Address": "Mataderos 2312",
      "City": "México D.F.",
      "Region": null,
      "PostalCode": "05023",
      "Country": "Mexico",
      "Phone": "(5) 555-3932",
      "Fax": null
    },
    {
      "CustomerID": "AROUT",
      "CompanyName": "Around the Horn",
      "ContactName": "Thomas Hardy",
      "ContactTitle": "Sales Representative",
      "Address": "120 Hanover Sq.",
      "City": "London",
      "Region": null,
      "PostalCode": "WA1 1DP",
      "Country": "UK",
      "Phone": "(171) 555-7788",
      "Fax": "(171) 555-6750"
    },
    {
      "CustomerID": "BOLID",
      "CompanyName": "Bólido Comidas preparadas",
      "ContactName": "Martín Sommer",
      "ContactTitle": "Owner",
      "Address": "C/ Araquil, 67",
      "City": "Madrid",
      "Region": null,
      "PostalCode": "28023",
      "Country": "Spain",
      "Phone": "(91) 555 22 82",
      "Fax": "(91) 555 91 99"
    },

    {
      "CustomerID": "ERNSH",
      "CompanyName": "Ernst Handel",
      "ContactName": "Roland Mendel",
      "ContactTitle": "Sales Manager",
      "Address": "Kirchgasse 6",
      "City": "Graz",
      "Region": null,
      "PostalCode": "8010",
      "Country": "Austria",
      "Phone": "7675-3425",
      "Fax": "7675-3426"
    }
  ]
}</pre>
</li>
<li>Secondly, we will create the following code to load the data in a combo box:<br />
<strong>NOTE:</strong> To read from multiple files use wild card pattern (e.g. c:\data\test*.json)<br />
<pre class="crayon-plain-tag">using (OdbcConnection conn = new OdbcConnection("Driver={ZappySys JSON Driver};" +
    @"DataPath = 'c:\data\test.json'; "))
{
    conn.Open();
    OdbcCommand cmd = new OdbcCommand("SELECT CustomerID FROM value", conn);

    //Increases the timeout duration from the default 30 seconds, which may be insufficient in certain scenarios.
    cmd.CommandTimeout=600; // 600-seconds

    var rdr = cmd.ExecuteReader();
    while (rdr.Read())
    {
        for (int i = 0; i &lt; rdr.FieldCount; i++)
        {

            comboBox1.Items.Add(rdr[i].ToString());
        }

    }
}</pre>
</li>
<li>Finally, execute the code to see the results:
<div id="attachment_4229" style="width: 134px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-c-load-data-from-json-file-to-combobox.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4229" class="size-full wp-image-4229" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-c-load-data-from-json-file-to-combobox.png" alt="Invoke JSON file in C#" width="124" height="107" /></a><p id="caption-attachment-4229" class="wp-caption-text">Read JSON file in C#</p></div></li>
</ol>
<h3>Calling REST API in C# to get Gmail information</h3>
<p>The next example will show how to get Gmail information in C# using REST API.</p>
<ol>
<li>First of all, go to the ODBC Administrator in Windows:
<div id="attachment_4232" style="width: 403px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/06/open-ODBC-Data-souce-administrator.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4232" class="size-full wp-image-4232" src="https://zappysys.com/blog/wp-content/uploads/2018/06/open-ODBC-Data-souce-administrator.png" alt="ODBC Windows" width="393" height="531" srcset="https://zappysys.com/blog/wp-content/uploads/2018/06/open-ODBC-Data-souce-administrator.png 393w, https://zappysys.com/blog/wp-content/uploads/2018/06/open-ODBC-Data-souce-administrator-222x300.png 222w" sizes="(max-width: 393px) 100vw, 393px" /></a><p id="caption-attachment-4232" class="wp-caption-text">Windows ODBC Data Sources</p></div></li>
<li>Secondly, in the ODBC Administrator press the add button:</li>
<li> Also, select the ZappySys JSON driver.</li>
<li>In addition, enter the DSN and the URL. In this example, we will use the following URL:<br />
<pre class="crayon-plain-tag">https://www.googleapis.com/gmail/v1/users/me/messages/1642915a12765abe</pre>
</li>
<li>Where 1642915a12765abe is the ID of the email that you can get from the email:
<div id="attachment_4248" style="width: 839px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/06/gmail-email-1.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4248" class="size-full wp-image-4248" src="https://zappysys.com/blog/wp-content/uploads/2018/06/gmail-email-1.png" alt="Get Gmail mail in c#" width="829" height="505" srcset="https://zappysys.com/blog/wp-content/uploads/2018/06/gmail-email-1.png 829w, https://zappysys.com/blog/wp-content/uploads/2018/06/gmail-email-1-300x183.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/06/gmail-email-1-768x468.png 768w" sizes="(max-width: 829px) 100vw, 829px" /></a><p id="caption-attachment-4248" class="wp-caption-text">REST API gmail</p></div></li>
<li>Additionally, you need to select the authentication type to Oauth, select the GET HTTP method and press the Click to configure link.</li>
<li>In the same way, we can configure the OAuth parameters. Select the Google OAuth provider, in scopes select the following URL:<br />
<pre class="crayon-plain-tag">https://mail.google.com</pre>
<div id="attachment_4236" style="width: 812px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/06/gmail-oauth-credentials.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4236" class="size-full wp-image-4236" src="https://zappysys.com/blog/wp-content/uploads/2018/06/gmail-oauth-credentials.png" alt="Gmail credentials REST API ODBC" width="802" height="702" srcset="https://zappysys.com/blog/wp-content/uploads/2018/06/gmail-oauth-credentials.png 802w, https://zappysys.com/blog/wp-content/uploads/2018/06/gmail-oauth-credentials-300x263.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/06/gmail-oauth-credentials-768x672.png 768w" sizes="(max-width: 802px) 100vw, 802px" /></a><p id="caption-attachment-4236" class="wp-caption-text">OAuth credential REST API Gmail</p></div></li>
<li>The code used to get data is the following:<br />
<pre class="crayon-plain-tag">try
            {
                string Conn = "dsn=ZappySys JSON Gmail;";
                string Sql = "select * from [_root_]";

                using (OdbcConnection con = new OdbcConnection(Conn))
                using (OdbcDataAdapter dadapter = new OdbcDataAdapter(Sql, con))
                {
                    DataTable table = new DataTable();
                    dadapter.Fill(table);

                    this.dataGridView1.DataSource = table;
                }
            }
            catch (Exception ex)
            {


                MessageBox.Show(ex.ToString());</pre>
</li>
<li>Note that we are invoking a DSN in the code:<br />
<pre class="crayon-plain-tag">string Conn = "dsn=ZappySys JSON Gmail;";</pre>
</li>
<li>Also, note that the query used to get data is the following:<br />
<pre class="crayon-plain-tag">string Sql = "select * from [_root_]";</pre>
</li>
<li>If everything is OK, you will be able to see the mail information in the dataGridView:
<div id="attachment_4237" style="width: 607px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/06/gmail-rest-api-c-get-information-datadridview.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4237" class="size-full wp-image-4237" src="https://zappysys.com/blog/wp-content/uploads/2018/06/gmail-rest-api-c-get-information-datadridview.png" alt="DataGrid View" width="597" height="202" srcset="https://zappysys.com/blog/wp-content/uploads/2018/06/gmail-rest-api-c-get-information-datadridview.png 597w, https://zappysys.com/blog/wp-content/uploads/2018/06/gmail-rest-api-c-get-information-datadridview-300x102.png 300w" sizes="(max-width: 597px) 100vw, 597px" /></a><p id="caption-attachment-4237" class="wp-caption-text">Gmail DataGrid View</p></div></li>
</ol>
<h2>ZappySys JSON /REST API Driver Query Examples</h2>
<p>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 <a href="https://zappysys.com/onlinehelp/odbc-powerpack/scr/json-odbc-driver-sql-query-examples.htm" target="_blank" rel="noopener">see json query examples</a>.</p>
<h2>ZappySys XML / SOAP Driver Query Examples</h2>
<p>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 <a href="https://zappysys.com/onlinehelp/odbc-powerpack/scr/xml-odbc-driver-sql-query-examples.htm" target="_blank" rel="noopener">see xml query examples</a>.</p>
<h2>Calling XML SOAP Web Service in C#</h2>
<p>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 Qlik.</p>
<div class="content_block" id="custom_post_widget-3870">To call SOAP API you need to know Request XML Body Structure. If you are not sure how to create SOAP Request body then no worries. <a href="https://zappysys.com/blog/calling-soap-web-service-in-ssis-xml-source/" target="_blank" rel="noopener">Check this article</a> to learn how to generate SOAP Request body using the Free tool <a href="https://www.soapui.org/downloads/latest-release.html" target="_blank" rel="noopener">SoapUI</a>. Basically, you have to use SoapUI to generate Request XML and after that, you can replace parameters as needed in the generated body.
<h3>What is SOAP Web Service?</h3>
If you are new to SOAP Web Service sometimes referred as XML Web Service then please read some concept about SOAP Web service standard <a href="https://msdn.microsoft.com/en-us/library/ms996507.aspx?f=255&amp;MSPPError=-2147217396" target="_blank" rel="noopener">from this link</a>

There are two important aspects in SOAP Web service.
<ol>
 	<li>Getting WSDL file or URL</li>
 	<li>Knowing exact Web Service URL</li>
</ol>
<h3>What is WSDL</h3>
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 )
<h3>Example SQL Query for SOAP API call using ZappySys XML Driver</h3>
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.
<pre class="lang:tsql decode:true">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='
&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hol="http://www.holidaywebservice.com/HolidayService_v2/"&gt;
   &lt;soapenv:Header/&gt;
   &lt;soapenv:Body&gt;
      &lt;hol:GetHolidaysAvailable&gt;
         &lt;!--type: Country - enumeration: [Canada,GreatBritain,IrelandNorthern,IrelandRepublicOf,Scotland,UnitedStates]--&gt;
         &lt;hol:countryCode&gt;UnitedStates&lt;/hol:countryCode&gt;
      &lt;/hol:GetHolidaysAvailable&gt;
   &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;'
)</pre>
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)
<h3>Video Tutorial - Introduction to SOAP Web Service and SoapUI tool</h3>
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.

&nbsp;

<iframe loading="lazy" width="560" height="315" src="https://www.youtube.com/embed/d_x5bgGjg0Y?rel=0&amp;showinfo=0" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen="allowfullscreen" data-mce-fragment="1"></iframe>
<h3>Using SoapUI to test SOAP API call / Create Request Body XML</h3>
Assuming you have downloaded and installed <a href="https://www.soapui.org/downloads/latest-release.html" target="_blank" rel="noopener">SoapUI from here</a>, 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 <strong>?wsdl </strong>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 <strong>Web service Description Language</strong> (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.
<ol>
 	<li>Open SoapUI and click SOAP button to create new SOAP Project</li>
 	<li>Enter WSDL URL or File Path of WSDLFor example WSDL for our sample service can be accessed via this URL
<pre class="lang:default highlight:0 decode:true">http://www.dneonline.com/calculator.asmx?wsdl</pre>
<a href="https://zappysys.com/blog/wp-content/uploads/2018/06/calling-soap-api-import-wsdl-new-soapui-project.png"><img loading="lazy" decoding="async" class="size-full wp-image-3871" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-call-soap-api-14.png" alt="Create new SOAP API Project in SoapUI tool for SOAP API Testing" width="486" height="349" /></a>
<div style="margin-bottom: 1em;">Create new SOAP API Project in SoapUI tool for SOAP API Testing</div></li>
 	<li>Once WSDL is loaded you will see possible operations you can call for your SOAP Web Service.</li>
 	<li>If your web service requires credentials then you have to configure it. There are two common credential types for public services (<strong>SOAP WSS</strong> or <strong>BASIC</strong> )
<ol>
 	<li>
<div style="margin-bottom: 1em;">To use <strong>SOAP WSS Credentials</strong> select request node and enter UserId, Password, and <strong>WSS-PasswordType</strong> (PasswordText or PasswordHash)</div>
<a href="https://zappysys.com/blog/wp-content/uploads/2018/06/calling-soap-api-pass-soap-wss-credentials-userid-password.png"><img loading="lazy" decoding="async" class="size-full wp-image-3872 alignnone" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-call-soap-api-2.png" alt="Configure SOAP WSS Credentials for SoapUI (SOAP API Testing Tool)" width="294" height="544" /></a>
<div style="display: block;">Configure SOAP WSS Credentials for SoapUI (SOAP API Testing Tool)</div></li>
 	<li>To use <strong>BASIC Auth</strong> 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.<a href="https://zappysys.com/blog/wp-content/uploads/2018/06/calling-soap-api-pass-basic-authentication-userid-password.png"><img loading="lazy" decoding="async" class="size-full wp-image-3873" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-call-soap-api-2.png" alt="Configure Basic Authorization for SoapUI (SOAP API Testing Tool)" width="616" height="653" /></a>
<div style="margin-bottom: 1em;">Configure Basic Authorization for SoapUI (SOAP API Testing Tool)</div></li>
</ol>
</li>
 	<li>Now you can test your request first Double-click on the request node to open request editor.</li>
 	<li>Change necessary parameters, remove optional or unwanted parameters. If you want to regenerate request you can click on <strong>Recreate default request toolbar icon</strong>.
<a href="https://zappysys.com/blog/wp-content/uploads/2016/06/create-soap-request-with-optional-parameters-soapui.png"><img loading="lazy" decoding="async" class="size-full wp-image-2812" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-call-soap-api-4.png" alt="Create SOAP Request XML (With Optional Parameters)" width="807" height="315" /></a>
<div style="margin-bottom: 1em;">Create SOAP Request XML (With Optional Parameters)</div></li>
 	<li>Once your SOAP Request XML is ready, <strong>Click the Play button</strong> in the toolbar to execute SOAP API Request and Response will appear in Right side panel.
<a href="https://zappysys.com/blog/wp-content/uploads/2018/06/soapui-test-soap-api-request-response-edit-xml-body.png"><img loading="lazy" decoding="async" class="size-full wp-image-3874" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-call-soap-api-5.png" alt="Test SOAP API using SoapUI Tool (Change Default XML Body / Parameters, Execute and See Response)" width="1216" height="511" /></a>
Test SOAP API using SoapUI Tool (Change Default XML Body / Parameters, Execute and See Response)</li>
</ol>
<h3>Create DSN using ZappySys XML Driver to call SOAP API</h3>
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.
<ol>
 	<li>First open <strong>ODBC Data Sources</strong> (search ODBC in your start menu or go under ZappySys &gt; ODBC PowerPack &gt; <strong>ODBC 64 bit</strong>)</li>
 	<li>Goto <strong>System DSN</strong> Tab (or User DSN which is not used by Service account)</li>
 	<li>Click <strong>Add</strong> and Select ZappySys XML Driver
<a href="https://zappysys.com/blog/wp-content/uploads/2018/06/zappysys-odbc-xml-soap-api-driver.png"><img loading="lazy" decoding="async" class="size-full wp-image-3875" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-call-soap-api-6.png" alt="ZappySys ODBC Driver for XML / SOAP API" width="593" height="459" /></a>
ZappySys ODBC Driver for XML / SOAP API</li>
 	<li>Configure API URL, Request Method and Request Body as below
<a href="https://zappysys.com/blog/wp-content/uploads/2018/06/calling-soap-web-service-zappysys-xml-driver.png"><img loading="lazy" decoding="async" class="size-full wp-image-3876" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-call-soap-api-7.png" alt="ZappySys XML Driver - Calling SOAP API - Configure URL, Method, Body" width="916" height="874" /></a>
ZappySys XML Driver - Calling SOAP API - Configure URL, Method, Body</li>
 	<li><strong>(This step is Optional)</strong> If your SOAP API requires credentials then Select Connection Type to HTTP and configure as below.
<a href="https://zappysys.com/blog/wp-content/uploads/2018/06/soap-api-call-credential-basic-soap-wss-zappysys-xml-driver.png"><img loading="lazy" decoding="async" class="size-full wp-image-3877" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-call-soap-api-8.png" alt="ZappySys XML Driver - Configure SOAP WSS Credentials or Basic Authorization (Userid, Password)" width="564" height="483" /></a>
<div style="display: block;">ZappySys XML Driver - Configure SOAP WSS Credentials or Basic Authorization (Userid, Password)</div></li>
 	<li>Configure-Request Headers as below (You can get it from Request &gt; Raw tab from SoapUI after you test the request by clicking the Play button)
<a href="https://zappysys.com/blog/wp-content/uploads/2018/06/set-soap-api-request-headers-zappysys-xml-driver.png"><img loading="lazy" decoding="async" class="size-full wp-image-3881" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-call-soap-api-9.png" alt="Configure SOAP API Request Headers - ZappySys XML Driver" width="1009" height="747" /></a>
Configure SOAP API Request Headers - ZappySys XML Driver</li>
 	<li>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.
<a href="https://zappysys.com/blog/wp-content/uploads/2018/06/soap-api-query-select-filter-zappysys-xml-driver.png"><img loading="lazy" decoding="async" class="size-full wp-image-3882" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-call-soap-api-10.png" alt="Select Filter - Extract data from nested XML / SOAP API Response (Denormalize Hierarchy)" width="809" height="594" /></a>
Select Filter - Extract data from nested XML / SOAP API Response (Denormalize Hierarchy)</li>
 	<li>If prompted select yes to treat selected node as Array (This is helpful when you expect one or more record for selected node)
<a href="https://zappysys.com/blog/wp-content/uploads/2018/06/xml-api-array-handling-zappysys-xml-driver.png"><img loading="lazy" decoding="async" class="size-full wp-image-3883" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-call-soap-api-11.png" alt="Treat selected node as XML Array Option for SOAP API Response XML" width="655" height="572" /></a>
Treat selected node as XML Array Option for SOAP API Response XML</li>
</ol>
<h3>Preview SOAP API Response / Generate SQL Code for SOAP API Call</h3>
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.
<h3>Preview Data</h3>
<a href="https://zappysys.com/blog/wp-content/uploads/2018/06/calling-soap-web-service-zappysys-xml-api-driver.png"><img loading="lazy" decoding="async" class="size-full wp-image-3884" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-call-soap-api-12.png" alt="Preview SOAP API Response in ZappySys XML Driver" width="808" height="780" /></a>
Preview SOAP API Response in ZappySys XML Driver
<h3>Generate Code Option</h3>
<a href="https://zappysys.com/blog/wp-content/uploads/2018/06/zappysys-driver-code-generator.png"><img loading="lazy" decoding="async" class="size-full wp-image-3885" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-call-soap-api-13.png" alt="Generate Example Code for ZappySys Driver" width="572" height="618" /></a>
<div style="display: block;">Generate Example Code for ZappySys Driver</div></div>
<h2>POST data to REST API URL from file in C#</h2>
<p>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).</p><pre class="crayon-plain-tag">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'
)</pre><p>
&nbsp;</p>
<h2>REST API Pagination in C#</h2>
<div class="content_block" id="custom_post_widget-3892"><div style="margin-bottom: 1em;">Even we set up ODBC Data Source to get the data, it may not be enough. Usually, if you are getting a huge data set from API provider, it won't give it to you in one HTTP response. Instead, it gives back only a subset of data and provides a mechanism for data pagination. The good news is that <em>ZappySys ODBC Driver</em> includes many options to cover virtually any pagination method.</div>
<div><span style="font-size: 16px;">Below you will find a few examples of API pagination. If you need something more sophisticated check the below link (the article was written for SSIS PowerPack but UI options and concepts apply to ODBC Driver too):</span></div>
<div style="margin-bottom: 1em;"><a href="https://zappysys.com/blog/ssis-rest-api-looping-until-no-more-pages-found/" target="_blank" rel="noopener">https://zappysys.com/blog/ssis-rest-api-looping-until-no-more-pages-found/</a></div>
<h3>Paginate by Response Attribute</h3>
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.
<pre class="lang:tsql decode:true codeblock">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']
)</pre>
<h3>Paginate by URL Parameter (Loop until certain StatusCode)</h3>
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).
<pre class="lang:tsql decode:true codeblock">SELECT * FROM $
WITH (
SRC=@'https://zappysys.com/downloads/files/test/page-xml.aspx?page=1&amp;mode=DetectBasedOnResponseStatusCode'
,PagingMode='ByUrlParameter'
,PagingByUrlAttributeName='page'
,PagingByUrlEndStrategy='DetectBasedOnResponseStatusCode'
,PagingByUrlCheckResponseStatusCode=401
,IncrementBy=1
)</pre>
<h3>Paginate by URL Path (Loop until no record)</h3>
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).
<pre class="lang:tsql decode:true codeblock">SELECT * FROM $
WITH (
SRC=@'https://zappysys.com/downloads/files/test/cust-&lt;%page%&gt;.xml'
,PagingMode='ByUrlPath'
,PagingByUrlAttributeName='&lt;%page%&gt;'
,PagingByUrlEndStrategy='DetectBasedOnRecordCount'
,IncrementBy=1
)</pre>
<h3>Paginate by Header Link (RFC 5988)</h3>
API like GitHub / Wordpress use Next link in Headers (<a href="https://tools.ietf.org/html/rfc5988" target="_blank" rel="noopener">RFC 5988</a>)
<pre class="lang:default decode:true ">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
)</pre>
&nbsp;</div>
<h2>Error Handling in REST API / SOAP</h2>
<div class="content_block" id="custom_post_widget-3894">Sometimes errors occur... they just do and there is nothing you can do! Or can you? Actually, in ODBC PowerPack you can handle them in two ways.
<h3>METHOD 1 - Using Error Handling Options</h3>
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-3949" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-api-error-handling-1.png" alt="" width="668" height="702" />
<h4>When to use?</h4>
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.
<h4>Scenario 1</h4>
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. <span style="text-decoration: underline;"><em>http://www.some-server.com/data/2018-06-20.json</em></span>. 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 <a href="https://en.wikipedia.org/wiki/HTTP_404" target="_blank" rel="noopener">HTTP 404 status code</a> (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 <strong><span class="lang:default highlight:0 decode:true crayon-inline">Continue on any error</span></strong> or <strong><span class="lang:default highlight:0 decode:true crayon-inline">Continue when Url is invalid or missing (404 Errors)</span></strong> to avoid an error being raised and let other data sources to be updated.
<h4>Scenario 2</h4>
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 <strong><span class="lang:default highlight:0 decode:true crayon-inline">Continue on any error</span></strong> or alike together with  <strong><span class="lang:default highlight:0 decode:true crayon-inline">Get response data on error</span></strong> to continue on an error and get the data:

<img loading="lazy" decoding="async" class="alignnone wp-image-3961 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-powerpack-get-response-data-on-error.png" alt="" width="547" height="235" srcset="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-powerpack-get-response-data-on-error.png 547w, https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-powerpack-get-response-data-on-error-300x129.png 300w" sizes="(max-width: 547px) 100vw, 547px" />
<h3>METHOD 2 - Using Connection [Retry Settings]</h3>
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 <em>Connection</em>:

<img loading="lazy" decoding="async" class="alignnone wp-image-3963 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-api-error-handling-3.png" alt="" width="671" height="572" /></div>
<h2>REST API / SOAP Connection Types in C# (OAuth / HTTP)</h2>
<div class="content_block" id="custom_post_widget-3896"><div style="margin-bottom: 1em;">If you need to authenticate or authorize your user to access a web resource, you will need to use one of the <em>Connections:</em></div>
<ul>
 	<li>HTTP</li>
 	<li>OAuth</li>
</ul>
<img loading="lazy" decoding="async" class="wp-image-4078 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-powerpack-authentication-authorization-e1529337108252.png" alt="ZappySys XML Driver - HTTP and OAuth Connection Types" width="577" height="302" srcset="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-powerpack-authentication-authorization-e1529337108252.png 577w, https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-powerpack-authentication-authorization-e1529337108252-300x157.png 300w" sizes="(max-width: 577px) 100vw, 577px" />
<h3>HTTP Connection</h3>
<div style="margin-bottom: 1em;">Use <em>HTTP Connection</em> for simple Windows, Basic, NTLM or Kerberos authentication. Just fill in a username and a password and you are good to go!</div>
<div style="margin-bottom: 1em;">You can also use <em>HTTP Connection</em> for more sophisticated authentication like:</div>
<ul>
 	<li><strong>SOAP WSS</strong> (when accessing a SOAP WebService)</li>
 	<li><strong>Static Token / API Key</strong> (when need to pass an API key in HTTP header)</li>
 	<li><strong>Dynamic Token</strong> (same as Static Token method except that each time you need to log in and retrieve a fresh API key)</li>
 	<li><strong>JWT Token</strong> (As per RFC 7519)</li>
</ul>
<img loading="lazy" decoding="async" class="alignnone wp-image-4091 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-api-connection-type-1.png" alt="" width="622" height="570" />
<h3>OAuth</h3>
If you are trying to access REST API resource, it is a huge chance, you will need to use <em>OAuth Connection</em>. <a href="https://zappysys.com/blog/rest-api-authentication-with-oauth-2-0-using-ssis/" target="_blank" rel="noopener">Read this article</a> to understand how OAuth authentication and authorization works and how to use it (article originally was written for <a href="https://zappysys.com/products/ssis-powerpack/" target="_blank" rel="noopener">SSIS PowerPack</a>, but the concepts and UI stay the same): <br/>
<a href="https://zappysys.com/blog/rest-api-authentication-with-oauth-2-0-using-ssis/" target="_blank" rel="noopener">https://zappysys.com/blog/rest-api-authentication-with-oauth-2-0-using-ssis/</a>
<img loading="lazy" decoding="async" class="alignnone size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-api-connection-type-2.png" width="721" height="708" /></div>
<h2>Performance consideration for Web API Calls</h2>
<div class="content_block" id="custom_post_widget-4455">While calling APIs you may face some performance issues. There are a few tips you can consider to speed up things.
<h4><span style="font-size: 14pt;"><strong>Use Server-side filtering if possible in URL or Body Parameters</strong></span></h4>
Many API supports filtering your data by URL parameters or via Body. Whenever possible try to use such features.  Here is an example of <a href="http://www.odata.org/getting-started/basic-tutorial/" target="_blank" rel="noopener">odata API</a>, In the below query the first query is faster than the second query because in the first query we filter at the server.
<pre class="lang:tsql decode:true">SELECT * FROM value
WITH(
	 Src='https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json&amp;$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'
)</pre>
<h4><span style="font-size: 14pt;"><strong>Avoid Special features in SQL Query (e.g. WHERE, Group By, Order By)</strong></span></h4>
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 )
<ul>
 	<li>WHERE Clause</li>
 	<li>GROUP BY Clause</li>
 	<li>HAVING Clause</li>
 	<li>ORDER BY</li>
 	<li>FUNCTIONS (e.g. Math, String, DateTime, Regex... )</li>
</ul>
LIMIT clause does not trigger client-side processing.
<h4><span style="font-size: 14pt;"><strong>Consider using pre-generated Metadata / Cache File</strong></span></h4>
Use META option in WITH Clause to use static metadata (Pre-Generated)There are two more options to speedup query processing time. Check <a href="https://zappysys.com/blog/caching-metadata-odbc-drivers-performance/" target="_blank" rel="noopener">this article</a> for details.
<ol>
 	<li>
<pre class="lang:default decode:true">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",&amp;nbsp;"Type": "String", Length: 100},&amp;nbsp;{"Name": "col2",&amp;nbsp;"Type": "Int32"} ...... ]' )</pre>
</li>
 	<li>Enable Data Caching Options (Found on <strong>Property Grid</strong> &gt; <strong>Advanced</strong> Mode Only )</li>
</ol>
<h4><span style="font-size: 14pt;"><strong>Consider using Metadata / Data Caching Option</strong></span></h4>
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 <a href="https://zappysys.com/blog/caching-metadata-odbc-drivers-performance/" target="_blank" rel="noopener">this article</a> 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.
<pre class="">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
)
</pre>
&nbsp;

&nbsp;
<h4><strong><span style="font-size: 14pt;">Use --FAST Option to enable Stream Mode</span></strong></h4>
ZappySys JSON / XML drivers support <strong>--FAST</strong> suffix for Filter. By using this suffix after Filter driver enables Stream Mode, <a href="https://zappysys.com/blog/caching-metadata-odbc-drivers-performance/#Reading_Large_Files_Streaming_Mode_for_XML_JSON" target="_blank" rel="noopener">Read this article</a> to understand how this works.
<pre class="lang:default decode:true">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)
)</pre>
&nbsp;</div>
<h2>Other considerations for Web API calls in C#</h2>
<div class="content_block" id="custom_post_widget-3901">There are few settings you can coder while calling Web API
<h3><strong>API Limit / Throttling</strong></h3>
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.
<h3><strong>2D Array Transformation</strong></h3>
If you are using JSON or XML API Driver then possible you may have to transform your data using 2D array transformation feature. <a href="https://zappysys.com/blog/parse-multi-dimensional-json-array-ssis/" target="_blank" rel="noopener">Check this link</a> for more information.

&nbsp;</div>
<h2>Conclusion</h2>
<p>In this article, we saw how to use C# to call REST API. We show how to do REST API calls in C# using the ZappySys ODBC driver. Also, we show how to get data from local files and get Gmail information with REST API. If you liked this article and you want to try, you can download the <a href="https://zappysys.com/products/odbc-powerpack/download/" target="_blank" rel="noopener">ZappySys ODBC installer here</a>.</p>
<h2>References</h2>
<ul>
<li><a href="https://zappysys.com/products/odbc-powerpack/download/" target="_blank" rel="noopener">ZappySys ODBC installer.</a></li>
<li><a href="https://support.microsoft.com/en-za/help/310988/how-to-use-the-odbc-net-managed-provider-in-visual-c-net-and-connectio target=" rel="noopener">How To Use the ODBC .NET Managed Provider in Visual C# .NET and Connection Strings</a></li>
</ul>
<p>&nbsp;</p>
<p>The post <a href="https://zappysys.com/blog/calling-rest-api-in-c/">Calling REST API in C# (Read JSON Data)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
