<?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>T-SQL (SQL Server) Archives | ZappySys Blog</title>
	<atom:link href="https://zappysys.com/blog/category/odbc-powerpack/odbc-programming/programming-tsql/feed/" rel="self" type="application/rss+xml" />
	<link>https://zappysys.com/blog/category/odbc-powerpack/odbc-programming/programming-tsql/</link>
	<description>SSIS / ODBC Drivers / API Connectors for JSON, XML, Azure, Amazon AWS, Salesforce, MongoDB and more</description>
	<lastBuildDate>Wed, 11 Mar 2026 07:08:29 +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>T-SQL (SQL Server) Archives | ZappySys Blog</title>
	<link>https://zappysys.com/blog/category/odbc-powerpack/odbc-programming/programming-tsql/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to Make PayPal API Call in ODBC / SQL Server (T-SQL)</title>
		<link>https://zappysys.com/blog/make-paypal-api-call-odbc-sql-server/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Sat, 14 Sep 2019 08:49:27 +0000</pubDate>
				<category><![CDATA[JSON File / REST API Driver]]></category>
		<category><![CDATA[T-SQL (SQL Server)]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[oauth2]]></category>
		<category><![CDATA[odbc]]></category>
		<category><![CDATA[paypal]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=8010</guid>

					<description><![CDATA[<p>Introduction In our previous article we saw how to call PayPal API in SSIS. Now in this article, we will see How to Make PayPal API Call in ODBC from the SQL Server. This blog mainly focuses on ODBC approach but steps mentioned to call PayPal APIs can be useful for any developer regardless of which [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/make-paypal-api-call-odbc-sql-server/">How to Make PayPal API Call in ODBC / SQL Server (T-SQL)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2><span id="Introduction">Introduction</span></h2>
<p><a href="https://zappysys.com/blog/wp-content/uploads/2019/08/paypal-logo-preview.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="alignleft wp-image-7825 size-thumbnail" title="PayPal" src="https://zappysys.com/blog/wp-content/uploads/2019/08/paypal-logo-preview-150x150.png" alt="PayPal" width="150" height="150" srcset="https://zappysys.com/blog/wp-content/uploads/2019/08/paypal-logo-preview-150x150.png 150w, https://zappysys.com/blog/wp-content/uploads/2019/08/paypal-logo-preview-300x300.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/08/paypal-logo-preview.png 512w" sizes="(max-width: 150px) 100vw, 150px" /></a>In our previous article we saw <a href="https://zappysys.com/blog/read-paypal-api-data-ssis/" target="_blank" rel="noopener">how to call PayPal API in SSIS</a>. Now in this article, we will see How to Make PayPal API Call in ODBC from the SQL Server. This blog mainly focuses on ODBC approach but steps mentioned to call PayPal APIs can be useful for any developer regardless of which programming language or tool set you use. We will also see How to send basic Authorization header along with body in OAuth2.</p>
<p>We will go through the steps to Create PayPal Order from MS SQL Server.</p>
<p>In nutshell, this post will focus on how to make PayPal API Call using ODBC Driver.</p>
<p>&nbsp;</p>
<h2><span id="Prerequisites">Prerequisites</span></h2>
<p>Before we perform the steps listed in this article, you will need to make sure the following prerequisites are met:</p>
<ol>
<li>A first requirement, make sure that Microsoft Access installed</li>
<li>Make sure to have <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> installed.</li>
<li>Credentials of PayPal API. Click <a href="https://developer.paypal.com/developer/applications/" target="_blank" rel="noopener">here</a> to create API.</li>
</ol>
<h2><span id="What_is_Walmart"><span id="What_is_WordPress">What is PayPal?</span></span></h2>
<p><a href="https://www.paypal.com" target="_blank" rel="noopener">PayPal</a> is an American company operating a worldwide online payments system that supports online money transfers and serves as an electronic alternative to traditional paper methods like checks and money orders. The company operates as a payment processor for online vendors, auction sites, and many other commercial users, for which it charges a fee in exchange for benefits such as one-click transactions and password memory. PayPal&#8217;s payment system, also called PayPal, is considered a type of payment rail.</p>
<h2 class="dx-content-title">Get Started with PayPal API</h2>
<p>If you have need to automate PayPal operations (e.g. read / write / update / delete ) then you can use PayPal REST API. Before you can integrate a PayPal product or solution, you must set up your development environment to get OAuth 2.0 client ID and secret credentials for the sandbox and live environments. You exchange these credentials for an access token that authorizes your REST API calls. To test your web and mobile apps, you create sandbox accounts.</p>
<h3 id="get-credentials" class="dx-anchor">Get PayPal credentials</h3>
<p>To generate OAuth 2.0 credentials for the sandbox and live environments:</p>
<ol>
<li><a href="https://www.paypal.com/signin?returnUri=https%3A%2F%2Fdeveloper.paypal.com%2Fdeveloper%2Fapplications" target="_blank" rel="noopener"><strong>Log into Dashboard</strong></a> and type your PayPal personal or business account email and password.</li>
<li>In the <strong>REST API apps</strong> section, click <strong>Create App</strong>. The purpose of this app is to generate your credentials.</li>
<li>Type a name for your app and click <strong>Create App</strong>. The page shows your sandbox app information, which includes your credentials.<br />
<blockquote class="dx-blockquote-note"><p><strong>Note:</strong> To show your live app information, toggle to <strong>Live</strong>.</p></blockquote>
</li>
<li>Copy and save the client ID and secret for your sandbox app.
<div id="attachment_7837" style="width: 730px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/08/paypal-client-ID-and-secret.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7837" class="wp-image-7837 size-medium_large" src="https://zappysys.com/blog/wp-content/uploads/2019/08/paypal-client-ID-and-secret-768x443.png" alt="PayPal Client ID and Secret" width="720" height="415" srcset="https://zappysys.com/blog/wp-content/uploads/2019/08/paypal-client-ID-and-secret-768x443.png 768w, https://zappysys.com/blog/wp-content/uploads/2019/08/paypal-client-ID-and-secret-300x173.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/08/paypal-client-ID-and-secret.png 940w" sizes="(max-width: 720px) 100vw, 720px" /></a><p id="caption-attachment-7837" class="wp-caption-text">PayPal Client ID and Secret</p></div></li>
<li>Review your app details and save your app.</li>
</ol>
<h2><span id="Read_PayPal_API_Data_using_SSIS_JSON_Source"><span id="Read_Walmart_API_Data_using_SSIS_JSON_Source"><span id="Read_data_fromWordPressusing_SSIS_JSON_Source">Call PayPal </span></span></span>Create Order API in SQL Server (T-SQL) using Data Gateway</h2>
<p>Let’s start with an example. We use JSON Driver to make the call to PayPal API, we will Create the PayPal Order from SQL Server.</p>
<p>In REST API calls, include the URL to the API service for the environment:</p>
<ul class="compact">
<li>Sandbox: <code>https://api.sandbox.paypal.com</code></li>
<li>Live: <code>https://api.paypal.com</code></li>
</ul>
<ol>
<li>To do this, first of all, we will open the ZappySys Data Gateway Configuration:
<div id="attachment_5283" style="width: 410px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5283" class="wp-image-5283 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png" alt="Open ZappySys Data Gateway" width="400" height="315" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png 400w, https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway-300x236.png 300w" sizes="(max-width: 400px) 100vw, 400px" /></a><p id="caption-attachment-5283" class="wp-caption-text">Open ZappySys Data Gateway</p></div></li>
<li>Add the Native &#8211; ZappySys JSON Driver Data source.
<div id="attachment_5284" style="width: 568px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5284" class="wp-image-5284 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source.png" alt="Add Gateway Data Source (Native JSON Driver)" width="558" height="533" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source.png 558w, https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source-300x287.png 300w" sizes="(max-width: 558px) 100vw, 558px" /></a><p id="caption-attachment-5284" class="wp-caption-text">Add Gateway Data Source (Native JSON Driver)</p></div></li>
<li>Now it&#8217;s time to connect with PayPal. Let&#8217;s use JSON Driver Data source with the following URL:<br />
<pre class="crayon-plain-tag">https://api.sandbox.paypal.com/v2/checkout/orders</pre>
Body:<br />
<pre class="crayon-plain-tag">{
  "intent": "CAPTURE",
  "purchase_units": [
    {
      "amount": {
        "currency_code": "USD",
        "value": "100.00"
      }
    }
  ]
}</pre>
<div id="attachment_8013" style="width: 875px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/09/odbc-json-driver-paypal-create-order.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-8013" class="wp-image-8013 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/09/odbc-json-driver-paypal-create-order.png" alt="PayPal : Create Order" width="865" height="703" srcset="https://zappysys.com/blog/wp-content/uploads/2019/09/odbc-json-driver-paypal-create-order.png 865w, https://zappysys.com/blog/wp-content/uploads/2019/09/odbc-json-driver-paypal-create-order-300x244.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/09/odbc-json-driver-paypal-create-order-768x624.png 768w" sizes="(max-width: 865px) 100vw, 865px" /></a><p id="caption-attachment-8013" class="wp-caption-text">PayPal : Create Order</p></div></li>
<li>Create Basic OAuth Client Credentials Grant (Configure ZS-OAuth Connection).<br />
In the SSIS ZS OAuth Connection Manager, Select Provider as Custom, select version as OAuth2 and select Grant Type as  Client Credentials Grant. Enter the credentials and access token url and click OK.<br />
<pre class="crayon-plain-tag">https://api.sandbox.paypal.com/v1/oauth2/token</pre>
<div id="attachment_8014" style="width: 807px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/09/odbc-paypal-oauth-basic-client-credential-grant.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-8014" class="wp-image-8014 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/09/odbc-paypal-oauth-basic-client-credential-grant.png" alt="ZS OAuth Connection – Client Credentials Grant" width="797" height="751" srcset="https://zappysys.com/blog/wp-content/uploads/2019/09/odbc-paypal-oauth-basic-client-credential-grant.png 797w, https://zappysys.com/blog/wp-content/uploads/2019/09/odbc-paypal-oauth-basic-client-credential-grant-300x283.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/09/odbc-paypal-oauth-basic-client-credential-grant-768x724.png 768w" sizes="(max-width: 797px) 100vw, 797px" /></a><p id="caption-attachment-8014" class="wp-caption-text">ZS OAuth Connection – Client Credentials Grant</p></div></li>
<li>Furthermore, Now click on Test Connection button to test PayPal Connection.
<div id="attachment_8015" style="width: 812px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/09/odbc-paypal-test-connection.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-8015" class="wp-image-8015 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/09/odbc-paypal-test-connection.png" alt="PayPal : Test Connection" width="802" height="702" srcset="https://zappysys.com/blog/wp-content/uploads/2019/09/odbc-paypal-test-connection.png 802w, https://zappysys.com/blog/wp-content/uploads/2019/09/odbc-paypal-test-connection-300x263.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/09/odbc-paypal-test-connection-768x672.png 768w" sizes="(max-width: 802px) 100vw, 802px" /></a><p id="caption-attachment-8015" class="wp-caption-text">PayPal : Test Connection</p></div></li>
<li>Write your Query and <strong>Preview Data</strong>.</li>
<li><strong>(Optional Step)</strong> If your Query use POST method (e.g. Create Invoice) to submit data then you have <a href="https://zappysys.com/blog/caching-metadata-odbc-drivers-performance/#Metadata_Options_in_SQL_Query" target="_blank" rel="noopener">Save Metadata (Read More)</a>. We will use this meta file in later step when we call POST request.
<div id="attachment_4716" style="width: 551px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/08/post-data-json-rest-api-using-sql-query-odbc-driver.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4716" class="size-full wp-image-4716" src="https://zappysys.com/blog/wp-content/uploads/2018/08/post-data-json-rest-api-using-sql-query-odbc-driver.png" alt="Generate Metadata File for REST API POST Operation using ZappySys API Driver (JSON / XML)" width="541" height="593" srcset="https://zappysys.com/blog/wp-content/uploads/2018/08/post-data-json-rest-api-using-sql-query-odbc-driver.png 541w, https://zappysys.com/blog/wp-content/uploads/2018/08/post-data-json-rest-api-using-sql-query-odbc-driver-274x300.png 274w" sizes="(max-width: 541px) 100vw, 541px" /></a><p id="caption-attachment-4716" class="wp-caption-text">Generate Metadata File for REST API POST Operation using ZappySys API Driver (JSON / XML)</p></div></li>
<li>Now using Code Generator we will generate the query.
<div id="attachment_6416" style="width: 766px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-generate-quickbooks-query.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-6416" class="wp-image-6416 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-generate-quickbooks-query.png" alt="odbc-json-driver-generate-quickbooks-query" width="756" height="432" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-generate-quickbooks-query.png 756w, https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-generate-quickbooks-query-300x171.png 300w" sizes="(max-width: 756px) 100vw, 756px" /></a><p id="caption-attachment-6416" class="wp-caption-text">Generate Query</p></div></li>
</ol>
<h3>Setup Linked Server <span id="Create_ODBC_DSN_8211_JSON_Driver">in MS SQL Server for PayPal</span></h3>
<p>Once you configured the data source in Gateway, we can now setup Linked Server in SQL Server to query API Calls.</p>
<ol>
<li>Assuming you have installed SQL Server and SSMS. If not then get both for FREE from here: <a href="https://www.microsoft.com/en-us/sql-server/sql-server-editions-express" target="_blank" rel="noopener">Get SQL Server Express</a> and  <a href="https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms" target="_blank" rel="noopener">Get SSMS</a></li>
<li>Open SSMS and connect to SQL Server.</li>
<li>Go to Root &gt; Server Objects &gt; Linked Servers node. Right click and click <strong>New Linked Server&#8230;</strong>
<div class="wp-caption alignnone">
<p><a href="https://i1.wp.com/zappysys.com/blog/wp-content/uploads/2018/03/create-new-linked-server-ssms.png?ssl=1" target="_blank" rel="noopener"><img loading="lazy" decoding="async" src="https://i1.wp.com/zappysys.com/blog/wp-content/uploads/2018/03/create-new-linked-server-ssms.png?w=720&amp;ssl=1" alt="Add Linked Server in SQL Server" width="420" height="262" /></a></p>
<p class="wp-caption-text">Add Linked Server in SQL Server</p>
</div>
</li>
<li> Now enter the linked server name, select Provider as SQL Native Client</li>
<li>Enter data source as <strong><pre class="crayon-plain-tag">GatewayServerName, PORT_NUMBER</pre></strong> where server name is where ZappySys Gateway is running (Can be same as SQL Server machine or remote machine). Default PORT_NUMBER is 5000 but confirm on Data gateway &gt; General tab in case its different.</li>
<li>Enter Catalog Name. This must match name from Data gateway Data sources grid &gt; Name column
<div class="wp-caption alignnone">
<p><a href="https://i1.wp.com/zappysys.com/blog/wp-content/uploads/2018/11/ssms-sql-server-configure-linked-server-1.png?ssl=1" target="_blank" rel="noopener"><img loading="lazy" decoding="async" src="https://i1.wp.com/zappysys.com/blog/wp-content/uploads/2018/11/ssms-sql-server-configure-linked-server-1.png?w=720&amp;ssl=1" alt="Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection" width="643" height="496" /></a></p>
<p class="wp-caption-text">Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection</p>
</div>
</li>
<li>Click on Security Tab and select last option &#8220;<strong>Be made using this security context</strong>&#8220;. Enter your gateway user account here.</li>
<li>Click OK to save Linked Server</li>
</ol>
<h3>Create Order in PayPal from SQL Server (Call POST API Method)</h3>
<ol>
<li>To Create Order in PayPal we need to execute the query like this. Please refer to this link for more information: <a href="https://developer.paypal.com/docs/api/orders/v2/#orders_create" target="_blank" rel="noopener">Create Order example.</a><br />
<div class="su-note"  style="border-color:#e5de9d;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><div class="su-note-inner su-u-clearfix su-u-trim" style="background-color:#fff8b7;border-color:#ffffff;color:#333333;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;">Important Note*: Below query uses META property <a href="https://zappysys.com/blog/caching-metadata-odbc-drivers-performance/#Metadata_Options_in_SQL_Query" target="_blank" rel="noopener">(fully explained here)</a>. This is needed if you creating anew record using POST, PUT. If you don&#8217;t pass META='{xxxx}&#8217; in query driver calls REST API two times (first time to parse metadata and second time to get actual data). So that you find some odd thing in PayPal if you execute the query without Meta then you will find two same Orders created in your PayPal as the driver makes two calls as mentioned above.</div></div>
<pre class="crayon-plain-tag">-- In below query rather than WITH(META=''[{"Name": "Success","Type": "Int32"}]'' ....
-- You can also use WITH(META=''c:\my-meta-file.txt'' .... We created this file in previous section

SELECT * FROM OPENQUERY([MY_LINKED_SERVER_NAME]
, 'SELECT * FROM $
WITH(META=''[{"Name": "Success","Type": "Int32"}]''
	 ,Src=''https://api.sandbox.paypal.com/v2/checkout/orders''
	,RequestData=''{
  "intent": "CAPTURE",
  "purchase_units": [
    {
      "amount": {
        "currency_code": "USD",
        "value": "100.00"
      }
    }
  ]
}''
	,RequestContentTypeCode=''ApplicationJson''
	,RequestMethod=''POST''
)')</pre>
</li>
<li>Here is the preview after you run REST API query in SQL Server. It will return created Order Id, Links and status. Notice that you can override default configuration by supplying <a href="https://zappysys.com/onlinehelp/odbc-powerpack/scr/json-odbc-driver-connectionstring.htm" target="_blank" rel="noopener">many parameters</a> in WITH clause.
<div id="attachment_8018" style="width: 586px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/09/sql-server-create-order-result.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-8018" class="wp-image-8018 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/09/sql-server-create-order-result.png" alt="Create Order In PayPal Using SQL Query" width="576" height="750" srcset="https://zappysys.com/blog/wp-content/uploads/2019/09/sql-server-create-order-result.png 576w, https://zappysys.com/blog/wp-content/uploads/2019/09/sql-server-create-order-result-230x300.png 230w" sizes="(max-width: 576px) 100vw, 576px" /></a><p id="caption-attachment-8018" class="wp-caption-text">Create Order In PayPal Using SQL Query</p></div></li>
<li>You can also find this created Order by opening that URL in the browser.
<div id="attachment_8019" style="width: 730px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/09/paypal-created-order.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-8019" class="wp-image-8019 size-medium_large" src="https://zappysys.com/blog/wp-content/uploads/2019/09/paypal-created-order-768x751.png" alt="Created Order In PayPal" width="720" height="704" srcset="https://zappysys.com/blog/wp-content/uploads/2019/09/paypal-created-order-768x751.png 768w, https://zappysys.com/blog/wp-content/uploads/2019/09/paypal-created-order-300x293.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/09/paypal-created-order.png 815w" sizes="(max-width: 720px) 100vw, 720px" /></a><p id="caption-attachment-8019" class="wp-caption-text">Created Order In PayPal</p></div></li>
</ol>
<h2><span id="Read_PayPal_API_Data_using_SSIS_JSON_Source"><span id="Read_Walmart_API_Data_using_SSIS_JSON_Source"><span id="Read_data_fromWordPressusing_SSIS_JSON_Source">PayPal API integration in ODBC apps (e.g. Power BI, Excel, Informatica, Access, C#&#8230;)</span></span></span></h2>
<p>So far we have looked at SQL Server integration only, but what if you like to use same powerful ZappySys API drivers part of <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ODBC PowerPack</a> in other Apps like Power BI, Excel, MS Access, Informatica and many more&#8230; ?? Well not to worry if you know that App supports ODBC you can use ZappySys ODBC Driver same way described earlier&#8230; only difference is you dont need Linked Server and you dont have to use OPENQUERY statement when you use ODBC Drivers.</p>
<div class="content_block" id="custom_post_widget-7051">ZappySys ODBC Drivers built using ODBC standard which is widely adopted by industry for a long time. Which mean the majority of BI Tools / Database Engines / ETL Tools already there will support native / 3rd party ODBC Drivers. Below is the small list of most popular tools / programming languages our Drivers support. If your tool / programming language doesn't appear in the below list, which means we have not documented use case but as long as your tool supports ODBC Standard, our drivers should work fine.

&nbsp;

<img loading="lazy" decoding="async" class="" src="//zappysys.com/images/odbc-powerpack/odbc-powerpack-integration.jpg" alt="ZappySys ODBC Drivers for REST API, JSON, XML - Integrate with Power BI, Tableau, QlikView, QlikSense, Informatica PowerCenter, Excel, SQL Server, SSIS, SSAS, SSRS, Visual Studio / WinForm / WCF, Python, C#, VB.net, PHP. PowerShell " width="750" height="372" />
<table style="valign: top;">
<tbody>
<tr>
<td>
<p style="text-align: center;"><strong>BI / Reporting Tools
Integration</strong></p>
</td>
<td style="text-align: center;"><strong>ETL Tools
Integration
</strong></td>
<td style="text-align: center;"><strong>Programming Languages</strong>
<strong>Integration</strong></td>
</tr>
<tr>
<td>
<ul>
 	<li><a href="https://zappysys.com/blog/howto-import-json-rest-api-power-bi/" target="_blank" rel="noopener">Microsoft Power BI</a></li>
 	<li><a href="https://zappysys.com/blog/import-rest-api-tableau-read-json-soap-xml-csv/">Tableau</a></li>
 	<li><a href="https://zappysys.com/blog/read-rest-api-using-ssrs-reports-call-json-xml-web-service/" target="_blank" rel="noopener">SSRS (SQL Reporting Services)</a></li>
 	<li><a href="https://zappysys.com/blog/qlik-rest-connector-examples-read-json-xml-api/" target="_blank" rel="noopener">QlikView /Qlik Sense</a></li>
 	<li><a href="https://zappysys.com/blog/call-rest-api-in-microstrategy-json-soap-xml/" target="_blank" rel="noopener">MicroStrategy</a></li>
 	<li><a href="https://zappysys.com/blog/import-rest-api-google-sheet-call-appscript-load-json-soap-xml-csv/" target="_blank" rel="noopener">Google Sheet</a></li>
 	<li><a href="https://zappysys.com/blog/import-json-excel-load-file-rest-api/" target="_blank" rel="noopener">Microsoft Excel</a></li>
 	<li><a href="https://zappysys.com/api/integration-hub/rest-api-connector/access?context=connector" target="_blank" rel="noopener">Microsoft Access</a></li>
 	<li>Oracle OBIEE</li>
 	<li>Many more (not in this list).....</li>
</ul>
</td>
<td>
<ul>
 	<li><a href="https://zappysys.com/blog/read-json-informatica-import-rest-api-json-file/" target="_blank" rel="noopener">Informatica PowerCenter</a> (Windows)</li>
 	<li>Informatica Cloud</li>
 	<li>SSIS (SQL Integration Services)</li>
 	<li><a href="https://zappysys.com/blog/import-rest-api-json-sql-server/" target="_blank" rel="noopener">SQL Server</a></li>
 	<li><a href="https://zappysys.com/blog/read-write-rest-api-data-in-talend-json-xml-soap/" target="_blank" rel="noopener">Talend Data Studio</a></li>
 	<li><a href="https://zappysys.com/blog/pentaho-read-rest-api-in-pentaho/" target="_blank" rel="noopener">Pentaho Kettle</a></li>
 	<li>Oracle OBIEE</li>
 	<li>Many more (not in this list).....</li>
</ul>
</td>
<td>
<ul>
 	<li>Visual Studio</li>
 	<li><a href="https://zappysys.com/blog/calling-rest-api-in-c/" target="_blank" rel="noopener">C#</a></li>
 	<li>C++</li>
 	<li><a href="https://zappysys.com/blog/connect-java-to-rest-api-json-soap-xml/" target="_blank" rel="noopener">JAVA</a></li>
 	<li><a href="https://zappysys.com/blog/set-rest-python-client/" target="_blank" rel="noopener">Python</a></li>
 	<li>PHP</li>
 	<li><a href="https://zappysys.com/blog/call-rest-api-powershell-script-export-json-csv/" target="_blank" rel="noopener">PowerShell</a></li>
 	<li><a href="https://zappysys.com/blog/import-rest-api-json-sql-server/" target="_blank" rel="noopener">T-SQL (Using Linked Server)</a></li>
</ul>
</td>
</tr>
</tbody>
</table>
&nbsp;</div>
<h2><span id="Step-by-Step_Import_REST_API_into_Power_BI">Conclusion</span></h2>
<p>So in this blog, we learned how to generate a PayPal API Token, Load PayPal data in MS SQL Server table using <a href="https://zappysys.com/products/odbc-powerpack/odbc-json-rest-api-driver/" target="_blank" rel="noopener">ODBC JSON / REST API Driver</a> in a very simple way. You can achieve many more functionalities with this tool. Check our blogs/articles on <a href="https://zappysys.com/blog/category/odbc-powerpack/odbc-drivers/json-rest-api-driver/" target="_blank" rel="noopener"><strong>JSON / REST API Driver</strong></a> to find out what <em>this tool</em> is capable of more.</p>
<h2><span id="References">References</span></h2>
<p>Finally, you can use the following links for more information about the use of PayPal API with our tools:</p>
<ul>
<li><strong>Landing Page</strong> for <a href="https://zappysys.com/products/odbc-powerpack/odbc-json-rest-api-driver/" target="_blank" rel="noopener">ODBC JSON / REST API Driver</a>, you can also find <a href="https://youtu.be/iwezz0Z3D4U" target="_blank" rel="noopener">Tutorial Video</a> here.</li>
<li><strong>Help File:</strong> Documentation of <a href="https://zappysys.com/onlinehelp/odbc-powerpack/index.htm#page=json-odbc-driver-intro.htm" target="_blank" rel="noopener">JSON Driver</a>.</li>
<li><a href="https://developer.paypal.com/docs/api/overview/" target="_blank" rel="noopener">PayPal API</a></li>
</ul>
<p>The post <a href="https://zappysys.com/blog/make-paypal-api-call-odbc-sql-server/">How to Make PayPal API Call in ODBC / SQL Server (T-SQL)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Import SAP S/4HANA OData Service Data Into Sql Server via ODBC Driver</title>
		<link>https://zappysys.com/blog/import-sap-s-4hana-odata-service-sql-server/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Sat, 20 Jul 2019 10:01:04 +0000</pubDate>
				<category><![CDATA[ODBC Gateway]]></category>
		<category><![CDATA[T-SQL (SQL Server)]]></category>
		<category><![CDATA[XML File / SOAP API Driver]]></category>
		<category><![CDATA[hana]]></category>
		<category><![CDATA[odbc]]></category>
		<category><![CDATA[s/4hana]]></category>
		<category><![CDATA[sap]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[xml]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=7490</guid>

					<description><![CDATA[<p>Introduction In our previous blog we saw how to read JIRA data in SQL Server. Now let’s learn how to Import SAP S/4HANA OData Service Data Into Sql Server. SAP S/4HANA provides OData REST API interface to access data in your application using HTTP Protocol. We will use ODBC XML Driver to read SAP data and load [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/import-sap-s-4hana-odata-service-sql-server/">Import SAP S/4HANA OData Service Data Into Sql Server via ODBC Driver</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2><span id="Introduction">Introduction</span></h2>
<p><a href="https://zappysys.com/blog/wp-content/uploads/2019/07/SAP_S4HANA.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="alignleft wp-image-7491 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/07/SAP_S4HANA.png" alt="SAP S/4HANA" width="150" height="150" /></a></p>
<p>In our previous blog we saw how to <a href="https://zappysys.com/blog/load-jira-data-sql-server-odbc-call-rest-api/" target="_blank" rel="noopener">read JIRA data in SQL Server</a>. Now let’s learn how to Import SAP S/4HANA OData Service Data Into Sql Server. SAP S/4HANA provides OData REST API interface to access data in your application using HTTP Protocol. We will use <a href="https://zappysys.com/products/odbc-powerpack/odbc-xml-soap-api-driver/" target="_blank" rel="noopener">ODBC XML Driver</a> to read SAP data and load into SQL Server.</p>
<p>So, let’s get started.</p>
<div id="custom_post_widget-2523" class="content_block">
<h2></h2>
<h2></h2>
<h2><span id="Requirements">Requirements</span></h2>
<ol>
<li>A first requirement will be to SQL Server Database Engine Installed</li>
<li>The second requirement will be SSMS installed</li>
<li>Finally, make sure to have <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> installed.</li>
</ol>
</div>
<h2><span id="About_SAP_HANA_OData_REST_API_Service">About SAP HANA / OData REST API Service</span></h2>
<p>You can expose your SAP Data using ODATA REST API Service. Here is a <a href="https://www.erpworkbench.com/sap-webapps/segw-odata-gateway-service.htm" target="_blank" rel="noopener">good article</a> which shows how to expose data as OData Service.   For more information on SAP OData Service feature check this <a href="https://help.sap.com/doc/05d53b2d3bbb43d2ab5efa23829b2777/1610%20001/en-US/frameset.htm?ecaeea50ca692309e10000000a445394.html" target="_blank" rel="noopener">SAP help page</a>. If you are new to OData Standard then <a href="https://www.odata.org/getting-started/basic-tutorial/" target="_blank" rel="noopener">read here</a> to know more how OData can facilitate data extraction using HTTP REST API. If you need Sample XML based OData Service then use below test URLs.</p><pre class="crayon-plain-tag">https://services.odata.org/Northwind/Northwind.svc/
https://services.odata.org/Northwind/Northwind.svc/Customers
https://services.odata.org/Northwind/Northwind.svc/Orders
https://services.odata.org/Northwind/Northwind.svc/Invoices
https://services.odata.org/Northwind/Northwind.svc/Products</pre><p>
Now let’s look at how to read SAP Data using ODBC Driver. At this point we assume you have exposed your data as OData Endpoint.</p>
<h2><span id="Read_SAP_HANA_data_using_XML_Source">Read SAP S/4HANA data using XML Driver</span></h2>
<p>First let’s look at steps to configure XML Driver. We will read data from SAP S/4HANA OData Service and then in next section we will look at how to load data into SQL Server or other target.</p>
<ol>
<li>To do this, first of all, we will open the ZappySys Data Gateway Configuration:
<div id="attachment_5283" style="width: 410px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5283" class="wp-image-5283 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png" alt="Open ZappySys Data Gateway" width="400" height="315" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png 400w, https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway-300x236.png 300w" sizes="(max-width: 400px) 100vw, 400px" /></a><p id="caption-attachment-5283" class="wp-caption-text">Open ZappySys Data Gateway</p></div></li>
<li>Add the Native &#8211; ZappySys XML Driver Data source.
<div id="attachment_5284" style="width: 568px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5284" class="wp-image-5284 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source.png" alt="Add Gateway Data Source" width="558" height="533" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source.png 558w, https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source-300x287.png 300w" sizes="(max-width: 558px) 100vw, 558px" /></a><p id="caption-attachment-5284" class="wp-caption-text">Add Gateway Data Source</p></div></li>
<li>Now edit that XML data source to configure it. Enter your OData Service URL its typically like below. Replace 3 parts with your own value (i.e. replace {MY-INSTANCE},  {MY-PROJECT}, {MY-TABLE})<br />
<pre class="crayon-plain-tag">https://{MY-INSTANCE}/sap/opu/odata/sap/{MY-PROJECT}/{MY-TABLE}</pre>
For example if you are hosting SAP HANA in Cloud Instance then your URL may look like below<br />
<pre class="crayon-plain-tag">https://myXXXXXX-api.s4hana.ondemand.com/sap/opu/odata/sap/MyTestProject/PurchaseOrders</pre>
And create New ZS-HTTP connection in it select <a href="https://zappysys.com/blog/how-to-set-base64-encoded-authorization-header-for-http-web-request/" target="_blank" rel="noopener">Basic Authentication</a> and enter your SAP HANA UserID / Password to call OData Service and select the desire filter.</p>
<div id="attachment_7497" style="width: 730px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/07/odbc-xml-driver-sap-hana-odata-service.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7497" class="wp-image-7497 size-medium_large" src="https://zappysys.com/blog/wp-content/uploads/2019/07/odbc-xml-driver-sap-hana-odata-service-768x537.png" alt="XML Driver : SAP S/4HANA OData Service Configuration" width="720" height="503" srcset="https://zappysys.com/blog/wp-content/uploads/2019/07/odbc-xml-driver-sap-hana-odata-service-768x537.png 768w, https://zappysys.com/blog/wp-content/uploads/2019/07/odbc-xml-driver-sap-hana-odata-service-300x210.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/07/odbc-xml-driver-sap-hana-odata-service.png 1019w" sizes="(max-width: 720px) 100vw, 720px" /></a><p id="caption-attachment-7497" class="wp-caption-text">XML Driver : SAP S/4HANA OData Service Configuration</p></div></li>
<li>Now go to Data Format / Compression (Zip/GZip) tab and select Data Format as OData to get all the records.
<div id="attachment_7498" style="width: 730px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/07/odbc-driver-select-odata-data-format.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7498" class="wp-image-7498 size-medium_large" src="https://zappysys.com/blog/wp-content/uploads/2019/07/odbc-driver-select-odata-data-format-768x446.png" alt="Data Format : Odata" width="720" height="418" srcset="https://zappysys.com/blog/wp-content/uploads/2019/07/odbc-driver-select-odata-data-format-768x446.png 768w, https://zappysys.com/blog/wp-content/uploads/2019/07/odbc-driver-select-odata-data-format-300x174.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/07/odbc-driver-select-odata-data-format.png 792w" sizes="(max-width: 720px) 100vw, 720px" /></a><p id="caption-attachment-7498" class="wp-caption-text">Data Format : Odata</p></div></li>
<li>Finally, now using Query Builder and Code Generator we will generate the query.
<div id="attachment_6416" style="width: 766px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-generate-quickbooks-query.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-6416" class="wp-image-6416 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-generate-quickbooks-query.png" alt="odbc-json-driver-generate-quickbooks-query" width="756" height="432" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-generate-quickbooks-query.png 756w, https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-generate-quickbooks-query-300x171.png 300w" sizes="(max-width: 756px) 100vw, 756px" /></a><p id="caption-attachment-6416" class="wp-caption-text">Generate Query</p></div></li>
<li>That’s it we are ready to load SAP S/4HANA OData Service data to SQL Server.</li>
</ol>
<h2>Load SAP S/4HANA OData Service in MS SQL Server</h2>
<div class="content_block" id="custom_post_widget-6457">Once you configured the data source in Gateway, we can now setup Linked Server in SQL Server to query API data.
<ol style="margin-left: 10px;">
 	<li>Assuming you have installed SQL Server and SSMS. If not then get both for FREE from here: <a href="https://www.microsoft.com/en-us/sql-server/sql-server-editions-express" target="_blank" rel="noopener">Get SQL Server Express</a> and  <a href="https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms" target="_blank" rel="noopener">Get SSMS</a></li>
 	<li>Open SSMS and connect to SQL Server.</li>
 	<li>Go to Root &gt; Server Objects &gt; Linked Servers node. Right click and click <strong>New Linked Server...</strong>
<div class="wp-caption alignnone">

<a href="https://i1.wp.com/zappysys.com/blog/wp-content/uploads/2018/03/create-new-linked-server-ssms.png?ssl=1" target="_blank" rel="noopener"><img loading="lazy" decoding="async" src="https://i1.wp.com/zappysys.com/blog/wp-content/uploads/2018/03/create-new-linked-server-ssms.png?w=720&amp;ssl=1" alt="Add Linked Server in SQL Server" width="420" height="262" /></a>
<p class="wp-caption-text">Add Linked Server in SQL Server</p>

</div></li>
 	<li> Now enter the linked server name, select Provider as SQL Native Client</li>
 	<li>Enter data source as <strong><span class="lang:default decode:true crayon-inline">GatewayServerName, PORT_NUMBER</span></strong> where server name is where ZappySys Gateway is running (Can be same as SQL Server machine or remote machine). Default PORT_NUMBER is 5000 but confirm on Data gateway &gt; General tab in case its different.</li>
 	<li>Enter Catalog Name. This must match name from Data gateway Data sources grid &gt; Name column
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/ssms-sql-server-configure-linked-server-2.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/ssms-sql-server-configure-linked-server-2.png" alt="Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection" />
</a>
<p class="wp-caption-text">Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection</p>
</div>
<div style="color: #31708f;background-color: #d9edf7;border-color: #bce8f1;padding: 15px;margin-bottom: 20px;border: 1px solid transparent;border-radius: 4px;">
<strong>INFO:</strong><br/>
<ul>
    <li>
      For <strong>SQL Server 2012, 2014, 2016, 2017, and 2019</strong>, use the <em>SQL Server Native Client 11.0</em> as the Provider.
    </li>
    <li>
      For <strong>SQL Server 2022 or higher</strong>, use the <em>Microsoft OLE DB Driver for SQL Server</em> as the Provider.
    </li>
  </ul>
</div></li>
 	<li>Click on Security Tab and select last option "<strong>Be made using this security context</strong>". Enter your gateway user account here.</li>
<li>
        <p>Optional: Under the Server Options Tab, Enable <b>RPC</b> and <b>RPC Out</b> and Disable Promotion of Distributed Transactions<b>(MSDTC)</b>.</p>
		<div class="wp-caption alignnone">
			<img decoding="async" class="block margin-bottom-10 img-thumbnail" src="https://zappysys.com/blog/wp-content/uploads/2018/11/linked-server-options-rpc-msdtc.png" title="RPC and MSDTC Settings" alt="RPC and MSDTC Settings" />
			<p class="wp-caption-text">RPC and MSDTC Settings</p>
		</div>
        <hr />
        <p>
            You need to enable RPC Out if you plan to use <b><i>EXEC(...) AT [MY_LINKED_SERVER_NAME]</i></b> rather than OPENQUERY.
            <br />
            If don't enabled it, you will encounter the <i>'Server "MY_LINKED_SERVER_NAME" is not configured for RPC'</i> error.
        </p>
        <p>
            Query Example:
            <code class="sql">EXEC('Select * from Products') AT [MY_LINKED_SERVER_NAME]</code>
        </p>
        <hr />
        <p>
            If you plan to use <b><i>'INSERT INTO...EXEC(....) AT [MY_LINKED_SERVER_NAME]'</i></b> in that case you need to Disable Promotion of Distributed Transactions(MSDTC).
            <br />
            If don't disabled it, you will encounter the <i>'The operation could not be performed because OLE DB provider "SQLNCLI11/MSOLEDBSQL" for linked server "MY_LINKED_SERVER_NAME" was unable to begin a distributed transaction.'</i> error.
        </p>
        <p>
            Query Example:
<pre class="">Insert Into dbo.Products 
EXEC('Select * from Products') AT [MY_LINKED_SERVER_NAME]</pre>
        </p>
        <hr />
</li>
 	<li>Click OK to save Linked Server</li>
 	<li>In SSMS execute below SQL query to test your connectivity.
<pre class="">SELECT * FROM OPENQUERY( MY_LINKED_SERVER_NAME, 'SELECT * FROM $')</pre>
</li>
 	<li>Here is the preview after you run some REST API query in SQL Server. Notice that you can override default configuration by supplying <a href="https://zappysys.com/onlinehelp/odbc-powerpack/scr/json-odbc-driver-connectionstring.htm" target="_blank" rel="noopener">many parameters</a> in WITH clause (second query example in the screenshot).
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc_json_driver__api_query_data_in_mssqlserver.png" target="_blank" rel="noopener">
<img loading="lazy" decoding="async" width="750" height="354" class="wp-image-6455 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc_json_driver__api_query_data_in_mssqlserver.png" alt="odbc_json_driver_api_query_data_in_mssqlserver" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc_json_driver__api_query_data_in_mssqlserver.png 750w, https://zappysys.com/blog/wp-content/uploads/2019/01/odbc_json_driver__api_query_data_in_mssqlserver-300x142.png 300w" sizes="(max-width: 750px) 100vw, 750px" />
</a>
<p class="wp-caption-text">SSMS Output - Query REST API via Linked Server OPENQUERY statement (Connect to ZappySys Data Gateway)</p>

</div></li>
 	<li>You can wrap your queries inside View or wrap inside Stored procedure to parameterize. Here is an example of creating the view which calls REST API queries.
<pre class="lang:tsql decode:true">CREATE VIEW dbo.vw_MyAPICall_View 
AS 
/*Call REST API inside SQL Server View*/
SELECT * FROM OPENQUERY( MY_LINKED_SERVER_NAME , 'SELECT * FROM $');

GO
</pre>
</li>
 	<li>Notice in above approach if you parameterize Stored Procedure then <a href="https://zappysys.com/blog/create-csv-list-sql-server-table-columns-datatypes/" target="_blank" rel="noopener">check this article to understand Dynamic Metadata</a>.</li>
 	<li>Now let's insert API data into the new data table "tblMyAPiData" in the SQL server database. For that, we need to execute below SQL query.
<pre class="lang:tsql decode:true ">Select * into tblMyAPiData FROM OPENQUERY( MY_LINKED_SERVER_NAME , 'SELECT * FROM $')</pre>
<div class="wp-caption alignnone">

<a href="https://zappysys.com/blog/wp-content/uploads/2019/02/odbc_json_driver_insert_data_in_sql.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" width="681" height="571" class="wp-image-6469 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/02/odbc_json_driver_insert_data_in_sql.png" alt="odbc_json_driver_insert_data_in_sql" srcset="https://zappysys.com/blog/wp-content/uploads/2019/02/odbc_json_driver_insert_data_in_sql.png 681w, https://zappysys.com/blog/wp-content/uploads/2019/02/odbc_json_driver_insert_data_in_sql-300x252.png 300w" sizes="(max-width: 681px) 100vw, 681px" /></a>
<p class="wp-caption-text">Insert data into the new table</p>

</div></li>
 	<li>Let's insert and update records into the already created table <span class="lang:default decode:true crayon-inline">"tblMyAPiData"</span>
<ul>
 	<li>To do that first we need to insert the new API data into the <span class="lang:default decode:true crayon-inline">"#temp_tblMyAPiData"</span> temporary database table.</li>
 	<li>Now let's delete the old records from the database table which are updated.</li>
 	<li>At the last insert all new API data into the database table.</li>
 	<li>To do that, we need to query like below SQL queries.</li>
</ul>
<pre class="lang:default decode:true">SELECT * into #temp_tblMyAPiData FROM OPENQUERY(MY_LINKED_SERVER_NAME, 'SELECT * FROM $')

DELETE FROM [dbo].[tblMyAPiData] WHERE id in (SELECT id FROM #temp_tblMyAPiData)

INSERT INTO tblMyAPiData
SELECT * FROM #temp_tblMyAPiData</pre>
&nbsp;</li>
 	<li>In the upper step, we see how to insert and update new records. Now if you want to update particular fields records only then you need to query like this.
<pre class="lang:default decode:true">Update dbtbl_1
set dbtbl_1.field1 = dbtbl_2.field1,
    dbtbl_1.field2 = dbtbl_2.field2
FROM tblMyAPiData dbtbl_1
JOIN (SELECT * FROM OPENQUERY(MY_LINKED_SERVER_NAME, 'SELECT * FROM $')) dbtbl_2 on dbtbl_1.id=dbtbl_2.id</pre>
<div class="su-note-inner su-clearfix" style="background-color: #fff4b7;border-color: #fffdf1;color: #333333">
<blockquote>*NOTE: If you are getting error like : "<strong>Cannot resolve the collation conflict between “Latin1_General_CI_AI” and “SQL_Latin1_General_CP1_CI_AS” in the equal to operation</strong>" then you need to query like this :
<pre class="lang:default decode:true">Update dbtbl_1
set dbtbl_1.field1 = dbtbl_2.field1,
    dbtbl_1.field2 = dbtbl_2.field2
FROM tblMyAPiData dbtbl_1
JOIN (SELECT * FROM OPENQUERY(MY_LINKED_SERVER_NAME, 'SELECT * FROM $')) dbtbl_2 
on dbtbl_1.id=dbtbl_2.id 
<strong>COLLATE SQL_Latin1_General_CP1_CI_AS</strong></pre>
&nbsp;</blockquote>
</div></li>
</ol></div>
<h2>SAP S/4HANA Integration with Other BI Tools (Power BI, Excel, SSRS, MS Access&#8230;)</h2>
<div class="content_block" id="custom_post_widget-7051">ZappySys ODBC Drivers built using ODBC standard which is widely adopted by industry for a long time. Which mean the majority of BI Tools / Database Engines / ETL Tools already there will support native / 3rd party ODBC Drivers. Below is the small list of most popular tools / programming languages our Drivers support. If your tool / programming language doesn't appear in the below list, which means we have not documented use case but as long as your tool supports ODBC Standard, our drivers should work fine.

&nbsp;

<img loading="lazy" decoding="async" class="" src="//zappysys.com/images/odbc-powerpack/odbc-powerpack-integration.jpg" alt="ZappySys ODBC Drivers for REST API, JSON, XML - Integrate with Power BI, Tableau, QlikView, QlikSense, Informatica PowerCenter, Excel, SQL Server, SSIS, SSAS, SSRS, Visual Studio / WinForm / WCF, Python, C#, VB.net, PHP. PowerShell " width="750" height="372" />
<table style="valign: top;">
<tbody>
<tr>
<td>
<p style="text-align: center;"><strong>BI / Reporting Tools
Integration</strong></p>
</td>
<td style="text-align: center;"><strong>ETL Tools
Integration
</strong></td>
<td style="text-align: center;"><strong>Programming Languages</strong>
<strong>Integration</strong></td>
</tr>
<tr>
<td>
<ul>
 	<li><a href="https://zappysys.com/blog/howto-import-json-rest-api-power-bi/" target="_blank" rel="noopener">Microsoft Power BI</a></li>
 	<li><a href="https://zappysys.com/blog/import-rest-api-tableau-read-json-soap-xml-csv/">Tableau</a></li>
 	<li><a href="https://zappysys.com/blog/read-rest-api-using-ssrs-reports-call-json-xml-web-service/" target="_blank" rel="noopener">SSRS (SQL Reporting Services)</a></li>
 	<li><a href="https://zappysys.com/blog/qlik-rest-connector-examples-read-json-xml-api/" target="_blank" rel="noopener">QlikView /Qlik Sense</a></li>
 	<li><a href="https://zappysys.com/blog/call-rest-api-in-microstrategy-json-soap-xml/" target="_blank" rel="noopener">MicroStrategy</a></li>
 	<li><a href="https://zappysys.com/blog/import-rest-api-google-sheet-call-appscript-load-json-soap-xml-csv/" target="_blank" rel="noopener">Google Sheet</a></li>
 	<li><a href="https://zappysys.com/blog/import-json-excel-load-file-rest-api/" target="_blank" rel="noopener">Microsoft Excel</a></li>
 	<li><a href="https://zappysys.com/api/integration-hub/rest-api-connector/access?context=connector" target="_blank" rel="noopener">Microsoft Access</a></li>
 	<li>Oracle OBIEE</li>
 	<li>Many more (not in this list).....</li>
</ul>
</td>
<td>
<ul>
 	<li><a href="https://zappysys.com/blog/read-json-informatica-import-rest-api-json-file/" target="_blank" rel="noopener">Informatica PowerCenter</a> (Windows)</li>
 	<li>Informatica Cloud</li>
 	<li>SSIS (SQL Integration Services)</li>
 	<li><a href="https://zappysys.com/blog/import-rest-api-json-sql-server/" target="_blank" rel="noopener">SQL Server</a></li>
 	<li><a href="https://zappysys.com/blog/read-write-rest-api-data-in-talend-json-xml-soap/" target="_blank" rel="noopener">Talend Data Studio</a></li>
 	<li><a href="https://zappysys.com/blog/pentaho-read-rest-api-in-pentaho/" target="_blank" rel="noopener">Pentaho Kettle</a></li>
 	<li>Oracle OBIEE</li>
 	<li>Many more (not in this list).....</li>
</ul>
</td>
<td>
<ul>
 	<li>Visual Studio</li>
 	<li><a href="https://zappysys.com/blog/calling-rest-api-in-c/" target="_blank" rel="noopener">C#</a></li>
 	<li>C++</li>
 	<li><a href="https://zappysys.com/blog/connect-java-to-rest-api-json-soap-xml/" target="_blank" rel="noopener">JAVA</a></li>
 	<li><a href="https://zappysys.com/blog/set-rest-python-client/" target="_blank" rel="noopener">Python</a></li>
 	<li>PHP</li>
 	<li><a href="https://zappysys.com/blog/call-rest-api-powershell-script-export-json-csv/" target="_blank" rel="noopener">PowerShell</a></li>
 	<li><a href="https://zappysys.com/blog/import-rest-api-json-sql-server/" target="_blank" rel="noopener">T-SQL (Using Linked Server)</a></li>
</ul>
</td>
</tr>
</tbody>
</table>
&nbsp;</div>
<h2><span id="Step-by-Step_Import_REST_API_into_Power_BI">Conclusion</span></h2>
<p>So in this blog, we learned how to Import SAP S/4HANA OData Service Data in MS SQL Server using <a href="https://zappysys.com/products/odbc-powerpack/odbc-xml-soap-api-driver/" target="_blank" rel="noopener">ODBC XML / SOAP API Driver</a> in a very simple way. You can achieve many more functionalities with this tool. Check our blogs/articles on <strong>XML File / REST API Driver </strong><a href="https://zappysys.com/blog/category/odbc-powerpack/odbc-drivers/xml-soap-api-driver/">https://zappysys.com/blog/category/odbc-powerpack/odbc-drivers/xml-soap-api-driver/</a> to find out what <em>this tool</em> is capable of more.</p>
<h2><span id="References">References</span></h2>
<p>Finally, you can use the following links for more information about the use of SAP S/4HANA OData Service with our tools:</p>
<ul>
<li><a href="https://api.sap.com/" target="_blank" rel="noopener">SAP API Business Hub</a></li>
<li><strong>Landing Page</strong> for <a href="https://zappysys.com/products/odbc-powerpack/odbc-xml-soap-api-driver/" target="_blank" rel="noopener">ODBC XML / SOAP API Driver</a>, you can also find <a href="https://youtu.be/iwezz0Z3D4U" target="_blank" rel="noopener">Tutorial Video</a> here.</li>
<li><strong>Help File:</strong> Documentation of <a href="https://zappysys.com/onlinehelp/odbc-powerpack/index.htm#page=xml-odbc-driver-intro.htm" target="_blank" rel="noopener">XML Driver</a>.</li>
<li><strong>Blog/articles link</strong>: <a href="https://zappysys.com/blog/category/odbc-powerpack/odbc-drivers/xml-soap-api-driver/" target="_blank" rel="noopener">https://zappysys.com/blog/category/odbc-powerpack/odbc-drivers/xml-soap-api-driver/</a></li>
</ul>
<p>The post <a href="https://zappysys.com/blog/import-sap-s-4hana-odata-service-sql-server/">Import SAP S/4HANA OData Service Data Into Sql Server via ODBC Driver</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Import Bing Ads data into SQL Server (Performance Reports)</title>
		<link>https://zappysys.com/blog/import-bing-ads-data-sql-server-performance-reports/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Thu, 13 Jun 2019 21:04:57 +0000</pubDate>
				<category><![CDATA[ODBC Gateway]]></category>
		<category><![CDATA[REST API Integration]]></category>
		<category><![CDATA[T-SQL (SQL Server)]]></category>
		<category><![CDATA[XML File / SOAP API Driver]]></category>
		<category><![CDATA[Bing Ads]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[xml]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=7217</guid>

					<description><![CDATA[<p>Introduction In our previous blog post we saw how to import REST / SOAP API in SQL Server. Using same concepts let&#8217;s look at how to import Bing Ads data into SQL Server. We will explore many techniques to call Bing Ads API and learn how to automate data extraction without doing any ETL. You [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/import-bing-ads-data-sql-server-performance-reports/">Import Bing Ads data into SQL Server (Performance Reports)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p><a href="https://zappysys.com/blog/wp-content/uploads/2019/06/bing-ads-logo.png"><img loading="lazy" decoding="async" class=" wp-image-7363 alignleft" src="https://zappysys.com/blog/wp-content/uploads/2019/06/bing-ads-logo.png" alt="" width="190" height="158" /></a>In our previous blog post we saw how to <a href="https://zappysys.com/blog/import-rest-api-json-sql-server/" target="_blank" rel="noopener">import REST / SOAP API in SQL Server</a>. Using same concepts let&#8217;s look at how to import Bing Ads data into SQL Server. We will explore many techniques to call Bing Ads API and learn how to automate data extraction without doing any ETL. You can call Bing Ads API just using T-SQL code (Yes you heard it right). At the end of this article you will learn how to <strong>Download Performance Reports from Bing Ads Account</strong> without any coding (See sample screenshot below). Please go through full article carefully.</p>
<p><strong>NOTE:</strong> Bing Ads now renamed as Microsoft Advertising but this article will use popular name for time being.</p>
<h2></h2>
<div id="attachment_7218" style="width: 841px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/06/import-bing-ads-data-into-sql-server-table.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7218" class="size-full wp-image-7218" src="https://zappysys.com/blog/wp-content/uploads/2019/06/import-bing-ads-data-into-sql-server-table.png" alt="Import Bing Ads data into SQL Server (Using SSMS T-SQL Code)" width="831" height="741" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/import-bing-ads-data-into-sql-server-table.png 831w, https://zappysys.com/blog/wp-content/uploads/2019/06/import-bing-ads-data-into-sql-server-table-300x268.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/06/import-bing-ads-data-into-sql-server-table-768x685.png 768w" sizes="(max-width: 831px) 100vw, 831px" /></a><p id="caption-attachment-7218" class="wp-caption-text">Import Bing Ads data into SQL Server (Using SSMS T-SQL Code)</p></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div class="content_block" id="custom_post_widget-7048"><h2>Requirements</h2>
This article talks about few tools and techniques in order to load API data in SQL Server. Please make sure following prerequisites are met.
<ol>
 	<li>Download and Install <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> (This includes XML / JSON / REST API and few other drivers for SQL Server and ODBC connectivity in tools like Excel, Power BI, SSRS)</li>
 	<li>Make sure you have access to SQL Server Instance. If you cant find one still want to try what is mentioned in this article then install <a href="https://www.microsoft.com/en-us/sql-server/sql-server-editions-express" target="_blank" rel="noopener">FREE SQL Express Edition</a></li>
 	<li>Confirm that you have SSMS Installed. If you don't have then you can download <a href="https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-2017">from here</a>.</li>
</ol></div>
<h2>About Bing Ads API / SOAP Web Service</h2>
<p>If you are new to Bing Ads API then <a href="https://docs.microsoft.com/en-us/advertising/" target="_blank" rel="noopener">start from here</a>. Bing Ads APIs are SOAP XML APIs. You can call it to automate <a href="https://docs.microsoft.com/en-us/advertising/guides/?view=bingads-13" target="_blank" rel="noopener">many scenarios</a> for Bing Ads. In this article we will mainly focus on read scenario (e.g. Read Performance Data) but you can use these techniques to write / update (e.g. Create New Campaign).</p>
<p>If you are new to SOAP WebService then <a href="https://zappysys.com/blog/calling-soap-web-service-in-ssis-xml-source/" target="_blank" rel="noopener">Check this article</a> to learn more. It will explain you how to use tools like <strong>SoapUI</strong> tool to craft SOAP Requests for Bing API or any other SOAP API.</p>
<p>For Bing API you can use Service WSDL files <a href="https://docs.microsoft.com/en-us/advertising/guides/web-service-addresses?view=bingads-13" target="_blank" rel="noopener">found here</a>. Use URL ending <strong>?wsdl</strong> to import in SoapUI.</p>
<h2>Example Bing API Request</h2>
<p>Here is raw API request for Bing API. This sample assumes you have completed 3-Legged OAuth Authorization to obtain AccessToken and RefreshToken (Explained later in this article). Below request uses AccessToken you might have already obtained via <a href="https://docs.microsoft.com/en-us/advertising/guides/get-started?view=bingads-13#get-developer-token" target="_blank" rel="noopener">process like this</a>. If you are using ZappySys tools then this will be generated automatically for you.</p>
<p><strong>Request Method / URL:</strong></p><pre class="crayon-plain-tag">POST https://clientcenter.api.bingads.microsoft.com/Api/CustomerManagement/v13/CustomerManagementService.svc</pre><p>
<strong>Headers:<br />
</strong>Notice that for each Api you may need correct <strong>SOAPAction</strong> in Header. If you are not sure then use SoapUI Tool. Execute request in SoapUI and then go to <strong>Raw tab </strong><a href="https://zappysys.com/blog/wp-content/uploads/2016/06/soapui-get-contenttype-soapaction-raw-tab.png" target="_blank" rel="noopener">like this one</a>.</p><pre class="crayon-plain-tag">Content-Type: text/xml; charset=utf-8
SOAPAction: "GetUser"</pre><p>
<strong>Body:<br />
</strong>Notice that you have to replace <strong>AuthenticationToken</strong> and <strong>DeveloperToken</strong> in below request. AccessToken is placed inside AuthenticationToken tag. This Auth token is short lived and extracted via OAuth Process and DeveloperToken you can extract as mentioned in the previous section <a href="https://developers.ads.microsoft.com/Account">or get it from here</a>.</p><pre class="crayon-plain-tag"><s:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header xmlns="https://bingads.microsoft.com/Customer/v13">
    <Action mustUnderstand="1">GetUser</Action>
    <AuthenticationToken i:nil="false"><%access_token%></AuthenticationToken>
    <DeveloperToken i:nil="false">1052Bxxxxxxxxxxxxxx</DeveloperToken>
  </s:Header>
  <s:Body>
    <GetUserRequest xmlns="https://bingads.microsoft.com/Customer/v13">
      <UserId i:nil="true"></UserId>
    </GetUserRequest>
  </s:Body>
</s:Envelope></pre><p>
<strong>Response:</strong></p><pre class="crayon-plain-tag">&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;s:Header&gt;
    &lt;h:TrackingId xmlns:h="https://bingads.microsoft.com/Customer/v13"&gt;fddf3cb9-e4c2-4e75-9546-f3bc20ea91a8&lt;/h:TrackingId&gt;
  &lt;/s:Header&gt;
  &lt;s:Body&gt;
    &lt;GetUserResponse xmlns="https://bingads.microsoft.com/Customer/v13"&gt;
      &lt;User xmlns:a="https://bingads.microsoft.com/Customer/v13/Entities" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
        &lt;a:ContactInfo&gt;
          &lt;a:Address&gt;
            &lt;a:City i:nil="true" /&gt;
            &lt;a:CountryCode&gt;US&lt;/a:CountryCode&gt;
            &lt;a:Id i:nil="true" /&gt;
            &lt;a:Line1 i:nil="true" /&gt;
            &lt;a:Line2 i:nil="true" /&gt;
            &lt;a:Line3 i:nil="true" /&gt;
            &lt;a:Line4 i:nil="true" /&gt;
            &lt;a:PostalCode i:nil="true" /&gt;
            &lt;a:StateOrProvince i:nil="true" /&gt;
            &lt;a:TimeStamp i:nil="true" /&gt;
            &lt;a:BusinessName i:nil="true" /&gt;
          &lt;/a:Address&gt;
          &lt;a:ContactByPhone&gt;false&lt;/a:ContactByPhone&gt;
          &lt;a:ContactByPostalMail&gt;false&lt;/a:ContactByPostalMail&gt;
          &lt;a:Email&gt;someone@zappysys.com&lt;/a:Email&gt;
          &lt;a:EmailFormat i:nil="true" /&gt;
          &lt;a:Fax i:nil="true" /&gt;
          &lt;a:HomePhone i:nil="true" /&gt;
          &lt;a:Id&gt;48045678&lt;/a:Id&gt;
          &lt;a:Mobile i:nil="true" /&gt;
          &lt;a:Phone1&gt;111-222-3333&lt;/a:Phone1&gt;
          &lt;a:Phone2 i:nil="true" /&gt;
        &lt;/a:ContactInfo&gt;
        &lt;a:CustomerId&gt;19112345&lt;/a:CustomerId&gt;
        &lt;a:Id&gt;48012345&lt;/a:Id&gt;
        &lt;a:JobTitle i:nil="true" /&gt;
        &lt;a:LastModifiedByUserId&gt;48012345&lt;/a:LastModifiedByUserId&gt;
        &lt;a:LastModifiedTime&gt;2019-06-04T14:22:35.38&lt;/a:LastModifiedTime&gt;
        &lt;a:Lcid&gt;EnglishUS&lt;/a:Lcid&gt;
        &lt;a:Name&gt;
          &lt;a:FirstName&gt;Someone&lt;/a:FirstName&gt;
          &lt;a:LastName&gt;Good&lt;/a:LastName&gt;
          &lt;a:MiddleInitial i:nil="true" /&gt;
        &lt;/a:Name&gt;
        &lt;a:Password i:nil="true" /&gt;
        &lt;a:SecretAnswer i:nil="true" /&gt;
        &lt;a:SecretQuestion&gt;None&lt;/a:SecretQuestion&gt;
        &lt;a:UserLifeCycleStatus&gt;Active&lt;/a:UserLifeCycleStatus&gt;
        &lt;a:TimeStamp&gt;AAAAAJiX/cU=&lt;/a:TimeStamp&gt;
        &lt;a:UserName&gt;someone@zappysys.com&lt;/a:UserName&gt;
        &lt;a:ForwardCompatibilityMap i:nil="true" xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic" /&gt;
      &lt;/User&gt;
      &lt;CustomerRoles xmlns:a="https://bingads.microsoft.com/Customer/v13/Entities" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
        &lt;a:CustomerRole&gt;
          &lt;a:RoleId&gt;41&lt;/a:RoleId&gt;
          &lt;a:CustomerId&gt;19160000&lt;/a:CustomerId&gt;
          &lt;a:AccountIds i:nil="true" xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays" /&gt;
          &lt;a:LinkedAccountIds xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays" /&gt;
          &lt;a:CustomerLinkPermission i:nil="true" /&gt;
        &lt;/a:CustomerRole&gt;
      &lt;/CustomerRoles&gt;
    &lt;/GetUserResponse&gt;
  &lt;/s:Body&gt;
&lt;/s:Envelope&gt;</pre><p>
<div class="content_block" id="custom_post_widget-7357"><h2>Things to know about REST / SOAP API</h2>
Before we deep dive into calling your specific APIs you like to integrate, you must have basic understanding what is REST API / SOAP API. In this section we will cover few important concepts and difference about these two API styles REST vs SOAP.
<h3><strong>What is REST API (or RESTful API)</strong></h3>
As per wikipedia <a href="https://en.wikipedia.org/wiki/Representational_state_transfer" target="_blank" rel="noopener">REST</a> is an architecture style which can be used to to expose data over the internet using http / https. Using REST style you can expose data operations / functions which can be called by other users. With API calls You can read / write data or just call business functions which triggers some workflow.

Most APIs documents various aspects of calling API (REST or SOAP). You need to pass these details accurately. Refer to your API documentation <a href="https://developer.zendesk.com/rest_api/docs/support/introduction" target="_blank" rel="noopener">like this one for example</a> . If its an internal API then contact API developer to get more details.
<ul>
 	<li><strong>URL and Parameters</strong>  (or sometimes referred as endpoint)</li>
 	<li><strong>Request Method</strong> (or sometimes referred as Verb)- e.g. GET, POST, PUT, PATCH .....</li>
 	<li><strong>HTTP Headers</strong></li>
 	<li><strong>Request Body</strong></li>
</ul>
<strong>Sample REST API Call</strong>

<strong>Request:</strong>
<pre class="lang:default decode:true">POST http://myhost/api/v2/customers/new
X-SecretKey: Abcdxxxxxxxxxxxxxx
Content-Type: application/json

{ firstname: "Someone", lastname: "Good" }</pre>
<strong>Response:</strong>
<pre class="lang:default highlight:0 decode:true">{
 request_status: "CreatedOK",
 new_customer_id: "1234566"
}</pre>
<h3>What is SOAP Web Service (XML API)</h3>
<a href="https://en.wikipedia.org/wiki/SOAP" target="_blank" rel="noopener">SOAP Web Service</a> is an old standard developed before REST Style got popular. SOAP is strictly XML based API on the other hand RESTful API can be any format. As we said earlier REST is an architecture style,  and SOAP is a standard (XML Based Protocol to transfer data).

For more information on SOAP API <a href="https://zappysys.com/blog/calling-soap-web-service-in-ssis-xml-source/" target="_blank" rel="noopener">refer to this link / videos</a>
<h3>Other Concepts Calling REST / SOAP</h3>
There are few things you have to find out from your API Provider (Read their documentation <a href="https://developer.zendesk.com/rest_api/docs/support/introduction" target="_blank" rel="noopener">like this for example</a>). Few important concepts for API calling listed below.
<ul>
 	<li><strong>Authentication</strong> - Most APIs need some sort of credentials to verify your identity. Here are some common Auth mechanism
<ul>
 	<li><a href="https://zappysys.com/blog/how-to-set-base64-encoded-authorization-header-for-http-web-request/">Basic Authentication</a>,</li>
 	<li><a href="https://zappysys.com/blog/rest-api-authentication-with-oauth-2-0-using-ssis/" target="_blank" rel="noopener">OAuth 1a or 2.0</a></li>
 	<li><a href="https://zappysys.com/blog/call-soap-rest-api-using-dynamic-token-ssis/" target="_blank" rel="noopener">Dynamic Token Auth </a></li>
 	<li>Pass API key via URL Parameter
e.g. <span class="lang:default decode:true  crayon-inline">http://myhost/api/v1/getcustomers?apikey=###some-secret-key####</span></li>
 	<li>Pass API key via Header</li>
</ul>
</li>
 	<li><strong>Pagination</strong> - Most APIs don't return huge amount of data in a single requests so you must call next request to continue fetch more data until all rows are fetched. There is no standard around pagination so find out from your API provider how to paginate. <a href="https://zappysys.com/blog/ssis-rest-api-looping-until-no-more-pages-found/" target="_blank" rel="noopener">Check this article for example</a> to learn about various pagination patterns.</li>
 	<li><strong>Throttling (API calls rate limit)</strong> - Most API providers enforce API call rate limit. Which means you cannot call it more than X times in a given time. If you ever face such issue, You can enable <a href="https://zappysys.com/blog/wp-content/uploads/2018/09/http-retry-settings-oauth-connection.png" target="_blank" rel="noopener">error retry option like this</a> or simply <a href="https://zappysys.com/blog/wp-content/uploads/2016/01/rest-api-limit-throttling-pause-request-per-seconds.png" target="_blank" rel="noopener">add delay like this</a> to slow down.</li>
</ul>
<h3>Must have Tools for API Testing / Debugging</h3>
Before you start integrating API calls in ZappySys products like <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ODBC PowerPack</a> or <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">SSIS PowerPack</a> you can start testing API using tools like CURL, Postman or Fiddler.
<h4><strong>Fiddler</strong></h4>
Fiddler is the best API API debugger out there. It acts like a small Proxy server so you can see all Web requests on your system in a raw format. You can also use this tool to Test API requests (See Composer tab in Fiddler) however if API testing is your primary use case then use POSTMAN (see next) because it has more UI elements compared to Fiddler. Here is <a href="https://zappysys.com/blog/how-to-use-fiddler-to-analyze-http-web-requests/">small tutorial to get started with Fiddler</a>.
<h4><strong>Postman</strong></h4>
<a href="https://www.getpostman.com/" target="_blank" rel="noopener">Postman</a> is probably the most popular tool to test API with full User interface. It's not data processing like ZappySys but you can pass various parts of API we talked earlier and test API before you can start using ZappySys for Data integration. Here is <a href="https://www.youtube.com/watch?v=t5n07Ybz7yI">Video Tutorial to get started with Postman</a>.
<h4><strong>cURL</strong></h4>
<a href="https://curl.haxx.se/">CURL</a> is a simple yet most popular command line tool to call / test APIs. It doesn't have UI elements like previous two tools so have to learn about each options you can pass to this command line.</div>
<h2>Step-By-Step: How to Import Bing Ads Data into SQL Server</h2>
<p>Now let&#8217;s look at how to import Bing Ads Data into SQL Server Table. This tutorial will require 10-15 mins of your time. At the end of this tutorial you will be able to Read Bing Ads Performance Report and Import data into SQL Server. Step listed in this tutorial may help you to call Bing API in other tools like <a href="https://zappysys.com/blog/call-rest-api-using-ssis-web-service-task/">SSIS</a>, <a href="https://zappysys.com/blog/call-soap-api-power-bi-read-xml-web-service-data/">Power BI</a>, SSRS, Tableau and so on.</p>
<p>So let&#8217;s get started.</p>
<h3>Register OAuth App for Bing Ads API (Azure Active Directory App)</h3>
<p>Very first thing to call any Bing API is to register OAuth App (Under Azure Active Directory Tab).</p>
<p>Here is how to register OAuth App which can be used to call Bing Ads API later on.</p>
<ol>
<li>
    <strong>Login to Azure Portal:</strong></p>
<ul>
<li>Navigate to the <a href="https://portal.azure.com/#home" target="_blank" rel="noopener"><strong>Azure Portal</strong></a> and log in using your credentials.</li>
</ul>
</li>
<li>
    <strong>Access Azure Active Directory:</strong></p>
<ul>
<li>In the left-hand menu, click on <a target="_blank" href="https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/Overview" rel="noopener"><strong>Azure Active Directory</strong></a>.</li>
</ul>
</li>
<li>
    <strong>Register a New Application:</strong></p>
<ul>
<li>Go to <a target="_blank" href="https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredApps" rel="noopener"><strong>App registrations</strong></a> and click on <strong>New registration</strong>.<br />
<a href="https://zappysys.com/blog/wp-content/uploads/2019/07/register-azure-active-directory-oauth-app.png"><img loading="lazy" decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2019/07/register-azure-active-directory-oauth-app.png" alt="" width="638" height="368" class="alignnone size-full wp-image-7344" srcset="https://zappysys.com/blog/wp-content/uploads/2019/07/register-azure-active-directory-oauth-app.png 638w, https://zappysys.com/blog/wp-content/uploads/2019/07/register-azure-active-directory-oauth-app-300x173.png 300w" sizes="(max-width: 638px) 100vw, 638px" /></a>
</li>
<li><strong>Application Name:</strong> Enter a name for your application.<br />
<a href="https://zappysys.com/blog/wp-content/uploads/2019/07/create-new-azure-oauth-app-select-type.png"><img loading="lazy" decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2019/07/create-new-azure-oauth-app-select-type.png" alt="" width="392" height="567" class="alignnone size-full wp-image-7345" srcset="https://zappysys.com/blog/wp-content/uploads/2019/07/create-new-azure-oauth-app-select-type.png 392w, https://zappysys.com/blog/wp-content/uploads/2019/07/create-new-azure-oauth-app-select-type-207x300.png 207w" sizes="(max-width: 392px) 100vw, 392px" /></a>
</li>
<li><strong>Supported Account Types:</strong> Choose the account types your app will support. For example, select <strong>Accounts in this organizational directory only</strong> if you need access to data in your organization only.</li>
<li><strong>Redirect URI:</strong>
<ul>
<li>Set the type to <strong>Web</strong>.</li>
<li>In the textbox enter <b>https://login.microsoftonline.com/common/oauth2/nativeclient</b> as the Redirect URI or any other valid redirect URL, e.g., <b>https://zappysys.com/oauth</b>.</li>
<li>Use this Redirect URI in the <strong>Redirect URL</strong> grid row.</li>
</ul>
</li>
</ul>
</li>
<li>
    <strong>Save Client ID:</strong></p>
<ul>
<li>After registering the app, copy the <strong>Application (client) ID</strong> and paste it into the <strong>Client ID</strong> field in the API Connection Manager configuration.</li>
</ul>
</li>
<li>
    <strong>Set Authorization &amp; Token URLs:</strong></p>
<ul>
<li>Click on the <strong>Endpoints</strong> link in the App registration overview.</li>
<li><strong>Authorization URL:</strong> Copy the <strong>OAuth 2.0 authorization endpoint (v2)</strong> URL (e.g., <code>https://login.microsoftonline.com/{your-tenant-id}/oauth2/v2.0/authorize</code>) and paste it into the <strong>Authorization URL</strong> field in the configuration grid.</li>
<li><strong>Token URL:</strong> Copy the <strong>OAuth 2.0 token endpoint (v2)</strong> URL (e.g., <code>https://login.microsoftonline.com/{your-tenant-id}/oauth2/v2.0/token</code>) and paste it into the <strong>Token URL</strong> field.</li>
</ul>
</li>
<li>
    <strong>Create a Client Secret:</strong></p>
<ul>
<li>In the <strong>Certificates &amp; secrets</strong> tab, click <strong>New client secret</strong>.</li>
<li>Set an expiration period for the secret.</li>
<li>Copy the generated client secret and paste it into the <strong>Client Secret</strong> field in the API Connection Manager configuration.</li>
</ul>
</li>
<li>
    <strong>Configure API Permissions:</strong></p>
<ul>
<li>Go to the <strong>API Permissions</strong> section.</li>
<li>Click on <strong>Add a permission</strong>, select <strong>Microsoft Graph</strong>, and choose <strong>Delegated Permissions</strong>.</li>
<li>Add the required permissions:
<ul>
<li>offline_access</li>
<li>openid</li>
<li>profile</li>
<li>Sites.Read.All</li>
<li>Sites.ReadWrite.All</li>
<li>User.Read</li>
<li>email</li>
</ul>
<div id="attachment_11177" style="width: 903px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/06/azure-ad-app-required-app-permissions.jpg"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-11177" src="https://zappysys.com/blog/wp-content/uploads/2019/06/azure-ad-app-required-app-permissions.jpg" alt="azure-ad-app-required-app-permissions" width="893" height="681" class="size-full wp-image-11177" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/azure-ad-app-required-app-permissions.jpg 893w, https://zappysys.com/blog/wp-content/uploads/2019/06/azure-ad-app-required-app-permissions-300x229.jpg 300w, https://zappysys.com/blog/wp-content/uploads/2019/06/azure-ad-app-required-app-permissions-768x586.jpg 768w" sizes="(max-width: 893px) 100vw, 893px" /></a><p id="caption-attachment-11177" class="wp-caption-text">Azure AD App &#8211; Required API Permissions</p></div>
      </li>
<li><strong>Grant Admin Consent</strong> for the permissions that require it.</li>
</ul>
</li>
<li>
    <strong>Generate Tokens:</strong></p>
<ul>
<li>Use the <strong>Generate Token</strong> feature in the API Connection Manager to generate authentication tokens.</li>
</ul>
</li>
<li>
    <strong>Use a Generic Account for Automation:</strong></p>
<div style="background-color: #f5f2c4; border-style: solid; border-color: #000000; border-width: 1px; margin-top: 3px; margin-bottom: 6px; padding: 6px;">
		<b>NOTE</b>: If you are planning to use your current data connection/token for automated processes, we recommend that you use a generic account for token generation when the login box appears (e.g. sales_automation@mycompany.com instead of bob_smith@mycompany.com). When you use a personal account which is tied to a specific employee profile and that employee leaves the company, the token may become invalid and any automated processes using that token will fail. Another potentially unwanted effect of using a personal token is incorrect logging; the API calls (e.g. Read, Edit, Delete, Upload) made with that token will record the specific user as performing the calls instead of an automated process.
    </div>
</li>
<li>That&#8217;s it!</li>
</ol>
<h3>Get Bing API Developer Token</h3>
<p>Once we have OAuth App registered next thing is to obtain Developer Token for Bing Ads API. <a href="https://developers.ads.microsoft.com/Account" target="_blank" rel="noopener">Click here to request new token</a> or view existing Developer token.</p>
<div class="content_block" id="custom_post_widget-5411"><h3><span style="font-size: 14pt;">Configure ZappySys Data Gateway</span></h3>
Now let's look at steps to configure Data Gateway after installation.
<ol style="margin-left: 0;">
 	<li style="text-align: left;">Assuming you have installed <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> using default options (Which also enables Data Gateway Service)</li>
 	<li style="text-align: left;">Search "Gateway" in your start menu and click ZappySys Data Gateway
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png" alt="Open ZappySys Data Gateway" /></a>
<p class="wp-caption-text">Opening ZappySys Data Gateway</p>

</div></li>
 	<li>First, make sure Gateway Service is running (Verify Start icon is disabled)</li>
 	<li>Also, verify Port on General Tab
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/03/ZappySys-data-gateway-port-5000.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/03/ZappySys-data-gateway-port-5000.png" alt="Port Number setting on ZappySys Data Gateway" /></a>
<p class="wp-caption-text">Checking port number setting on ZappySys Data Gateway</p>

</div></li>
 	<li>Now go to Users tab. <strong>Click Add</strong> icon to add a new user. Check Is admin to give access to all data sources you add in future. If you don't check admin then you have to manually configure user permission for each data source.
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-user.png">
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-5453" src="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-configure-add-user.png" alt="" width="564" height="438" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-configure-add-user.png 564w, https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-configure-add-user-300x233.png 300w" sizes="(max-width: 564px) 100vw, 564px" /></a>
<p class="wp-caption-text">Adding the Gateway user</p>

</div></li>
</ol>
&nbsp;</div>
<h3>Create new Bing Ads API Data Source in Gateway</h3>
<p>Once you setup Data Gateway user we can move to next step. To call Bing API we need to setup Connection for XML Driver in ZappySys Data Gateway.</p>
<ol>
<li>Click on Add New Data source. Name as <strong>BingAds</strong> and select <a href="https://zappysys.com/products/odbc-powerpack/odbc-xml-soap-api-driver/" target="_blank" rel="noopener"><strong>Native &#8211; ZappySys XML Driver</strong></a> option.
<div id="attachment_5557" style="width: 572px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc_json_driver_add_native_driver.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5557" class="size-full wp-image-5557" src="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc_json_driver_add_native_driver.png" alt="Add Gateway Data Source" width="562" height="539" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc_json_driver_add_native_driver.png 562w, https://zappysys.com/blog/wp-content/uploads/2018/11/odbc_json_driver_add_native_driver-300x288.png 300w" sizes="(max-width: 562px) 100vw, 562px" /></a><p id="caption-attachment-5557" class="wp-caption-text">Add Gateway Data Source</p></div></li>
<li>Now click Edit to Configure Settings. For now we will only care OAuth Connection settings. All other options are overwritten in SQL Query.
<div id="attachment_5440" style="width: 572px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-2-2.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5440" class="size-full wp-image-5440" src="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-2-2.png" alt="Edit Gateway Data Source Settings" width="562" height="385" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-2-2.png 562w, https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-2-2-300x206.png 300w" sizes="(max-width: 562px) 100vw, 562px" /></a><p id="caption-attachment-5440" class="wp-caption-text">Edit Gateway Data Source Settings</p></div></li>
<li>When UI opens Click on Load ConnectionString and Paste below connection string after changing some items (<strong>Screenshot may be differ</strong>). Make sure to replace following attributes.<strong>RefreshTokenFilePath</strong> &#8211; Enter some valid file path which will hold refresh token<br />
<strong>ClientId</strong> &#8211; get Application Id from Azure Portal under App we created earlier)<br />
<strong>DeveloperToken</strong> &#8211; Replace 1052Bxxxxxxxxxxxx with your own devloper token.</p>
<div id="attachment_7024" style="width: 996px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/05/zappysys-driver-load-connectionstring.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7024" class="size-full wp-image-7024" src="https://zappysys.com/blog/wp-content/uploads/2019/05/zappysys-driver-load-connectionstring.png" alt="Load ZappySys Driver ConnectionString to configure UI" width="986" height="454" srcset="https://zappysys.com/blog/wp-content/uploads/2019/05/zappysys-driver-load-connectionstring.png 986w, https://zappysys.com/blog/wp-content/uploads/2019/05/zappysys-driver-load-connectionstring-300x138.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/05/zappysys-driver-load-connectionstring-768x354.png 768w" sizes="(max-width: 986px) 100vw, 986px" /></a><p id="caption-attachment-7024" class="wp-caption-text">Load ZappySys Driver ConnectionString to configure UI</p></div>
<p><strong>Use below string and replace parameters </strong></p><pre class="crayon-plain-tag">DRIVER={ZappySys XML Driver};
DataPath='https://clientcenter.api.bingads.microsoft.com/Api/CustomerManagement/v13/CustomerManagementService.svc';
DataConnectionType=OAuth;
AuthUrl='https://login.microsoftonline.com/common/oauth2/v2.0/authorize';
TokenUrl='https://login.microsoftonline.com/common/oauth2/v2.0/token';
ReturnUrl='https://login.microsoftonline.com/common/oauth2/nativeclient';
RefreshTokenFilePath='c:\xxxxxx_some_folder_xxxxxxx\BingAds_RefreshToken.txt';
ScopeSeparator='{space}';
Scope='https://ads.microsoft.com/ads.manage offline_access';
ClientId='xxxxxxxxxxxxxx';
UseCustomApp=True;
RequestData='&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;s:Header&gt;
    &lt;h:ApplicationToken i:nil="true" xmlns:h="https://bingads.microsoft.com/Customer/v13" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" /&gt;
    &lt;h:AuthenticationToken xmlns:h="https://bingads.microsoft.com/Customer/v13"&gt;&lt;%access_token%&gt;&lt;/h:AuthenticationToken&gt;
    &lt;h:DeveloperToken xmlns:h="https://bingads.microsoft.com/Customer/v13"&gt;1052Bxxxxxxxxxxxx&lt;/h:DeveloperToken&gt;
    &lt;h:Password i:nil="true" xmlns:h="https://bingads.microsoft.com/Customer/v13" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" /&gt;
    &lt;h:UserName i:nil="true" xmlns:h="https://bingads.microsoft.com/Customer/v13" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" /&gt;
  &lt;/s:Header&gt;
  &lt;s:Body&gt;
    &lt;GetUserRequest xmlns="https://bingads.microsoft.com/Customer/v13"&gt;
      &lt;UserId i:nil="true" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" /&gt;
    &lt;/GetUserRequest&gt;
  &lt;/s:Body&gt;
&lt;/s:Envelope&gt;';
RequestContentTypeCode=TextXml;
RequestMethod='POST';
RequestHeaders='SOAPAction: "GetUser"'</pre><p>
</li>
<li>Next to <strong>OAuth</strong> Click on <strong>Configure Settings</strong></li>
<li>By default most of settings on OAuth connections should be pre-populated for you but still lets Notice few things. This is how to setup redirect URI</li>
<li>
<div id="attachment_7360" style="width: 1027px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/06/configure-oauth-redirect-url-azure-active-directory-oauth-app.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7360" class="size-full wp-image-7360" src="https://zappysys.com/blog/wp-content/uploads/2019/06/configure-oauth-redirect-url-azure-active-directory-oauth-app.png" alt="Configure Redirect URI for Bing Ads API OAuth Connection" width="1017" height="486" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/configure-oauth-redirect-url-azure-active-directory-oauth-app.png 1017w, https://zappysys.com/blog/wp-content/uploads/2019/06/configure-oauth-redirect-url-azure-active-directory-oauth-app-300x143.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/06/configure-oauth-redirect-url-azure-active-directory-oauth-app-768x367.png 768w" sizes="(max-width: 1017px) 100vw, 1017px" /></a><p id="caption-attachment-7360" class="wp-caption-text">Configure Redirect URI for Bing Ads API OAuth Connection</p></div></li>
<li>Here is where you setup <a href="https://zappysys.zendesk.com/hc/en-us/articles/115004555334-How-to-handle-Changing-OAuth-RefreshToken-in-SSIS-ODBC-" target="_blank" rel="noopener">Changing Refresh Token File path</a>. if you dont supply this path then your refresh token extracted first time will expire in 60 days.
<div id="attachment_7361" style="width: 609px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/06/handle-oauth-changing-refresh-token.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7361" class="size-full wp-image-7361" src="https://zappysys.com/blog/wp-content/uploads/2019/06/handle-oauth-changing-refresh-token.png" alt="Refresh Token File path (Only needed if API issues new Refresh Token when you request AccessToken)" width="599" height="355" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/handle-oauth-changing-refresh-token.png 599w, https://zappysys.com/blog/wp-content/uploads/2019/06/handle-oauth-changing-refresh-token-300x178.png 300w" sizes="(max-width: 599px) 100vw, 599px" /></a><p id="caption-attachment-7361" class="wp-caption-text">Refresh Token File path (Only needed if API issues new Refresh Token when you request AccessToken)</p></div></li>
<li>Once you verify all settings <strong>click</strong> <strong>Generate Token</strong> and Finish the process. It will populate <strong>AccessToken</strong> and <strong>RefreshToken</strong> Fields if everything goes well.
<div id="attachment_7359" style="width: 1054px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/06/configure-zppysys-bing-ads-driver-oauth-connection.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7359" class="size-full wp-image-7359" src="https://zappysys.com/blog/wp-content/uploads/2019/06/configure-zppysys-bing-ads-driver-oauth-connection.png" alt="Configure Bing Ads API Connection (OAuth 2.0)" width="1044" height="605" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/configure-zppysys-bing-ads-driver-oauth-connection.png 1044w, https://zappysys.com/blog/wp-content/uploads/2019/06/configure-zppysys-bing-ads-driver-oauth-connection-300x174.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/06/configure-zppysys-bing-ads-driver-oauth-connection-768x445.png 768w, https://zappysys.com/blog/wp-content/uploads/2019/06/configure-zppysys-bing-ads-driver-oauth-connection-1024x593.png 1024w" sizes="(max-width: 1044px) 100vw, 1044px" /></a><p id="caption-attachment-7359" class="wp-caption-text">Configure Bing Ads API Connection (OAuth 2.0)</p></div></li>
<li>Click OK to save OAuth Connection UI to go back to main UI</li>
<li>You can now <strong>Click Test Connection</strong> to confirm everything</li>
<li>If you need to access Gateway from Other machine then go to <strong>Firewall tab</strong> and Click Add Rule</li>
<li><strong>Click Save</strong> button <strong>on Gateway UI</strong> to save and restart the service.</li>
</ol>
<h3>Create a new Linked Server for Bing Ads API</h3>
<p>Once we setup setup Bing Ads Data Source in Gateway we can move to next step which is create a Linked Server which points to Data gateway Data source we created. This will create a bridge between ZappySys Driver and SQL Server so you can call API via T-SQL.</p>
<ol>
<li>If you are using Latest ODBC PowerPack then on Data gateway UI you will See <strong>App Integration Tab</strong>. Copy Code and run it in SSMS to create a new linked server.
<div id="attachment_7366" style="width: 774px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/06/data-gateway-code-generator-sql-linked-server.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7366" class="size-full wp-image-7366" src="https://zappysys.com/blog/wp-content/uploads/2019/06/data-gateway-code-generator-sql-linked-server.png" alt="ZappySys Data Gateway code generator for Linked Server" width="764" height="702" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/data-gateway-code-generator-sql-linked-server.png 764w, https://zappysys.com/blog/wp-content/uploads/2019/06/data-gateway-code-generator-sql-linked-server-300x276.png 300w" sizes="(max-width: 764px) 100vw, 764px" /></a><p id="caption-attachment-7366" class="wp-caption-text">ZappySys Data Gateway code generator for Linked Server</p></div></li>
<li>If things go well when you execute code you may see some result in grid.</li>
</ol>
<h3>Run sample Queries to call Bing API in SQL Server / Import Data</h3>
<p>Once Linked Server is created we can run various queries like below.</p>
<p><strong>Example-1</strong></p><pre class="crayon-plain-tag">--use all default settings from gateway data source UI
--Read
Select * from OPENQUERY( [YourLinkedServer] , 'select * from $')&amp;nbsp;

/*
--import
Select * into #tempTable from OPENQUERY( [YourLinkedServer] , 'select * from $') 
Select * from #tempTable
*/</pre><p>
<strong>Example-2</strong></p><pre class="crayon-plain-tag">--use Filter to extract specific Node from response XML
Select * from OPENQUERY( [YourLinkedServer] , 
'select * from $
WITH(Filter=''$.s:Envelope.s:Body.GetUserRequest[*]'', 
  ElementsToTreatAsArray=''GetUserResponse'' 
   )'
)</pre><p>
&nbsp;</p>
<p><strong>Example-3</strong></p><pre class="crayon-plain-tag">--Override URL, Headers and Body Settings. Change DeveloperToken in below request
--Header, Filter, URL, Request data is different for each Endpoint

SELECT * FROM OPENQUERY([YourLinkedServer]
, 'SELECT * FROM $
WITH(
	 ElementsToTreatAsArray=''GetUserResponse''
	,Src=''https://clientcenter.api.bingads.microsoft.com/Api/CustomerManagement/v13/CustomerManagementService.svc''
	,Filter=''$.s:Envelope.s:Body.GetUserResponse[*]''	
	,Header=''SOAPAction: "GetUser"''	
	,RequestData=''&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v13="https://bingads.microsoft.com/Customer/v13"&gt;
&lt;soapenv:Header&gt;
   &lt;v13:DeveloperToken&gt;1052xxxxxxxxxxxxx&lt;/v13:DeveloperToken&gt;
   &lt;v13:AuthenticationToken&gt;&lt;%access_token%&gt;&lt;/v13:AuthenticationToken&gt;
&lt;/soapenv:Header&gt;
&lt;soapenv:Body&gt;
   &lt;v13:GetUserRequest&gt;
      &lt;v13:UserId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/&gt;
   &lt;/v13:GetUserRequest&gt;
&lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;''
)')</pre><p>
&nbsp;</p>
<h3>Download Bing Ads Performance Data in SQL Server Table</h3>
<p>Now lets look at more complex example to read data from Bing Performance Report. Calling This API is tricky due to many steps involved in data extraction. But not to worry if you use ZappySys Drivers. This is API is somewhat similar as <a href="https://zappysys.com/blog/import-amazon-mws-data-sql-server-t-sql/" target="_blank" rel="noopener">Amazon MWS Report Request (See last section)</a>.</p>
<p>Here are high level steps needs to be performed to call API for Bing Ads Report (e.g. Performance Report)</p>
<ol>
<li>Call <a href="https://docs.microsoft.com/en-us/advertising/reporting-service/submitgeneratereport?view=bingads-13" target="_blank" rel="noopener">SubmitGenerateReportResponse</a> API to request new Report. This returns ReportRequestId</li>
<li>Now we have to keep checking every few seconds see report is ready or not. Call <a href="https://docs.microsoft.com/en-us/advertising/reporting-service/pollgeneratereport?view=bingads-13" target="_blank" rel="noopener">PollGenerateReport</a> until Status field is Success from Pending</li>
<li>Once previous step returns Success extract Report Download URL (Its Zip File which may contain data in CSV or XML)</li>
</ol>
<p>So lets get started to implement above login in a single T-SQL Query and load data into Table. There is a known limitation with Query Size we can send to data gateway from SSMS so we can use some tricks to read Body from File rather than hard coding in SQL. We can use IsMultiPart=True and then supply Filepath in RequestBody (Path must start with @ symbol)</p>
<ol>
<li>Bing Report API needs 2 additional values along with DeveloperToken we got earlier. You need to supply <strong>AccountId</strong> and <strong>CustomerId</strong> part of Body so obtain it by visiting below page in your bing account.<br />
Visit <a href="https://ads.microsoft.com/cc/accounts" target="_blank" rel="noopener">https://ads.microsoft.com/cc/accounts</a></p>
<div id="attachment_7362" style="width: 666px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/06/how-to-get-bing-ads-accountid-customerid.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7362" class="size-full wp-image-7362" src="https://zappysys.com/blog/wp-content/uploads/2019/06/how-to-get-bing-ads-accountid-customerid.png" alt="Obtain Bing Ads AccountId, ClientId for APi calls" width="656" height="556" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/how-to-get-bing-ads-accountid-customerid.png 656w, https://zappysys.com/blog/wp-content/uploads/2019/06/how-to-get-bing-ads-accountid-customerid-300x254.png 300w" sizes="(max-width: 656px) 100vw, 656px" /></a><p id="caption-attachment-7362" class="wp-caption-text">Obtain Bing Ads AccountId, ClientId for APi calls</p></div></li>
<li>Create new XML file for first step in a Notepad. Enter below content and save as <strong>C:\Requests\BingAds\sql_body1.xml</strong><br />
Replace Following Values as per your settingsCustomerAccountId (Found 2 places)<br />
CustomerId<br />
DeveloperToken<br />
<pre class="crayon-plain-tag">&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;s:Header&gt;
    &lt;h:ApplicationToken i:nil="true" xmlns:h="https://bingads.microsoft.com/Reporting/v13" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" /&gt;
    &lt;h:AuthenticationToken xmlns:h="https://bingads.microsoft.com/Reporting/v13"&gt;&lt;%access_token%&gt;&lt;/h:AuthenticationToken&gt;
    &lt;h:CustomerAccountId xmlns:h="https://bingads.microsoft.com/Reporting/v13"&gt;481xxxxxxxxxxx&lt;/h:CustomerAccountId&gt;
    &lt;h:CustomerId xmlns:h="https://bingads.microsoft.com/Reporting/v13"&gt;191xxxxxxxxxxx&lt;/h:CustomerId&gt;
    &lt;h:DeveloperToken xmlns:h="https://bingads.microsoft.com/Reporting/v13"&gt;1052Bxxxxxxxxxxx&lt;/h:DeveloperToken&gt;
    &lt;h:Password i:nil="true" xmlns:h="https://bingads.microsoft.com/Reporting/v13" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" /&gt;
    &lt;h:UserName i:nil="true" xmlns:h="https://bingads.microsoft.com/Reporting/v13" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" /&gt;
  &lt;/s:Header&gt;
  &lt;s:Body&gt;
    &lt;SubmitGenerateReportRequest xmlns="https://bingads.microsoft.com/Reporting/v13"&gt;
      &lt;ReportRequest i:type="CampaignPerformanceReportRequest" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
        &lt;ExcludeColumnHeaders&gt;false&lt;/ExcludeColumnHeaders&gt;
        &lt;ExcludeReportFooter&gt;false&lt;/ExcludeReportFooter&gt;
        &lt;ExcludeReportHeader&gt;false&lt;/ExcludeReportHeader&gt;
        &lt;Format&gt;Xml&lt;/Format&gt;
        &lt;ReportName&gt;My Campaign Performance Report&lt;/ReportName&gt;
        &lt;ReturnOnlyCompleteData&gt;false&lt;/ReturnOnlyCompleteData&gt;
        &lt;Aggregation&gt;Hourly&lt;/Aggregation&gt;
        &lt;Columns&gt;
          &lt;CampaignPerformanceReportColumn&gt;TimePeriod&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;AccountId&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;CampaignId&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;CampaignName&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;CampaignStatus&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;DeviceType&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;BidMatchType&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;QualityScore&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;AdRelevance&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;LandingPageExperience&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;Revenue&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;Assists&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;ExpectedCtr&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;DeliveredMatchType&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;AveragePosition&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;Conversions&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;AdDistribution&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;Network&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;Clicks&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;Impressions&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;Ctr&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;AverageCpc&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;Spend&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;LowQualityClicks&lt;/CampaignPerformanceReportColumn&gt;
          &lt;CampaignPerformanceReportColumn&gt;LowQualityConversionRate&lt;/CampaignPerformanceReportColumn&gt;
        &lt;/Columns&gt;
        &lt;Filter&gt;
          &lt;AccountStatus i:nil="true" /&gt;
          &lt;AdDistribution i:nil="true" /&gt;
          &lt;DeviceOS i:nil="true" /&gt;
          &lt;DeviceType i:nil="true" /&gt;
          &lt;Status i:nil="true" /&gt;
        &lt;/Filter&gt;
        &lt;Scope&gt;
          &lt;AccountIds xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"&gt;
            &lt;a:long&gt;481xxxxxxxxxxx&lt;/a:long&gt;
          &lt;/AccountIds&gt;
          &lt;Campaigns i:nil="true" /&gt;
        &lt;/Scope&gt;
        &lt;Time&gt;
          &lt;CustomDateRangeEnd i:nil="true" /&gt;
          &lt;CustomDateRangeStart i:nil="true" /&gt;
          &lt;PredefinedTime&gt;Yesterday&lt;/PredefinedTime&gt;
          &lt;ReportTimeZone&gt;PacificTimeUSCanadaTijuana&lt;/ReportTimeZone&gt;
        &lt;/Time&gt;
      &lt;/ReportRequest&gt;
    &lt;/SubmitGenerateReportRequest&gt;
  &lt;/s:Body&gt;
&lt;/s:Envelope&gt;</pre>
&nbsp;</li>
<li>Create another XML file for second step in a Notepad. Enter below content and save as <strong>C:\Requests\BingAds\sql_body2.xml</strong><br />
Replace following values as per your need.<br />
<pre class="crayon-plain-tag">&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;s:Header&gt;
    &lt;h:ApplicationToken i:nil="true" xmlns:h="https://bingads.microsoft.com/Reporting/v13" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" /&gt;
    &lt;h:AuthenticationToken xmlns:h="https://bingads.microsoft.com/Reporting/v13"&gt;&lt;%access_token%&gt;&lt;/h:AuthenticationToken&gt;
    &lt;h:CustomerAccountId xmlns:h="https://bingads.microsoft.com/Reporting/v13"&gt;480xxxxxxxxxxx&lt;/h:CustomerAccountId&gt;
    &lt;h:CustomerId xmlns:h="https://bingads.microsoft.com/Reporting/v13"&gt;191xxxxxxxxxxx&lt;/h:CustomerId&gt;
    &lt;h:DeveloperToken xmlns:h="https://bingads.microsoft.com/Reporting/v13"&gt;1052Bxxxxxxxxxxx&lt;/h:DeveloperToken&gt;
    &lt;h:Password i:nil="true" xmlns:h="https://bingads.microsoft.com/Reporting/v13" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" /&gt;
    &lt;h:UserName i:nil="true" xmlns:h="https://bingads.microsoft.com/Reporting/v13" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" /&gt;
  &lt;/s:Header&gt;
  &lt;s:Body&gt;
    &lt;PollGenerateReportRequest xmlns="https://bingads.microsoft.com/Reporting/v13"&gt;
      &lt;ReportRequestId&gt;[$a.ReportRequestId$]&lt;/ReportRequestId&gt;
    &lt;/PollGenerateReportRequest&gt;
  &lt;/s:Body&gt;
&lt;/s:Envelope&gt;</pre>
&nbsp;</li>
<li>Now try to execute below query. This should generate Performance report and download it in a SQL table for you.<br />
<pre class="crayon-plain-tag">select * into tmpBingAdsReport from OPENQUERY(Zs_BingAds,
'SELECT c.* FROM $
WITH(
	--submit report request for XML format

	 alias=''a'' 
	,Src=''https://reporting.api.bingads.microsoft.com/Api/Advertiser/Reporting/v13/ReportingService.svc''
	,Filter=''$.s:Envelope.s:Body.SubmitGenerateReportResponse''
	,RequestData=''@C:\Requests\BingAds\sql_body1.xml''
	,IsMultiPart=''True''
	,RequestContentTypeCode=''TextXml''
	,Header=''SOAPAction: "SubmitGenerateReport"''
	,RequestMethod=''POST''
	,EnableBodyPlaceholderForMultiPart=''True''
	,Meta=''[{"Name": "ReportRequestId","Type": "Int64"}]''

	--keep checking status until report is ready - returns final url when done

	,join1_alias=''b''
	,join1_Filter=''$.s:Envelope.s:Body.PollGenerateReportResponse.ReportRequestStatus''
	,join1_RequestData=''@C:\Requests\BingAds\sql_body2.xml''
	,join1_IsMultiPart=''True''
	,join1_Src=''https://reporting.api.bingads.microsoft.com/Api/Advertiser/Reporting/v13/ReportingService.svc''
	,join1_RequestContentTypeCode=''TextXml''
	,join1_Header=''SOAPAction: "PollGenerateReport"''
	,join1_RequestMethod=''POST''
	,join1_EnableBodyPlaceholderForMultiPart=''True''
	,join1_EnableStatusCheck=''True'', 
	,join1_StatucCheckMaxWaitSeconds=300, --wait max 5 mins?
	,join1_StatucCheckIterationWaitSeconds=5, --check every 5 sec?
	,join1_StatusSuccessValue=''Success'', --look for success word in response

	--Download report (Zip file) and Parse rows

	,join2_alias=''c''
	,join2_DataConnectionType=''Default''
	,join2_Src=''[$b.ReportDownloadUrl$]''
	,join2_Filter=''$.Report.Table.Row[*]''
	,join2_ElementsToTreatAsArray=''Row''	
	,join2_RequestMethod=''GET''
	,join2_IsMultiPart=''False''
	,join2_FileCompressionType=''Zip''	
)')

select * from tmpBingAdsReport</pre>
<div id="attachment_7218" style="width: 841px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/06/import-bing-ads-data-into-sql-server-table.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7218" class="size-full wp-image-7218" src="https://zappysys.com/blog/wp-content/uploads/2019/06/import-bing-ads-data-into-sql-server-table.png" alt="" width="831" height="741" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/import-bing-ads-data-into-sql-server-table.png 831w, https://zappysys.com/blog/wp-content/uploads/2019/06/import-bing-ads-data-into-sql-server-table-300x268.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/06/import-bing-ads-data-into-sql-server-table-768x685.png 768w" sizes="(max-width: 831px) 100vw, 831px" /></a><p id="caption-attachment-7218" class="wp-caption-text">Import Bing Ads data into SQL Server</p></div></li>
</ol>
<h2>Multi Step Query to download Report</h2>
<p>So in previous section we saw how to write a single query to get your Performance Report from Bing Ads. However there will be time you want to split 3 steps into seperate queries.</p>
<p>Here is how to do.</p><pre class="crayon-plain-tag">/*
RPC and RPC OUT options must be turned on to run this proc

EXEC master.dbo.sp_serveroption @server=N'Zs_BingAds', @optname=N'rpc', @optvalue=N'true'
EXEC master.dbo.sp_serveroption @server=N'Zs_BingAds', @optname=N'rpc out', @optvalue=N'true'
--Below needed to support EXEC + INSERT (dynamic query)
EXEC master.dbo.sp_serveroption @server=N'Zs_BingAds, @optname=N'remote proc transaction promotion', @optvalue=N'false'
Also 
1. Change Body file path
2. Change CustomerAccountId, CustomerId, DeveloperToken
*/

ALTER proc usp_Api_BingAds_Reports
as
--///////////////////////////////////////////////////////////////////////////////
--Step-1 - submit report request for XML format
--///////////////////////////////////////////////////////////////////////////////
create table #tmpBingAdsReport_Step1(ReportRequestId bigint)
INSERT into #tmpBingAdsReport_Step1
EXEC(
'SELECT * FROM $
WITH(
 Src=''https://reporting.api.bingads.microsoft.com/Api/Advertiser/Reporting/v13/ReportingService.svc''
,Filter=''$.s:Envelope.s:Body.SubmitGenerateReportResponse''
,RequestData=''@c:\BWProjects\Requests\BingAds\sql_body1.xml''
,IsMultiPart=''True''
,RequestContentTypeCode=''TextXml''
,Header=''SOAPAction: "SubmitGenerateReport"''
,RequestMethod=''POST''
,EnableBodyPlaceholderForMultiPart=''True''
,Meta=''[{"Name": "ReportRequestId","Type": "Int64"}]''
)') AT zs_BingAds


--///////////////////////////////////////////////////////////////////////////////
--Step2 - keep checking status until report is ready - returns final url when done
--///////////////////////////////////////////////////////////////////////////////

declare @reportid varchar(100)
select top 1 @reportid=cast(ReportRequestId as varchar(100)) from #tmpBingAdsReport_Step1

create table #tmpBingAdsReport_Step2(ReportDownloadUrl varchar(500))
INSERT into #tmpBingAdsReport_Step2 
EXEC(
'SELECT * FROM $
WITH(
 Filter=''$.s:Envelope.s:Body.PollGenerateReportResponse.ReportRequestStatus''
,RequestData=''&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
  &lt;s:Header&gt;
    &lt;h:ApplicationToken i:nil="true" xmlns:h="https://bingads.microsoft.com/Reporting/v13" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" /&gt;
    &lt;h:AuthenticationToken xmlns:h="https://bingads.microsoft.com/Reporting/v13"&gt;&lt;%access_token%&gt;&lt;/h:AuthenticationToken&gt;
    &lt;h:CustomerAccountId xmlns:h="https://bingads.microsoft.com/Reporting/v13"&gt;480xxxxxxxxx&lt;/h:CustomerAccountId&gt;
    &lt;h:CustomerId xmlns:h="https://bingads.microsoft.com/Reporting/v13"&gt;191xxxxxxxxx&lt;/h:CustomerId&gt;
    &lt;h:DeveloperToken xmlns:h="https://bingads.microsoft.com/Reporting/v13"&gt;105xxxxxxxxxxx&lt;/h:DeveloperToken&gt;
    &lt;h:Password i:nil="true" xmlns:h="https://bingads.microsoft.com/Reporting/v13" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" /&gt;
    &lt;h:UserName i:nil="true" xmlns:h="https://bingads.microsoft.com/Reporting/v13" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" /&gt;
  &lt;/s:Header&gt;
  &lt;s:Body&gt;
    &lt;PollGenerateReportRequest xmlns="https://bingads.microsoft.com/Reporting/v13"&gt;
      &lt;ReportRequestId&gt;'+ @reportid +'&lt;/ReportRequestId&gt;
    &lt;/PollGenerateReportRequest&gt;
  &lt;/s:Body&gt;
&lt;/s:Envelope&gt;''
--,IsMultiPart=''True''
,Src=''https://reporting.api.bingads.microsoft.com/Api/Advertiser/Reporting/v13/ReportingService.svc''
,RequestContentTypeCode=''TextXml''
,Header=''SOAPAction: "PollGenerateReport"''
,RequestMethod=''POST''
--,EnableBodyPlaceholderForMultiPart=''True''
,EnableStatusCheck=''True'', 
,StatucCheckMaxWaitSeconds=300, --wait max 5 mins?
,StatucCheckIterationWaitSeconds=5, --check every 5 sec?
,StatusSuccessValue=''Success'', --look for success word in response
,Meta=''[{"Name": "ReportDownloadUrl","Type": "String",Length:"300"}]''
)') AT zs_BingAds


declare @reportpath varchar(500)
select top 1 @reportpath=ReportDownloadUrl from #tmpBingAdsReport_Step2

select * from #tmpBingAdsReport_Step1
select * from #tmpBingAdsReport_Step2

--///////////////////////////////////////////////////////////////////////////////
--Step-3 - Get report file
--///////////////////////////////////////////////////////////////////////////////
--Static table
--//INSERT INTO BingAdsReport
EXEC(
'SELECT * FROM $
WITH(
 DataConnectionType=''Default''
,Src='''+ @reportpath +'''
,Filter=''$.Report.Table.Row[*]''
,ElementsToTreatAsArray=''Row''	
,RequestMethod=''GET''
,IsMultiPart=''False''
,FileCompressionType=''Zip''	
)') AT zs_BingAds


--select * from tmpBingAdsReport_Step3
--select * from openquery(Bing, 'select * from $')


/*
select * into tmpBingAdsReport from OPENQUERY(zs_BingAds,
'SELECT c.* FROM $
WITH(
--submit report request for XML format

alias=''a'' 
,Src=''https://reporting.api.bingads.microsoft.com/Api/Advertiser/Reporting/v13/ReportingService.svc''
,Filter=''$.s:Envelope.s:Body.SubmitGenerateReportResponse''
,RequestData=''@c:\BWProjects\Requests\BingAds\sql_body1.xml''
,IsMultiPart=''True''
,RequestContentTypeCode=''TextXml''
,Header=''SOAPAction: "SubmitGenerateReport"''
,RequestMethod=''POST''
,EnableBodyPlaceholderForMultiPart=''True''
,Meta=''[{"Name": "ReportRequestId","Type": "Int64"}]''

--keep checking status until report is ready - returns final url when done

,join1_alias=''b''
,join1_Filter=''$.s:Envelope.s:Body.PollGenerateReportResponse.ReportRequestStatus''
,join1_RequestData=''@c:\BWProjects\Requests\BingAds\sql_body2.xml''
,join1_IsMultiPart=''True''
,join1_Src=''https://reporting.api.bingads.microsoft.com/Api/Advertiser/Reporting/v13/ReportingService.svc''
,join1_RequestContentTypeCode=''TextXml''
,join1_Header=''SOAPAction: "PollGenerateReport"''
,join1_RequestMethod=''POST''
,join1_EnableBodyPlaceholderForMultiPart=''True''
,join1_EnableStatusCheck=''True'', 
,join1_StatucCheckMaxWaitSeconds=300, --wait max 5 mins?
,join1_StatucCheckIterationWaitSeconds=5, --check every 5 sec?
,join1_StatusSuccessValue=''Success'', --look for success word in response

--Download report (Zip file) and Parse rows

,join2_alias=''c''
,join2_DataConnectionType=''Default''
,join2_Src=''[$b.ReportDownloadUrl$]''
,join2_Filter=''$.Report.Table.Row[*]''
,join2_ElementsToTreatAsArray=''Row''	
,join2_RequestMethod=''GET''
,join2_IsMultiPart=''False''
,join2_FileCompressionType=''Zip''	
)')

select * from tmpBingAdsReport

select * from openquery(Bing, 'select * from $')
*/
go</pre><p>
&nbsp;</p>
<h2>Conclusion</h2>
<p>In this article we saw how to import Bing Ads API data in SQL Server without any coding using <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack (SOAP / XML Driver)</a>. Download it it and try it for FREE to explore many API integration features not discussed in this article.</p>
<p>The post <a href="https://zappysys.com/blog/import-bing-ads-data-sql-server-performance-reports/">Import Bing Ads data into SQL Server (Performance Reports)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to import Amazon MWS data into SQL Server (T-SQL)</title>
		<link>https://zappysys.com/blog/import-amazon-mws-data-sql-server-t-sql/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Thu, 30 May 2019 15:37:37 +0000</pubDate>
				<category><![CDATA[CSV File / REST API Driver]]></category>
		<category><![CDATA[ODBC Gateway]]></category>
		<category><![CDATA[T-SQL (SQL Server)]]></category>
		<category><![CDATA[XML File / SOAP API Driver]]></category>
		<category><![CDATA[Amazon MWS]]></category>
		<category><![CDATA[linked server]]></category>
		<category><![CDATA[openquery]]></category>
		<category><![CDATA[t-sql]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=6961</guid>

					<description><![CDATA[<p>Introduction In our previous blog post we saw how to import rest API in SQL Server. Using same concepts lets look at how to import Amazon MWS Data into SQL Server. We will explore many techniques to call Amazon MWS API and learn how to automate Amazon MWS data extraction without doing any ETL. We [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/import-amazon-mws-data-sql-server-t-sql/">How to import Amazon MWS data into SQL Server (T-SQL)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<div class="su-note"  style="border-color:#e2dec9;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><div class="su-note-inner su-u-clearfix su-u-trim" style="background-color:#fcf8e3;border-color:#ffffff;color:#8a6d3b;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;">
<strong><span style="vertical-align: text-bottom;font-size: 0.86em;">⚠️</span> Deprecation Notice: MWS API is deprecated</strong><br />
Amazon&#8217;s MWS (Marketplace Web Service) is being deprecated and <strong>replaced by the newer AWS Selling Partner API (SP-API).</strong> For a more robust and secure integration, we <strong>recommend</strong> using our <strong><a href="/api/integration-hub/amazon-selling-partner-connector/">AWS Selling Partner (SP-API) Connector</a>.</strong> As Amazon is phasing out MWS functionality and eventually plans to fully deprecate it.<br />
</div></div>
<p><a href="https://zappysys.com/blog/wp-content/uploads/2016/10/amazon-mws-api-integration.png"><img loading="lazy" decoding="async" class="wp-image-1632 alignleft" src="https://zappysys.com/blog/wp-content/uploads/2016/10/amazon-mws-api-integration.png" alt="" width="98" height="98" srcset="https://zappysys.com/blog/wp-content/uploads/2016/10/amazon-mws-api-integration.png 505w, https://zappysys.com/blog/wp-content/uploads/2016/10/amazon-mws-api-integration-150x150.png 150w, https://zappysys.com/blog/wp-content/uploads/2016/10/amazon-mws-api-integration-300x300.png 300w" sizes="(max-width: 98px) 100vw, 98px" /></a>In our previous blog post we saw how to <a href="https://zappysys.com/blog/import-rest-api-json-sql-server/" target="_blank" rel="noopener">import rest API in SQL Server</a>. Using same concepts lets look at how to import Amazon MWS Data into SQL Server. We will explore many techniques to call Amazon MWS API and learn how to automate Amazon MWS data extraction without doing any ETL. We will call MWS XML or CSV API just using T-SQL code. We will also learn how to Download Reports from by calling MWS API.</p>
<p>You can also refer other articles <a href="https://zappysys.com/blog/import-amazon-mws-data-power-bi/" target="_blank" rel="noopener">here (Power BI)</a> and <a href="https://zappysys.com/blog/call-amazon-mws-api-using-ssis-marketplace-web-service/" target="_blank" rel="noopener">here (SSIS)</a></p>
<p>&nbsp;</p>
<div class="content_block" id="custom_post_widget-7048"><h2>Requirements</h2>
This article talks about few tools and techniques in order to load API data in SQL Server. Please make sure following prerequisites are met.
<ol>
 	<li>Download and Install <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> (This includes XML / JSON / REST API and few other drivers for SQL Server and ODBC connectivity in tools like Excel, Power BI, SSRS)</li>
 	<li>Make sure you have access to SQL Server Instance. If you cant find one still want to try what is mentioned in this article then install <a href="https://www.microsoft.com/en-us/sql-server/sql-server-editions-express" target="_blank" rel="noopener">FREE SQL Express Edition</a></li>
 	<li>Confirm that you have SSMS Installed. If you don't have then you can download <a href="https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-2017">from here</a>.</li>
</ol></div>
<h2></h2>
<h2>About Amazon MWS  API</h2>
<p>If you want to sell something on Amazon you can use their e-commerce platform with some monthly fee. You can setup your entire online store / inventory using admin interface.</p>
<p>Amazon Marketplace Web Service (Amazon MWS) is an integrated web service API that helps Amazon sellers to programmatically exchange data on listings, orders, payments, reports, and more. Using these API you can read or write data from your Seller account and integrate it inside your own Systems (e.g. Reporting / ETL / BI tools).</p>
<div class="su-note"  style="border-color:#e5de9d;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><div class="su-note-inner su-u-clearfix su-u-trim" style="background-color:#fff8b7;border-color:#ffffff;color:#333333;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;">NOTE: Amazon MWS may allow only certain number of requests per minute depending which API you calling so you might want to use each call wisely. We will suggest you various techniques throughout this article so you can avoid errors so read each section carefully. You can find Throttling information on API help page itself (<a href="https://docs.developer.amazonservices.com/en_IT/orders-2013-09-01/Orders_ListOrders.html" target="_blank" rel="noopener">like this one</a> see throttling section. Also <a href="https://docs.developer.amazonservices.com/en_IT/dev_guide/DG_Throttling.html">this one</a>).</div></div>
<h2>Obtain MWS API Access Key / Secret and Seller ID</h2>
<p>Very first thing to call any MWS API is to obtain Access Key, Secret Key and Seller ID (i.e. Merchant ID). To obtain this you first have to <a href="https://docs.developer.amazonservices.com/en_US/dev_guide/DG_Registering.html" target="_blank" rel="noopener">register a developer</a>.</p>
<p>Here is where to look for your Merchant ID and Key / Secret.  Here is direct link to <a href="https://sellercentral.amazon.com/gp/account-manager/home.html/ref=xx_userperms_dnav_userperms" target="_blank" rel="noopener">User Permissions</a> page.</p>
<div id="attachment_4843" style="width: 997px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/09/obtain-amazon-mws-developer-aws-access-key-secret-key-sellerid.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4843" class="size-full wp-image-4843" src="https://zappysys.com/blog/wp-content/uploads/2018/09/obtain-amazon-mws-developer-aws-access-key-secret-key-sellerid.png" alt="How to get Amazon MWS developer keys and know your Merchant ID (i.e. Seller ID)" width="987" height="422" srcset="https://zappysys.com/blog/wp-content/uploads/2018/09/obtain-amazon-mws-developer-aws-access-key-secret-key-sellerid.png 987w, https://zappysys.com/blog/wp-content/uploads/2018/09/obtain-amazon-mws-developer-aws-access-key-secret-key-sellerid-300x128.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/09/obtain-amazon-mws-developer-aws-access-key-secret-key-sellerid-768x328.png 768w" sizes="(max-width: 987px) 100vw, 987px" /></a><p id="caption-attachment-4843" class="wp-caption-text">How to get Amazon MWS developer keys and know your Merchant ID (i.e. Seller ID)</p></div>
<h2>Getting Started</h2>
<p>Now let&#8217;s look at step by step instructions on how to call Amazon MWS API and then import into Power BI. In below steps we will use  <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> so make sure it&#8217;s installed first.</p>
<h3>Using ScratchPad to Test Amazon MWS API</h3>
<p>Each MWS API has set of required and optional parameters. You can refer each API page for details. For example <a href="https://docs.developer.amazonservices.com/en_US/products/Products_ListMatchingProducts.html" target="_blank" rel="noopener">ListMatchingProducts</a> API which we will use as an example. To make MWS API testing / learning easy, Amazon provides online testing tool called <a href="https://mws.amazonservices.com/scratchpad/index.html" target="_blank" rel="noopener">MWS ScratchPad</a>. We will use this tool to craft API requests and use that information in ODBC driver SQL queries and later import data in Power BI.</p>
<ol>
<li>Open <a href="https://mws.amazonservices.com/scratchpad/index.html" target="_blank" rel="noopener">MWS ScratchPad</a>  by vising <strong>https://mws.amazonservices.com/scratchpad/index.html</strong></li>
<li>Select <strong>Products</strong> API category and pick <strong>ListMatchingProducts</strong> API</li>
<li>Enter your <strong>SellerID</strong> (i.e. Merchant ID), Developer AccessKey (i.e. <strong>AWSAccessKeyId</strong>) and <strong>Secret Key</strong> we obtained in the previous section. Enter MarketId (e.g. <strong>ATVPDKIKX0DER</strong> for USA Market) and other parameters as below and Click Submit to see response.
<div id="attachment_4844" style="width: 800px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/09/amazon-mws-api-scratchpad-online-testing-tool.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4844" class="size-full wp-image-4844" src="https://zappysys.com/blog/wp-content/uploads/2018/09/amazon-mws-api-scratchpad-online-testing-tool.png" alt="Using Amazon MWS ScratchPad (API Testing Tool - Created by Amazon)" width="790" height="500" srcset="https://zappysys.com/blog/wp-content/uploads/2018/09/amazon-mws-api-scratchpad-online-testing-tool.png 790w, https://zappysys.com/blog/wp-content/uploads/2018/09/amazon-mws-api-scratchpad-online-testing-tool-300x190.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/09/amazon-mws-api-scratchpad-online-testing-tool-768x486.png 768w" sizes="(max-width: 790px) 100vw, 790px" /></a><p id="caption-attachment-4844" class="wp-caption-text">Using Amazon MWS ScratchPad (API Testing Tool &#8211; Created by Amazon)</p></div></li>
<li>Click on the <strong>Response Details</strong> Tab to extract some important information we will use for ODBC configuration. Notice attributes in red rectangles. They are the ones which we will need in the POST request Body. ZappySys Drivers supply many common parameters automatically but any API endpoint specific parameter must be supplied in the Request Body. For example you dont have to supply <b>SignatureVersion, Timestamp, Signature or SignatureMethod</b>
<div id="attachment_4847" style="width: 933px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/09/amazon-mws-api-response-scratchpad-listmatchingproducts-example.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4847" class="size-full wp-image-4847" src="https://zappysys.com/blog/wp-content/uploads/2018/09/amazon-mws-api-response-scratchpad-listmatchingproducts-example.png" alt="Calling Amazon MWS API in Scratchpad Testing Tool (Response Details Tab) - ListMatchingProducts Example" width="923" height="527" srcset="https://zappysys.com/blog/wp-content/uploads/2018/09/amazon-mws-api-response-scratchpad-listmatchingproducts-example.png 923w, https://zappysys.com/blog/wp-content/uploads/2018/09/amazon-mws-api-response-scratchpad-listmatchingproducts-example-300x171.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/09/amazon-mws-api-response-scratchpad-listmatchingproducts-example-768x439.png 768w" sizes="(max-width: 923px) 100vw, 923px" /></a><p id="caption-attachment-4847" class="wp-caption-text">Calling Amazon MWS API in Scratchpad Testing Tool (Response Details Tab) &#8211; ListMatchingProducts Example</p></div></li>
</ol>
<p>This API requires Market ID parameter so enter it as per your Market where you selling. For example USA marketplaceid = ATVPDKIKX0DER. You can lookup correct MarketplaceId by <a href="https://docs.developer.amazonservices.com/en_US/dev_guide/DG_Endpoints.html" target="_blank" rel="noopener">checking this help (endpoints / marketplaces)</a>.</p>
<h3></h3>
<h2>Setup Amazon MWS API Connections</h2>
<div class="content_block" id="custom_post_widget-5411"><h3><span style="font-size: 14pt;">Configure ZappySys Data Gateway</span></h3>
Now let's look at steps to configure Data Gateway after installation.
<ol style="margin-left: 0;">
 	<li style="text-align: left;">Assuming you have installed <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> using default options (Which also enables Data Gateway Service)</li>
 	<li style="text-align: left;">Search "Gateway" in your start menu and click ZappySys Data Gateway
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png" alt="Open ZappySys Data Gateway" /></a>
<p class="wp-caption-text">Opening ZappySys Data Gateway</p>

</div></li>
 	<li>First, make sure Gateway Service is running (Verify Start icon is disabled)</li>
 	<li>Also, verify Port on General Tab
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/03/ZappySys-data-gateway-port-5000.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/03/ZappySys-data-gateway-port-5000.png" alt="Port Number setting on ZappySys Data Gateway" /></a>
<p class="wp-caption-text">Checking port number setting on ZappySys Data Gateway</p>

</div></li>
 	<li>Now go to Users tab. <strong>Click Add</strong> icon to add a new user. Check Is admin to give access to all data sources you add in future. If you don't check admin then you have to manually configure user permission for each data source.
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-user.png">
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-5453" src="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-configure-add-user.png" alt="" width="564" height="438" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-configure-add-user.png 564w, https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-configure-add-user-300x233.png 300w" sizes="(max-width: 564px) 100vw, 564px" /></a>
<p class="wp-caption-text">Adding the Gateway user</p>

</div></li>
</ol>
&nbsp;</div>
<h3>Create XML Driver Connection for Amazon MWS API (e.g. RequestReport )</h3>
<p>Some APIs we need to call in this article is XML format and some API (e.g. GetReport) is CSV format &#8211; Tab delimited so we need to create 2 different connections using CSV driver and XML driver. So lets get started with Amazon MWS Connection for XML API.</p>
<ol>
<li>Click on Add New Data source. Name as <strong>AMAZON-MWS-XML</strong> and select <a href="https://zappysys.com/products/odbc-powerpack/odbc-xml-soap-api-driver/" target="_blank" rel="noopener"><strong>Native &#8211; ZappySys XML Driver</strong></a> option.
<div id="attachment_5557" style="width: 572px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc_json_driver_add_native_driver.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5557" class="size-full wp-image-5557" src="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc_json_driver_add_native_driver.png" alt="Add Gateway Data Source" width="562" height="539" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc_json_driver_add_native_driver.png 562w, https://zappysys.com/blog/wp-content/uploads/2018/11/odbc_json_driver_add_native_driver-300x288.png 300w" sizes="(max-width: 562px) 100vw, 562px" /></a><p id="caption-attachment-5557" class="wp-caption-text">Add Gateway Data Source</p></div></li>
<li>Now click Edit to Configure Settings. For now we will only care OAuth Connection settings. All other options are overwritten in SQL Query.
<div id="attachment_5440" style="width: 572px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-2-2.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5440" class="size-full wp-image-5440" src="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-2-2.png" alt="Edit Gateway Data Source Settings" width="562" height="385" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-2-2.png 562w, https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-2-2-300x206.png 300w" sizes="(max-width: 562px) 100vw, 562px" /></a><p id="caption-attachment-5440" class="wp-caption-text">Edit Gateway Data Source Settings</p></div></li>
<li>When UI opens for Driver Enter MWS API Service URL as below. Notice that we added /Products/2011-10-01 (This was extracted from previous section). You can check <a href="https://docs.developer.amazonservices.com/en_ES/dev_guide/DG_Endpoints.html" target="_blank" rel="noopener">full list of Amazon MWS Endpoints here</a>. Because we are connecting to USA region we will use below URL.<br />
<pre class="crayon-plain-tag">https://mws.amazonservices.com/Products/2011-10-01</pre>
</li>
<li>Select <strong>OAuth</strong> from the Connection dropdown and Click <strong>Configure Settings</strong></li>
<li>On the Connection UI, Select OAuth Provider <strong>Amazon Market Web Service (MWS)</strong></li>
<li>Enter your API <strong>Access Key</strong> and <strong>Secret Key</strong> (obtained <a href="https://sellercentral.amazon.com/gp/account-manager/home.html/ref=xx_userperms_dnav_userperms" target="_blank" rel="noopener">from here</a>)</li>
<li>Your connection will look like below.
<div id="attachment_4850" style="width: 667px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/09/amazon-mws-api-odbc-driver-connection.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4850" class="size-full wp-image-4850" src="https://zappysys.com/blog/wp-content/uploads/2018/09/amazon-mws-api-odbc-driver-connection.png" alt="ODBC Connection Credentials for Amazon MWS API (Access Key, Secret Key, URL Endpoint)" width="657" height="570" srcset="https://zappysys.com/blog/wp-content/uploads/2018/09/amazon-mws-api-odbc-driver-connection.png 657w, https://zappysys.com/blog/wp-content/uploads/2018/09/amazon-mws-api-odbc-driver-connection-300x260.png 300w" sizes="(max-width: 657px) 100vw, 657px" /></a><p id="caption-attachment-4850" class="wp-caption-text">ODBC Connection Credentials for Amazon MWS API (Access Key, Secret Key, URL Endpoint)</p></div></li>
<li>Also configure Retry options to handle API limit reached error when you call API too often. For Amazon MWS we get Status code 503 when request is throttled so lets narrow down on which error we want to retry.
<div id="attachment_7156" style="width: 599px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/09/http-retry-settings-oauth-connection.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7156" class="size-full wp-image-7156" src="https://zappysys.com/blog/wp-content/uploads/2018/09/http-retry-settings-oauth-connection.png" alt="Retry Options" width="589" height="429" srcset="https://zappysys.com/blog/wp-content/uploads/2018/09/http-retry-settings-oauth-connection.png 589w, https://zappysys.com/blog/wp-content/uploads/2018/09/http-retry-settings-oauth-connection-300x219.png 300w" sizes="(max-width: 589px) 100vw, 589px" /></a><p id="caption-attachment-7156" class="wp-caption-text">Retry Options</p></div></li>
<li>Click OK to save OAuth Connection UI to go back to main UI</li>
<li>Now Go to Throttling Tab and enter some delay (e.g. <strong>enter 20000 for 20sec delay after each request</strong>). This will slow down API calls so we don&#8217;t face errors about API Limit reached.</li>
<li>Click OK to Save UI</li>
<li>Click Save button on Gateway UI to save and restart</li>
</ol>
<h3>Create CSV Driver Connection for Amazon MWS API (e.g. GetReport )</h3>
<p>Now lets create a connection CSV API (e.g. <a href="https://docs.developer.amazonservices.com/en_UK/reports/Reports_GetReport.html" target="_blank" rel="noopener">GetReport</a> ).</p>
<p>Follow almost same steps as previous section except use CSV Driver when you click on Add new Data source select <strong><a href="https://zappysys.com/products/odbc-powerpack/odbc-csv-rest-api-driver/" target="_blank" rel="noopener">Native &#8211; ZappySys CSV Driver</a></strong> and name data source as <strong>AMAZON-MWS-CSV</strong> . As we mentioned for now we mostly want to setup Connection and not worry about Request Body, Pagination etc.</p>
<h3>Create Linked Server for SQL Server</h3>
<p>Run following Script in SSMS to create Linked servers. Change ######## with Your gateway password. Change localhost with machine name or IP where ZappySys Gateway Is running. Use localhost if SQL Server and Gateway both on the same machine.</p><pre class="crayon-plain-tag">USE [master]
GO

EXEC master.dbo.sp_addlinkedserver @server = N'AMAZON-MWS-XML', @srvproduct=N'', @provider=N'SQLNCLI', @datasrc=N'localhost,5000', @catalog=N'AMAZON-MWS-XML'
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'AMAZON-MWS-XML',@useself=N'False',@locallogin=NULL,@rmtuser=N'tdsuser',@rmtpassword='########'
GO

EXEC master.dbo.sp_addlinkedserver @server = N'AMAZON-MWS-CSV', @srvproduct=N'', @provider=N'SQLNCLI', @datasrc=N'localhost,5000', @catalog=N'AMAZON-MWS-CSV'
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'AMAZON-MWS-CSV',@useself=N'False',@locallogin=NULL,@rmtuser=N'tdsuser',@rmtpassword='########'
GO</pre><p>
If you want to know how to configure Linked Server using UI then <a href="https://zappysys.com/blog/import-rest-api-json-sql-server/" target="_blank" rel="noopener">check this article</a>.</p>
<p>&nbsp;</p>
<h2>Amazon MWS ListOrders Example</h2>
<p>Now lets look at how to call ListOrders request with pagination in SQL Server. Create a following Stored Procedure to List MWS Orders. If you want to extract many orders then call Report rather than this proc (See next section for generating reports)</p><pre class="crayon-plain-tag">USE MyDatabase
GO
/*
Example: 
 exec usp_MWS_ListOrders @SellerId='Axxxxxxx', @MarketplaceId ='Bxxxxxxx',@CreatedAfter='2019-01-01'  
*/
Create proc [dbo].[usp_MWS_ListOrders]
	@SellerId varchar(100),
	@MarketplaceId varchar(100),
	@CreatedAfter varchar(100),
	@CreatedBefore varchar(100)=null,
	@MaxRows int=0
as
declare @sql varchar(max) 
declare @limitClase varchar(100)=''
if(@MaxRows&gt;0)
	set @limitClase	=' LIMIT ' + cast(@MaxRows as varchar(20))

--//Confirm ISO Date format 2019-06-01T04%3A00%3A00Z  rather 2019-06-01T04:00:00Z
if(isnull(@CreatedAfter,'')&lt;&gt;'')
begin
	set @CreatedAfter='&amp;CreatedAfter=' + @CreatedAfter
	set @CreatedAfter=replace(@CreatedAfter,':','%3A')
	if(@CreatedAfter NOT LIKE @CreatedAfter + 'T%')
		set @CreatedAfter=@CreatedAfter + 'T00%3A00%3A00Z'
	if(@CreatedAfter NOT LIKE @CreatedAfter + '%Z')
		set @CreatedAfter=@CreatedAfter + 'Z'
	--//T04%3A00%3A00Z
end
if(isnull(@CreatedBefore,'')&lt;&gt;'')
begin
	set @CreatedBefore='&amp;CreatedBefore=' + @CreatedBefore
	set @CreatedBefore=replace(@CreatedBefore,':','%3A')
	if(@CreatedBefore NOT LIKE @CreatedBefore + 'T%')
		set @CreatedBefore=@CreatedBefore + 'T00%3A00%3A00Z'
	if(@CreatedBefore NOT LIKE @CreatedBefore + '%Z')
		set @CreatedBefore=@CreatedBefore + 'Z'
end

set @CreatedAfter = isnull(@CreatedAfter,'')
set @CreatedBefore = isnull(@CreatedBefore,'')


set @sql = 'SELECT * FROM OPENQUERY([AMAZON-MWS-XML]
, ''
SELECT ReportRequestId FROM $
' + @limitClase +' 
WITH(
     Src=''''https://mws.amazonservices.com/Orders/2013-09-01''''
	,Filter=''''$.RequestReportResponse.RequestReportResult.ReportRequestInfo''''
	,ElementsToTreatAsArray=''''Order''''
	,RequestData=''''Action=ListOrders[$tag$]' + @CreatedAfter + @CreatedBefore + '&amp;MarketplaceId.Id.1='+ @MarketplaceId +'&amp;SellerId='+ @SellerId +'''''
	,RequestMethod=''''POST''''
	,NextUrlAttributeOrExpr=''''$.ListOrders[$tag$]Response.ListOrders[$tag$]Result.NextToken''''
	,NextUrlSuffix=''''&amp;NextToken=&lt;%nextlink_encoded%&gt;''''
	,WaitTimeMs=20000 -- slow down to avoid throttling. 6 requests per min
	,HasDifferentNextPageInfo=''''True''''
	,EnablePageTokenForBody=''''True''''
	,PagePlaceholders=''''body=|ByNextToken;filter=|ByNextToken''''
	--,DataConnectionType=''''OAuth''''
	--,ScopeSeparator=''''{space}''''
	--,ServiceProvider=''''AmazonMWS''''
	--,ClientId=''''AKIxxxxxx''''
	--,ClientSecret=''''AKIxxxxxx''''
	--,UseCustomApp=''''True''''
	,CacheFileLocation=''''c:\temp\mws-orders.cache''''
	,CacheEntryTtl=300 --send every 5 mins else use from cache
	,IncludeParentColumns=''''False''''
)
'')'
print @sql

EXECUTE( @sql)</pre><p>
Here is how to call this proc. Change SellerId, MarketplaceId and Date.</p><pre class="crayon-plain-tag">exec usp_MWS_ListOrders @SellerId='Axxxxxxx', @MarketplaceId ='Bxxxxxxx',@CreatedAfter='2019-01-01'</pre><p>
&nbsp;</p>
<h2>Download Amazon MWS Report data in SQL Server (CSV / XML Format)</h2>
<p>Now lets look at how to extract data from <a href="https://docs.developer.amazonservices.com/en_UK/reports/Reports_ReportType.html" target="_blank" rel="noopener">Custom Report API</a> (You must need ODBC PowerPack <strong>v1.1.1</strong> or higher). However reading data from Reports not single step process because report generation is Job style API. Which means you send report request and wait  until its done. Once Report ready you have to read in CSV format or XML. Some Reports only available in CSV format. <a href="https://docs.developer.amazonservices.com/en_UK/reports/Reports_Overview.html" target="_blank" rel="noopener">Check this post</a> to understand how complex it can be to get data. We will make it simple for you to understand this in 3 steps. Basically calling reports requires minimum 3 API calls (see below)</p>
<ol>
<li>Create a new report request &#8211; Cal <a href="https://docs.developer.amazonservices.com/en_UK/reports/Reports_RequestReport.html" target="_blank" rel="noopener">RequestReport</a> API . It returns <strong>ReportRequestId</strong> (You can use it in the next step)</li>
<li>Check Report Status see its done &#8211; Call <a href="https://docs.developer.amazonservices.com/en_UK/reports/Reports_GetReportRequestList.html" target="_blank" rel="noopener">GetReportRequestList</a> API (Pass <strong>ReportRequestId</strong> got in the previous step to get data for only one Report request we care). Keep checking Report Status every few seconds until you get <strong>_DONE_</strong>  or <strong>_DONE_NO_DATA_</strong> status in response.</li>
<li>Read Report Data &#8211; Call <a href="https://docs.developer.amazonservices.com/en_UK/reports/Reports_GetReport.html" target="_blank" rel="noopener">GetReport</a>. This API call returns CSV or XML data. So use correct Driver for this step. If CSV data is returned then we must use CSV Driver rather than XML Driver.</li>
</ol>
<h3>Method 1 &#8211; Single query approach (New Driver)</h3>
<p>In new driver ZappySys added few new features which makes it possible to call above 3 steps process in a single query. New query syntax offers StatusCheck and Mixing Content Formats using same driver. Because Most MWS Reports are in CSV Format we have to use CSV Driver but oddly first 2 steps listed in above sections are in XML Format so we have to use XML driver. Technically we need atleast 2 steps (i.e 2 queries) but we will show you how to achieve using single query as below.</p>
<ol>
<li>Assuming you have followed steps to create a linked server AMAZON-MWS-CSV (see previous section)</li>
<li>Run below query. Replace necessary parameters as per your need. (i.e MarketplaceId , SellerId, CreatedAfter date)<br />
<pre class="crayon-plain-tag">--- //////////////////////////////////////////////////////////////////////////
-- Change _GET_MERCHANT_LISTINGS_DATA_ to something else if you need different report type (all 3 steps) -- https://docs.developer.amazonservices.com/en_US/reports/Reports_ReportType.html
-- Replace MarketplaceId in all 3 steps (i.e for USA use ATVPDKIKX0DER) --https://docs.developer.amazonservices.com/en_US/dev_guide/DG_Endpoints.html
-- Replace SellerId in all 3 steps
-- Remove or Change CreatedAfter in first step (or use CreatedBefore parameter instread of CreatedAfter)
--- //////////////////////////////////////////////////////////////////////////
select * into tmpMWS_Report from OPENQUERY([AMAZON-MWS-CSV],
'
SELECT s3.* FROM $
WITH(
Src=''https://mws.amazonservices.com/Reports/2009-01-01'',RequestMethod=''POST''
,RequestData=''Action=RequestReport&amp;ReportType=_GET_MERCHANT_LISTINGS_DATA_&amp;MarketplaceId=ATVPDKIKX0DER&amp;SellerId=Axxxxxxxxxx&amp;CreatedAfter=2017-12-31T04%3A00%3A00Z''
,IncludeParentColumns=''False''
,EnableRawOutputModeSingleRow=''True''
,RawOutputFilterExpr=''//*[local-name()="ReportRequestId"]'' 
,RawOutputDataRowTemplate=''{ReportRequestId:"[$1]"}'' 
,RawOutputExtractMode=''Xml'' 
,WaitTimeMs=5000
,Meta=''[{"Name": "ReportRequestId","Type": "Int64"}]''
,Alias=''s1''

,Join1_alias=''s2''	
,Join1_Src=''https://mws.amazonservices.com/Reports/2009-01-01'',Join1_RequestMethod=''POST''
,Join1_RequestData=''Action=GetReportRequestList&amp;ReportRequestIdList.Id.1=[$s1.ReportRequestId$]&amp;MarketplaceId=ATVPDKIKX0DER&amp;SellerId=Axxxxxxxxxxxxx''
,Join1_EnableRawOutputModeSingleRow=''True''
,Join1_RawOutputFilterExpr=''//*[local-name()="ReportProcessingStatus"]||//*[local-name()="GeneratedReportId"]'' 
,Join1_RawOutputDataRowTemplate=''{ReportProcessingStatus:"[$1]",GeneratedReportId:"[$2]"}'' 
,Join1_RawOutputExtractMode=''Xml'' 
,Join1_EnableStatusCheck=''True'', 
,Join1_StatucCheckMaxWaitSeconds=300,
,Join1_StatucCheckIterationWaitSeconds=25,
,Join1_StatusSuccessValue=''_DONE_''
,Join1_StatusFailedValue=''_DONE_NO_DATA_|_CANCELLED_''

,Join2_Alias=''s3''
,Join2_Src=''https://mws.amazonservices.com/Reports/2009-01-01'',Join2_RequestMethod=''POST''
,Join2_RequestData=''Action=GetReport&amp;ReportId=[$s2.GeneratedReportId$]&amp;MarketplaceId=ATVPDKIKX0DER&amp;SellerId=Axxxxxxxxxxxxxx''	
,Join2_ColumnDelimiter=''{TAB}''
,Join2_ResponseCharset=''Windows-1252''	 
,Join2_EnableStatusCheck=''False'' 
,Join2_EnableRawOutputModeSingleRow=''False''
,Join2_WaitTimeMs=10000
)') 
go
select * from tmpMWS_Report</pre>
&nbsp;</li>
</ol>
<p>&nbsp;</p>
<p><strong>Performance Tip</strong></p>
<p>If you like to improve performance and dont want to use SELECT INTO approach to load into temp table as above then you can use EXEC (&#8230;.) AT YourLinkedServerName  as below.</p>
<p>Advantage of this method is your Query speed will increase because system calls API only once when you call EXEC AT. In OPENROWSET it needs to call above query twice (Once to obtain metadata and once to get data).</p><pre class="crayon-plain-tag">INSERT INTO tmpMWS_Report
EXEC('select s3.* .................. ') AT [AMAZON-MWS-CSV]</pre><p>
<div class="su-note"  style="border-color:#e5de9d;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><div class="su-note-inner su-u-clearfix su-u-trim" style="background-color:#fff8b7;border-color:#ffffff;color:#333333;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;">When you use OPENQUERY / EXEC..AT with Data Gateway there is a known limitation with SQL Query Length. Your query must be less than 2048 characters otherwise you may get [**** Data is invalid error ****] Try to avoid column names for long query and use SELECT * INTO temp_table FROM OPENQUERY(&#8230;..) approach. </div></div>
<p>&nbsp;</p>
<h3>Method 2 &#8211; Multiple query approach (For old driver)</h3>
<p>Now lets see how to load Amazon MWS data in SQL Server using <strong>old driver</strong> (<strong>v1.1.2 or older</strong>) which didnt support single query approach like previous section. If you are using older driver or for some reason you like to split steps into multiple procedures then use below approach.</p>
<h4>usp_MWS_Report  Stored Proc ( Generate ReportRequest, Wait until done, Read data )</h4>
<pre class="crayon-plain-tag">USE MyDatabase
GO

/*
Examples: 
Get ReportType from here https://docs.developer.amazonservices.com/en_UK/reports/Reports_ReportType.html

exec usp_MWS_Report @MarketplaceId ='ATVPDKIKX0DER', @SellerId='AZxxxxxxxx', @ReportType = '_GET_MERCHANT_LISTINGS_DATA_'
exec usp_MWS_Report @MarketplaceId ='ATVPDKIKX0DER', @SellerId='AZxxxxxxxx', @ReportType = '_GET_FLAT_FILE_ORDER_REPORT_DATA_'

--Do not Throw Error if no data found (return empty resultset or run custom sql)
exec usp_MWS_Report @MarketplaceId ='ATVPDKIKX0DER', @SellerId='AZxxxxxxxx', @ReportType = '_GET_FLAT_FILE_ORDER_REPORT_DATA_',@ThrowErrIfNoData=0,@EmptyRowSql='select top 0 * from Orders'
--Supply date range
exec usp_MWS_Report @MarketplaceId ='ATVPDKIKX0DER', @SellerId='AZxxxxxxxx', @ReportType = '_GET_MERCHANT_LISTINGS_DATA_', @StartDate='2019-01-01T00:00:00Z', @EndDate='2019-01-31T00:00:00Z'

--loading into table 

--//////////////////////////////////
— Step-1 : Create Local Linked server to point to self
--//////////////////////////////////
USE [master]
GO
--change default catalog
--For MSSQL 2012, 2014, 2016, 2017, and 2019 use @provider=N'MSOLEDBSQL' below (SQL Server Native Client 11.0)---
EXEC master.dbo.sp_addlinkedserver @server = N'ME', @srvproduct=N'', @provider=N'SQLNCLI11', @datasrc=N'localhost', @catalog=N'Northwind'
--For MSSQL 2022 or higher use @provider=N'MSOLEDBSQL' below (Microsoft OLE DB Driver for SQL Server)---
--EXEC master.dbo.sp_addlinkedserver @server = N'ME', @srvproduct=N'', @provider=N'MSOLEDBSQL', @datasrc=N'localhost', @catalog=N'Northwind'

EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'ME',@useself=N'True',@locallogin=NULL,@rmtuser=NULL,@rmtpassword=NULL
GO
--//////////////////////////////////
— Step-2 : Enable RPC OUT and Disable MSDTC
--//////////////////////////////////
EXEC sp_serveroption 'ME', 'rpc out', true;  
GO
--Below needed to support EXEC + INSERT (dynamic query)
EXEC sp_serveroption 'ME', 'remote proc transaction promotion', false;
GO
--test simple query
select * from OPENQUERY(ME,'select 1')
GO

--//////////////////////////////////
— Step-3 : Load data into table from MWS Report
--//////////////////////////////////
SELECT * INTO #amazon_mws_report
FROM OPENQUERY(me,'
SET NOCOUNT ON;
EXEC usp_MWS_Report 
   @Columns=''[item-name], [item-description], [listing-id]'',
   @MarketplaceId =''ATVPDKIKX0DER'', 
   @SellerId=''Axxxxxxxxxxxxxxxxx'', 
   @ReportType = ''_GET_MERCHANT_LISTINGS_DATA_''
WITH RESULT SETS 
(
	(itmname varchar(1000),itmdesc varchar(1000),itmid varchar(1000))
)
')

select * from #amazon_mws_report


*/
CREATE proc [dbo].[usp_MWS_Report]
	@MarketplaceId varchar(100),
	@SellerId varchar(100),
	@ReportType varchar(100)='_GET_MERCHANT_LISTINGS_DATA_',
	@StartDate varchar(100)=null,
	@EndDate varchar(100)=null,
	@ReportId bigint=null,  ---i.e. 14783134522018025
	@ThrowErrIfNoData bit=1,
	@EmptyRowSql varchar(1000)=null, --SQL to run if no data found
	@Columns varchar(8000)='*'  --report columns which goes in final SELECT  e.g. [item-name], [item-description], [listing-id] ....
as


declare @retGeneratedReportId bigint
set @retGeneratedReportId=@ReportId
---////// STEP 1 /////////
if(@ReportId is null)
begin
	create table #step1(ReportRequestId bigint)
	insert into #step1
	exec usp_MWS_RequestReport @ReportType,@MarketplaceId,@SellerId,@StartDate,@EndDate

	--select * from #step1 --debug

	declare @retReportRequestId bigint
	select @retReportRequestId=ReportRequestId from #step1

	---////// STEP 2 /////////
	declare @status varchar(100)
	declare @cnt int
	create table #step2(ReportProcessingStatus varchar(100),GeneratedReportId bigint)
	
	--Keep looping until status is done or we waited too long
	while(isnull(@status,'') IN ('','_SUBMITTED_','_IN_PROGRESS_') )
	begin
		truncate table #step2
		insert into #step2
		exec usp_MWS_GetReportIdAndStatus @retReportRequestId,@MarketplaceId,@SellerId 
	
		select @status=ReportProcessingStatus, @retGeneratedReportId=GeneratedReportId from #step2
		if(isnull(@status,'') IN ('','_SUBMITTED_','_IN_PROGRESS_') )			
		begin
			--amazon says dont check often https://docs.developer.amazonservices.com/en_UK/reports/Reports_GetReportRequestList.html
			Print 'Status='+  isnull(@status,'') +'. Checking after 45 sec... #' + cast(@cnt as varchar(10))
			WAITFOR DELAY '00:00:45'			
		end
		else
			print @status

		set @cnt=@cnt+1

		--if(@cnt&gt;50)
			--//throw err?
	end
	--select * from #step2 --debug
end

if(@retGeneratedReportId is null and @status='_DONE_NO_DATA_')
begin
	if(@ThrowErrIfNoData=1)
		RAISERROR('Cannot generate report - No data found for specified criteria',16,1); 
	else if (isnull(@EmptyRowSql,'')&lt;&gt;'')
		execute(@EmptyRowSql)
end
else if(@retGeneratedReportId is null)
	RAISERROR('Cannot generate report - Unknown error (either report got cancelled or other error occurred)',16,1); 

	
---////// STEP 3 /////////
--If xml format of report data then use XML driver else CSV (most are Tab delimited reports in CSV format)
--exec usp_MWS_GetReportDataXml @retGeneratedReportId,@MarketplaceId,@SellerId
exec usp_MWS_GetReportDataCsv @retGeneratedReportId,@MarketplaceId,@SellerId,@Columns

drop table #step1
drop table #step2

GO</pre>
&nbsp;</p>
<h4>usp_MWS_RequestReport  Stored Proc ( Step1 &#8211; Create Report Request )</h4>
<p>&nbsp;</p><pre class="crayon-plain-tag">USE [MyDatabase]
GO

CREATE proc [dbo].[usp_MWS_RequestReport]
	@ReportType varchar(100),
	@MarketplaceId varchar(100),
	@SellerId varchar(100),
	@StartDate varchar(100)=null,
	@EndDate varchar(100)=null
as

/*Learn more : https://docs.developer.amazonservices.com/en_UK/reports/Reports_RequestReport.html */

--//Confirm ISO Date format 2019-06-01T04%3A00%3A00Z  rather 2019-06-01T04:00:00Z
if(isnull(@StartDate,'')&lt;&gt;'')
begin
	set @StartDate='&amp;StartDate=' + @StartDate
	set @StartDate=replace(@StartDate,':','%3A')
	if(@StartDate NOT LIKE @StartDate + 'T%')
		set @StartDate=@StartDate + 'T00%3A00%3A00Z'
	if(@StartDate NOT LIKE @StartDate + '%Z')
		set @StartDate=@StartDate + 'Z'
	--//T04%3A00%3A00Z
end
if(isnull(@EndDate,'')&lt;&gt;'')
begin
	set @EndDate='&amp;EndDate=' + @EndDate
	set @EndDate=replace(@EndDate,':','%3A')
	if(@EndDate NOT LIKE @EndDate + 'T%')
		set @EndDate=@EndDate + 'T00%3A00%3A00Z'
	if(@EndDate NOT LIKE @EndDate + '%Z')
		set @EndDate=@EndDate + 'Z'
end

set @StartDate = isnull(@StartDate,'')
set @EndDate = isnull(@EndDate,'')

declare @sql varchar(max) 
set @sql = 'SELECT * FROM OPENQUERY([AMAZON-MWS-XML]
, ''
SELECT ReportRequestId FROM $
WITH(
	Src=''''https://mws.amazonservices.com/Reports/2009-01-01'''',RequestMethod=''''POST''''
	--,ElementsToTreatAsArray=''''Product''''
	,Filter=''''$.RequestReportResponse.RequestReportResult.ReportRequestInfo''''
	,RequestData=''''Action=RequestReport&amp;ReportType=' + @ReportType  + '&amp;MarketplaceId='+ @MarketplaceId +'&amp;SellerId='+ @SellerId + @StartDate + @EndDate +'''''
	,CacheFileLocation=''''c:\temp\mws-cache-step-1.cache''''
	,CacheEntryTtl=300 --send every 5 mins else use from cache
	,WaitTimeMs=''''300''''
	,IncludeParentColumns=''''False''''
	,Meta=''''[{"Name": "ReportRequestId","Type": "Int64"}]''''
)'')'
--print @sql

EXECUTE( @sql)
--sleep 25 seconds after this - hope report is ready by that time else We have to loop
WAITFOR DELAY '00:00:25'  --lets wait 30 sec... incase we get luck and report is done?
GO</pre><p>
&nbsp;</p>
<p>&nbsp;</p>
<h4>usp_MWS_GetReportIdAndStatus Stored Proc ( Step2 &#8211; Get Report Id and Report Status )</h4>
<p>&nbsp;</p><pre class="crayon-plain-tag">USE MyDatabase
GO


CREATE proc [dbo].[usp_MWS_GetReportIdAndStatus]
	@ReportRequestId bigint,
	@MarketplaceId varchar(100),
	@SellerId varchar(100)
as

declare @sql varchar(max) 
set @sql = 'SELECT * FROM OPENQUERY([AMAZON-MWS-XML]
, ''SELECT *  FROM $
WITH(
	 Src=''''https://mws.amazonservices.com/Reports/2009-01-01'''',RequestMethod=''''POST''''
	,ElementsToTreatAsArray=''''ReportRequestInfo''''
	,Filter=''''$.GetReportRequestListResponse.GetReportRequestListResult.ReportRequestInfo''''
	,RequestData=''''Action=GetReportRequestList&amp;ReportRequestIdList.Id.1=' + cast(@ReportRequestId as varchar(20)) + '&amp;MarketplaceId='+ @MarketplaceId +'&amp;SellerId='+ @SellerId +'''''
	,WaitTimeMs=''''300''''
	,IncludeParentColumns=''''False''''
	--,CacheFileLocation=''''c:\temp\mws-cache-step-2.cache''''
	--,CacheEntryTtl=10  --do not use from cache too old.. but cache still prevents too many requests
	,Meta=''''[{"Name": "ReportProcessingStatus","Type": "String", Length: 100},{"Name": "GeneratedReportId","Type": "Int64"}]''''	
)'')'

--print @sql

EXECUTE( @sql)

GO</pre><p>
&nbsp;</p>
<h4>usp_MWS_GetReportDataCsv Stored Proc (Step3 &#8211; Get Report Data in CSV format )</h4>
<p>Last step in report generation is download the report data in CSV format.</p><pre class="crayon-plain-tag">USE MyDatabase
GO

CREATE proc [dbo].[usp_MWS_GetReportDataCsv]
	@ReportId bigint,
	@MarketplaceId varchar(100),
	@SellerId varchar(100),
	@Columns varchar(8000)='*'

as

declare @sql varchar(max) 
set @sql = 'SELECT '+ @Columns +' FROM OPENQUERY([AMAZON-MWS-CSV], 
''SELECT * FROM $
WITH(
    Src=''''https://mws.amazonservices.com/Reports/2009-01-01'''',RequestMethod=''''POST''''
	,RequestData=''''Action=GetReport&amp;ReportId=' + cast(@ReportId as varchar(20)) + '&amp;MarketplaceId='+ @MarketplaceId +'&amp;SellerId='+ @SellerId +'''''
	,WaitTimeMs=''''300''''
	,ColumnDelimiter=''''{TAB}''''
	,ResponseCharset=''''Windows-1252''''	
	,CacheFileLocation=''''c:\temp\mws-cache-step-3.cache''''
	,CacheEntryTtl=300 --once report is generated lets try to read from cache 
	)''
)'

print @sql

EXECUTE( @sql)
GO</pre><p>
&nbsp;</p>
<h4>Example &#8211; Import data from Amazon MWS into SQL Server Table</h4>
<p>Finally when we have all stored procs created we can load into target table as below. In our previous article we saw how to use SELECT INTO along with OPENQUERY to load data into new temp table or insert into some existing table. However when you want to load Stored Proc output into table its not straight forward specially when we calling dynamic SQL.</p>
<p>Three tricks worth mentioning here which makes it possible to load data from stored proc into temp table dynamically.</p>
<ol>
<li>Create a linked server to Self so we can use OPENQUERY against to call stored proc so its easy to use <strong>SELECT INTO</strong>.</li>
<li>Use <strong>WITH RESULT SETS</strong> to describe metadata of output. This is needed because we are using dynamic SQL inside proc and WITH RESULT SETS describes the metadata.</li>
<li>Use of SET NO COUNT ON to avoid error like below<br />
<pre class="crayon-plain-tag">"SOMESERVERNAME" indicates that either the object has no columns 
or the current user does not have permissions on that object</pre>
</li>
<li>If you dont do above tricks then you may see errors like <a href="https://stackoverflow.com/questions/3795263/errors-insert-exec-statement-cannot-be-nested-and-cannot-use-the-rollback-s" target="_blank" rel="noopener">this</a> (INSERT is not allowed when we use DYNAMIC SQL inside nested Stored Procs)</li>
</ol>
<p>To load output into table you must know column names from the output.  If you dont know you can try to run stored proc without @Columns like below.</p><pre class="crayon-plain-tag">EXEC usp_MWS_Report @MarketplaceId =''ATVPDKIKX0DER'', @SellerId=''Axxxxxxxxxxxxx'', @ReportType = ''_GET_MERCHANT_LISTINGS_DATA_''</pre><p>
Once we know columns from report, you can run following script to insert into table.</p>
<p><strong>Full Script &#8211; Load MWS Report Output into Table</strong></p><pre class="crayon-plain-tag">--//////////////////////////////////
— Step-1 : Create Local Linked server to point to self
--//////////////////////////////////
USE [master]
GO
--change default catalog
--For MSSQL 2012, 2014, 2016, 2017, and 2019 use @provider=N'MSOLEDBSQL' below (SQL Server Native Client 11.0)---
EXEC master.dbo.sp_addlinkedserver @server = N'ME', @srvproduct=N'', @provider=N'SQLNCLI11', @datasrc=N'localhost', @catalog=N'Northwind'
--For MSSQL 2022 or higher use @provider=N'MSOLEDBSQL' below (Microsoft OLE DB Driver for SQL Server)---
--EXEC master.dbo.sp_addlinkedserver @server = N'ME', @srvproduct=N'', @provider=N'MSOLEDBSQL', @datasrc=N'localhost', @catalog=N'Northwind'

EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'ME',@useself=N'True',@locallogin=NULL,@rmtuser=NULL,@rmtpassword=NULL
GO
--//////////////////////////////////
— Step-2 : Enable RPC OUT and Disable MSDTC
--//////////////////////////////////
EXEC sp_serveroption 'ME', 'rpc out', true;  
GO
--Below needed to support EXEC + INSERT (dynamic query)
EXEC sp_serveroption 'ME', 'remote proc transaction promotion', false;
GO
--test simple query
select * from OPENQUERY(ME,'select 1')
GO

--//////////////////////////////////
— Step-3 : Load data into temp table from Amazon MWS Report
--//////////////////////////////////
SELECT * INTO #amazon_mws_report
FROM OPENQUERY(me,'
SET NOCOUNT ON;
EXEC usp_MWS_Report 
   @Columns=''[item-name], [item-description], [listing-id]'',
   @MarketplaceId =''ATVPDKIKX0DER'', 
   @SellerId=''Axxxxxxxxxxxxx'', 
   @ReportType = ''_GET_MERCHANT_LISTINGS_DATA_''
WITH RESULT SETS 
(
	(itmname varchar(1000),itmdesc varchar(1000),itmid varchar(1000))
)
')

select * from #amazon_mws_report</pre><p>
<div id="attachment_7192" style="width: 865px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/05/import-amazon-mws-data-into-sql-server-table-generate-report.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7192" class="size-full wp-image-7192" src="https://zappysys.com/blog/wp-content/uploads/2019/05/import-amazon-mws-data-into-sql-server-table-generate-report.png" alt="Import Amazon MWS Data into SQL Table (Load Report output into temp table)" width="855" height="499" srcset="https://zappysys.com/blog/wp-content/uploads/2019/05/import-amazon-mws-data-into-sql-server-table-generate-report.png 855w, https://zappysys.com/blog/wp-content/uploads/2019/05/import-amazon-mws-data-into-sql-server-table-generate-report-300x175.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/05/import-amazon-mws-data-into-sql-server-table-generate-report-768x448.png 768w" sizes="(max-width: 855px) 100vw, 855px" /></a><p id="caption-attachment-7192" class="wp-caption-text">Import Amazon MWS Data into SQL Table (Load Report output into temp table)</p></div>
<h2>Conclusion</h2>
<p>In this article, we saw how to load Amazon MWS Data into SQL Server. We used simple SQL queries with ZappySys XML / CSV Driver to pull data from Amazon MWS API. <a href="https://zappysys.com/products/odbc-powerpack/">ZappySys ODBC PowerPack</a> makes it super easy to consume data from virtually any API (JSON / XML or CSV Web Services), no coding required. <a href="https://zappysys.com/products/odbc-powerpack/download/">Download here</a> to get started with ZappySys ODBC drivers.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a href="https://zappysys.com/blog/import-amazon-mws-data-sql-server-t-sql/">How to import Amazon MWS data into SQL Server (T-SQL)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Import Google Analytics data into SQL Server / Reporting / ETL</title>
		<link>https://zappysys.com/blog/import-google-analytics-data-sql-server-reporting-etl/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Sat, 25 May 2019 19:17:14 +0000</pubDate>
				<category><![CDATA[Google API]]></category>
		<category><![CDATA[ODBC Gateway]]></category>
		<category><![CDATA[REST API]]></category>
		<category><![CDATA[REST API Integration]]></category>
		<category><![CDATA[T-SQL (SQL Server)]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[google analytics]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[oauth]]></category>
		<category><![CDATA[openquery]]></category>
		<category><![CDATA[power bi]]></category>
		<category><![CDATA[ssms]]></category>
		<category><![CDATA[ssrs]]></category>
		<category><![CDATA[t-sql]]></category>
		<category><![CDATA[tableau]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=7003</guid>

					<description><![CDATA[<p>Introduction In our previous article we saw how to read Google Analytics data using SSIS. But what if you don&#8217;t use SSIS and you still like to Import Google Analytics data into SQL Server or Read inside other Reporting / ETL Apps (e.g. Excel, Power BI, MS Access &#8230; and many more). Not all BI [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/import-google-analytics-data-sql-server-reporting-etl/">Import Google Analytics data into SQL Server / Reporting / ETL</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p><a href="https://zappysys.com/blog/wp-content/uploads/2019/05/google-analytics-logo.png"><img loading="lazy" decoding="async" class=" wp-image-7056 alignleft" src="https://zappysys.com/blog/wp-content/uploads/2019/05/google-analytics-logo.png" alt="" width="162" height="162" srcset="https://zappysys.com/blog/wp-content/uploads/2019/05/google-analytics-logo.png 250w, https://zappysys.com/blog/wp-content/uploads/2019/05/google-analytics-logo-150x150.png 150w" sizes="(max-width: 162px) 100vw, 162px" /></a>In our previous article we saw how to <a href="https://zappysys.com/blog/get-data-from-google-analytics-in-ssis-using-rest-api-call/">read Google Analytics data using SSIS</a>. But what if you don&#8217;t use SSIS and you still like to Import Google Analytics data into SQL Server or Read inside other Reporting / ETL Apps (e.g. Excel, Power BI, MS Access &#8230; and many more). Not all BI tools comes with native driver / connectivity for Google Analytics. Sometimes they do offer Google Analytics connectivity but don&#8217;t offer feature you looking for (e.g. Sort, Segment Filter). In such case you have to look for solution outside.</p>
<p>Well not to worry we will show you how simple it is to connect to Google Analytics using <a href="https://zappysys.com/products/odbc-powerpack/odbc-json-rest-api-driver/" target="_blank" rel="noopener">ZappySys JSON Driver (For REST API / Files)</a> in few mins. This driver is one of the best REST API drivers you can find in the market. It is so generic that it can virtually access any REST API you may find internally or on public sites (e.g. Facebook, Salesforce, Azure, AWS). Check <a href="https://zappysys.com/blog/category/odbc-powerpack/odbc-drivers/json-rest-api-driver/" target="_blank" rel="noopener">these articles</a> to see many more use cases of JSON Driver.</p>
<p>At the end of this article you will learn how to Query Google Analytics data in <strong>SSMS</strong> like below (Yes that&#8217;s correct .. Pretty Awesome!!! ).</p>
<div id="attachment_7046" style="width: 649px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/05/import-google-analytics-data-into-sql-server.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7046" class="size-full wp-image-7046" src="https://zappysys.com/blog/wp-content/uploads/2019/05/import-google-analytics-data-into-sql-server.png" alt="Import Google Analytics Data into SQL Server Table (using T-SQL Code)" width="639" height="538" srcset="https://zappysys.com/blog/wp-content/uploads/2019/05/import-google-analytics-data-into-sql-server.png 639w, https://zappysys.com/blog/wp-content/uploads/2019/05/import-google-analytics-data-into-sql-server-300x253.png 300w" sizes="(max-width: 639px) 100vw, 639px" /></a><p id="caption-attachment-7046" class="wp-caption-text">Import Google Analytics Data into SQL Server Table (using T-SQL Code)</p></div>
<div class="content_block" id="custom_post_widget-7048"><h2>Requirements</h2>
This article talks about few tools and techniques in order to load API data in SQL Server. Please make sure following prerequisites are met.
<ol>
 	<li>Download and Install <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> (This includes XML / JSON / REST API and few other drivers for SQL Server and ODBC connectivity in tools like Excel, Power BI, SSRS)</li>
 	<li>Make sure you have access to SQL Server Instance. If you cant find one still want to try what is mentioned in this article then install <a href="https://www.microsoft.com/en-us/sql-server/sql-server-editions-express" target="_blank" rel="noopener">FREE SQL Express Edition</a></li>
 	<li>Confirm that you have SSMS Installed. If you don't have then you can download <a href="https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?view=sql-server-2017">from here</a>.</li>
</ol></div>
<h2>Testing Google Analytics API</h2>
<p>If you are new to Google Analytics API then read little bit about <a href="https://developers.google.com/analytics/devguides/reporting/core/v3/reference#data_request" target="_blank" rel="noopener">Google Analytics REST API here</a>. Google also offers a really good way to test Analytics API using <a href="https://ga-dev-tools.appspot.com/query-explorer/" target="_blank" rel="noopener">Query Explorer Tool here</a>. So please check that and understand how to craft correct REST API URL which will be used in the next section.</p>
<div id="attachment_7021" style="width: 908px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/05/generate-google-analytics-rest-api-url-query-explorer.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7021" class="size-full wp-image-7021" src="https://zappysys.com/blog/wp-content/uploads/2019/05/generate-google-analytics-rest-api-url-query-explorer.png" alt="Using Google Analytics Query Explorer Tool - Create REST API Url (Dimension / Metrics Selection Browser)" width="898" height="1379" srcset="https://zappysys.com/blog/wp-content/uploads/2019/05/generate-google-analytics-rest-api-url-query-explorer.png 898w, https://zappysys.com/blog/wp-content/uploads/2019/05/generate-google-analytics-rest-api-url-query-explorer-195x300.png 195w, https://zappysys.com/blog/wp-content/uploads/2019/05/generate-google-analytics-rest-api-url-query-explorer-768x1179.png 768w, https://zappysys.com/blog/wp-content/uploads/2019/05/generate-google-analytics-rest-api-url-query-explorer-667x1024.png 667w" sizes="(max-width: 898px) 100vw, 898px" /></a><p id="caption-attachment-7021" class="wp-caption-text">Using Google Analytics Query Explorer Tool &#8211; Create REST API Url (Dimension / Metrics Selection Browser)</p></div>
<h3>Sample Google Analytics API Response</h3>
<p>Behind the scene here is how API Request and Response Looks like for Google Analytics REST API. Notice that <strong>Authorization</strong> Header in below request is automatically added by ZappySys Driver or Query Testing tool above. Also notice <strong>nextLink</strong> attribute in response, its used to fetch more data. By default each response contains upto 10000 rows.</p>
<p><strong>Request</strong></p><pre class="crayon-plain-tag">GET https://www.googleapis.com/analytics/v3/data/ga?ids=ga:185737326&amp;start-date=30daysAgo&amp;end-date=yesterday&amp;metrics=ga:avgSessionDuration&amp;dimensions=ga:date
Authorization: Bearer ya29.GlwUxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</pre><p>
<strong>Response</strong></p><pre class="crayon-plain-tag">{
    "kind": "analytics#gaData",
    "id": "https://www.googleapis.com/analytics/v3/data/ga?ids=ga:123456789&amp;dimensions=ga:date&amp;metrics=ga:avgSessionDuration&amp;start-date=30daysAgo&amp;end-date=yesterday",
    "query": {
        "start-date": "30daysAgo",
        "end-date": "yesterday",
        "ids": "ga:123456789",
        "dimensions": "ga:date",
        "metrics": ["ga:avgSessionDuration"],
        "start-index": 1,
        "max-results": 1000
    },
    "itemsPerPage": 1000,
    "totalResults": 30,
    "selfLink": "https://www.googleapis.com/analytics/v3/data/ga?ids=ga:123456789&amp;dimensions=ga:date&amp;metrics=ga:avgSessionDuration&amp;start-date=30daysAgo&amp;end-date=yesterday",
    "nextLink": "https://www.googleapis.com/analytics/v3/data/ga?ids=ga:123456789&amp;dimensions=ga:date&amp;metrics=ga:avgSessionDuration&amp;start-date=30daysAgo&amp;end-date=yesterday&amp;start-index=10001&amp;max-results=10000",
    "profileInfo": {
        "profileId": "123456789",
        "accountId": "33445566",
        "webPropertyId": "UA-33445566-3",
        "internalWebPropertyId": "454545454",
        "profileName": "All Web Site Data",
        "tableId": "ga:123456789"
    },
    "containsSampledData": false,
    "columnHeaders": [
        {
            "name": "ga:date",
            "columnType": "DIMENSION",
            "dataType": "STRING"
        },
        {
            "name": "ga:avgSessionDuration",
            "columnType": "METRIC",
            "dataType": "TIME"
        }
    ], "totalsForAllResults": {
        "ga:avgSessionDuration": "49.3779488037477"
    },
    "rows": [ 
		["20190425", "401.38912133891213"], 
		["20190426", "512.49723756906077"], 
		["20190427", "11.53488372093024"], 
		["20190428", "432.148648648648646"], 
		["20190429", "234.650735294117645"],
		.......
		.......
		.......
		.......
		["20190525", "74.123435294117645"]
	]
}</pre><p>
&nbsp;</p>
<h2>Creating Google API Project (Obtain Client ID / Secret)</h2>
<p>Very first step to call any Google API including Google Analytics is to create Google API Project and register OAuth App to obtain <strong>Client ID</strong> and <strong>Client Secret</strong>. If you dont want to go through this hassle and start easy way then ZappySys offers Inbuilt Default App on <strong>OAuth</strong> Connection UI but <strong>we strongly recommend</strong> you create your own app rather than using Default App because in Default App API call limit is shared by many. Your data is never shared with ZappySys in any case even you use Default App.</p>
<p>Here is how to <a href="https://zappysys.com/blog/register-google-oauth-application-get-clientid-clientsecret/">create API Project to call Google API</a>. Once you create Google API Project make sure you <strong>enable</strong> <strong>Google Analytics API</strong>.</p>
<p>So once you have <strong>Client ID</strong> and <strong>Client Secret</strong> we can move forward to the next step.</p>
<h2>Loading Google Analytics data into SQL Server</h2>
<p>In our previous article we saw in depth general idea on how to <a href="https://zappysys.com/blog/import-rest-api-json-sql-server/">import REST API data in SQL Server (T-SQL Script)</a> without relying on any ETL tools.  Now lets look at step by step on <strong>how to load Google Analytics data into SQL Server</strong>.</p>
<p>In this example, our goal is to extract a Google Analytics report which shows average session duration and new users count by date (For last 30 days).</p>
<h3>Setup ZappySys Data Gateway</h3>
<p>Very first step to access any REST API Data inside SQL Server is to configure ZappySys Data Gateway. We covered this in <a href="https://zappysys.com/blog/import-rest-api-json-sql-server/" target="_blank" rel="noopener">previous article</a>.  But here are high level steps for initial setup of Data Gateway.</p>
<ol>
<li>Search for Gateway in Start menu and  Select ZappySys Data Gateway
<div id="attachment_5283" style="width: 410px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5283" class="size-full wp-image-5283" src="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png" alt="Open ZappySys Data Gateway" width="400" height="315" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png 400w, https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway-300x236.png 300w" sizes="(max-width: 400px) 100vw, 400px" /></a><p id="caption-attachment-5283" class="wp-caption-text">Open ZappySys Data Gateway</p></div></li>
<li>Create <strong>new User</strong> in Data gateway on Users tab. Enter username and password (we will use this when we create Linked Server) . <strong><strong><strong>Check Admin Option</strong></strong></strong>
<div id="attachment_5285" style="width: 426px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-user.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5285" class="size-full wp-image-5285" src="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-user.png" alt="Add Data Gateway User" width="416" height="444" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-user.png 416w, https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-user-281x300.png 281w" sizes="(max-width: 416px) 100vw, 416px" /></a><p id="caption-attachment-5285" class="wp-caption-text">Add Data Gateway User</p></div></li>
</ol>
<h3>Setup Google Analytics API Data Source in Gateway / ODBC</h3>
<p>Once gateway user is setup, now lets create a new Data Source for Google Analytics API. In this section we will talk how to create data source in gateway but most instructions can be used to create data source in ODBC too. At the end of this article we explained how to Launch ODBC Datasource UI. Step#1 and 2 are only different, all other steps same in ODBC DSN creation.</p>
<ol>
<li>Click Add Data Source option (Select Native &#8211; JSON Driver )
<div id="attachment_5284" style="width: 568px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5284" class="size-full wp-image-5284" src="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source.png" alt="Add Gateway Data Source (Native JSON Driver)" width="558" height="533" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source.png 558w, https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source-300x287.png 300w" sizes="(max-width: 558px) 100vw, 558px" /></a><p id="caption-attachment-5284" class="wp-caption-text">Add Gateway Data Source (Native JSON Driver)</p></div></li>
<li>Click Edit to configure data source
<div id="attachment_5440" style="width: 572px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-2-2.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5440" class="size-full wp-image-5440" src="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-2-2.png" alt="Edit Gateway Data Source Settings" width="562" height="385" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-2-2.png 562w, https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-2-2-300x206.png 300w" sizes="(max-width: 562px) 100vw, 562px" /></a><p id="caption-attachment-5440" class="wp-caption-text">Edit Gateway Data Source Settings</p></div></li>
<li>Now lets configure Driver settings.  Click on Load Connection String button.
<div id="attachment_7024" style="width: 996px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/05/zappysys-driver-load-connectionstring.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7024" class="size-full wp-image-7024" src="https://zappysys.com/blog/wp-content/uploads/2019/05/zappysys-driver-load-connectionstring.png" alt="Load ZappySys Driver ConnectionString to configure UI" width="986" height="454" srcset="https://zappysys.com/blog/wp-content/uploads/2019/05/zappysys-driver-load-connectionstring.png 986w, https://zappysys.com/blog/wp-content/uploads/2019/05/zappysys-driver-load-connectionstring-300x138.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/05/zappysys-driver-load-connectionstring-768x354.png 768w" sizes="(max-width: 986px) 100vw, 986px" /></a><p id="caption-attachment-7024" class="wp-caption-text">Load ZappySys Driver ConnectionString to configure UI</p></div></li>
<li>Enter the following ConnectionString to get started with predefined settings.<br />
Change ids (<strong>111223344</strong> to your own Profile ID in <strong>DataPath URL</strong>). Other URL Parameters explained in next section.<br />
<pre class="crayon-plain-tag">DRIVER={ZappySys JSON Driver};
DataPath='https://www.googleapis.com/analytics/v3/data/ga?ids=ga:11223344&amp;start-date=30daysAgo&amp;end-date=yesterday&amp;metrics=ga:avgSessionDuration,ga:newUsers&amp;dimensions=ga:date';
DataConnectionType=OAuth;
ScopeSeparator='{space}';
Scope='https://www.googleapis.com/auth/analytics https://www.googleapis.com/auth/analytics.readonly';
ServiceProvider=Google;
Filter='$.rows[*]';
ArrayTransformType=TransformSimpleTwoDimensionalArray;
ArrayTransColumnNameFilter='$.columnHeaders[*].name';
RequestMethod='GET';
NextUrlAttributeOrExpr='$.nextLink';
ClientId='xxxxxxxxxxxx';
ClientSecret='yyyyyyyyyyyyyy';
UseCustomApp='True'</pre>
&nbsp;</li>
<li>URL used in DataPath is most important (parameters explained below) . You can use   <a href="https://ga-dev-tools.appspot.com/query-explorer/" target="_blank" rel="noopener">Query Explorer Tool here</a> to build same URL.<br />
<pre class="crayon-plain-tag">https://www.googleapis.com/analytics/v3/data/ga?ids=ga:11223344&amp;start-date=30daysAgo&amp;end-date=yesterday&amp;metrics=ga:avgSessionDuration,ga:newUsers&amp;dimensions=ga:date</pre>
<strong><span style="text-decoration: underline;">Parameters Explained </span><br />
</strong><br />
Here is some required parameters used in above REST API URL.<br />
<strong>ids</strong>=ga:11223344<br />
This is your Profile ID which you like to extract.  <a href="https://developers.google.com/analytics/devguides/reporting/core/v3/reference#ids">Read more</a><strong><br />
start-date</strong>=30daysAgo<br />
This can be yyyy-MM-dd or some other some predefined date keywords (e.g today, yesterday 10daysAgo). <a href="https://developers.google.com/analytics/devguides/reporting/core/v3/reference#startDate" target="_blank" rel="noopener">Read more</a>.<br />
<strong>end-date</strong>=yesterday<br />
Same as above<br />
<strong>metrics</strong>=ga:avgSessionDuration,ga:newUsers<br />
This can be comma separated list of metrics you like to extract (max 10). <a href="https://developers.google.com/analytics/devguides/reporting/core/v3/reference#metrics" target="_blank" rel="noopener">Read more</a>.<br />
<strong>dimensions</strong>=ga:date<br />
This can be comma separated list of metrics you like to extract (max 7). <a href="https://developers.google.com/analytics/devguides/reporting/core/v3/reference#dimensions" target="_blank" rel="noopener">Read more</a>.</li>
<li>Now its time to configure <a href="https://zappysys.com/blog/rest-api-authentication-with-oauth-2-0-using-ssis/" target="_blank" rel="noopener">OAuth</a> settings. Click on Configure Connection. Enter Client ID and Client Secret Obtained in the previous section (<a href="https://zappysys.com/blog/register-google-oauth-application-get-clientid-clientsecret/" target="_blank" rel="noopener">see here</a>) and then click Generate Token as below.
<div id="attachment_7043" style="width: 1006px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/05/configure-google-analytics-api-driver-data-source-oauth.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7043" class="size-full wp-image-7043" src="https://zappysys.com/blog/wp-content/uploads/2019/05/configure-google-analytics-api-driver-data-source-oauth.png" alt="Configure Google API Data Source / DSN (Google Analytics API Example)" width="996" height="870" srcset="https://zappysys.com/blog/wp-content/uploads/2019/05/configure-google-analytics-api-driver-data-source-oauth.png 996w, https://zappysys.com/blog/wp-content/uploads/2019/05/configure-google-analytics-api-driver-data-source-oauth-300x262.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/05/configure-google-analytics-api-driver-data-source-oauth-768x671.png 768w" sizes="(max-width: 996px) 100vw, 996px" /></a><p id="caption-attachment-7043" class="wp-caption-text">Configure Google API Data Source / DSN (Google Analytics API Example)</p></div></li>
<li>Thats it now can click on Preview Tab and run sample query like below.<br />
<pre class="crayon-plain-tag">select * from $</pre>
<strong>&#8211;OR&#8211;</strong><br />
(Select Table name from dropdown and generate default query and then you can add alias , remove unwanted columns)<br />
<pre class="crayon-plain-tag">SELECT 
"ga:date" date, 
"ga:avgSessionDuration" avgSessionDuration,
"ga:newUsers" newUsers
FROM "rows"</pre>
<strong>&#8211;OR&#8211;</strong><br />
(Type custom query with your own URL generated <a href="https://ga-dev-tools.appspot.com/query-explorer/" target="_blank" rel="noopener">from here</a>, Change Profile ID &#8211; from 11223344 to your own id)<br />
<pre class="crayon-plain-tag">SELECT * FROM $
WITH(
	 Src='https://www.googleapis.com/analytics/v3/data/ga?ids=ga:11223344&amp;start-date=30daysAgo&amp;end-date=yesterday&amp;metrics=ga:avgSessionDuration,ga:newUsers&amp;dimensions=ga:date'
	,IncludeParentColumns='False'
)</pre>
<a href="https://zappysys.com/blog/wp-content/uploads/2019/05/query-google-analytics-data.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-7045" src="https://zappysys.com/blog/wp-content/uploads/2019/05/query-google-analytics-data.png" alt="" width="652" height="608" srcset="https://zappysys.com/blog/wp-content/uploads/2019/05/query-google-analytics-data.png 652w, https://zappysys.com/blog/wp-content/uploads/2019/05/query-google-analytics-data-300x280.png 300w" sizes="(max-width: 652px) 100vw, 652px" /></a></li>
</ol>
<h3>Create Linked Server in SQL Server using T-SQL Script</h3>
<p>Once our Gateway Data Source is configured we can now move to SQL Server Part to define Linked Server.</p>
<p>Here is how you can define linked server to access Google Analytics Data inside SQL Server. There are two ways to create Linked Server (1)  via T-SQL script (2) via SSMS UI)</p>
<p>Here is how to create using Script.</p><pre class="crayon-plain-tag">USE [master]
GO

--drop existing linked server for same name if already found
EXEC master.dbo.sp_dropserver @server=N'GOOGLE_ANALYTICS_LS', @droplogins='droplogins'
GO

EXEC master.dbo.sp_addlinkedserver 
	@server = N'GOOGLE_ANALYTICS_LS', 
	@srvproduct=N'', 
	@provider=N'SQLNCLI', 
	@datasrc=N'localhost,5000', --this is host name and port number where  ZappySys Data Gateway is running
	@catalog=N'ZS-GA' --this must be same name as defined on Data Source tab Grid on ZappySys Data Gateway

EXEC master.dbo.sp_addlinkedsrvlogin 
	@rmtsrvname=N'GOOGLE_ANALYTICS_LS',
	@useself=N'False',
	@locallogin=NULL,
	@rmtuser=N'SOME-GATEWAY-USER', -- user name created on ZappySys Data Gateway
	@rmtpassword='SOME-GATEWAY-PASSWORD' -- password for ZappySys Data Gateway user
GO</pre><p>
&nbsp;</p>
<h3>Create Microsoft SQL Server Linked Server using SSMS UI</h3>
<div class="content_block" id="custom_post_widget-5289">Once you configured data source in Gateway, we can now setup Linked Server in SQL Server to query API data.
<ol style="margin-left: 10px;">
 	<li>Assuming you have installed SQL Server and SSMS. If not then get both for FREE from here: <a href="https://www.microsoft.com/en-us/sql-server/sql-server-editions-express">Get SQL Server Express</a> and  <a href="https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms" target="_blank" rel="noopener">Get SSMS</a></li>
 	<li>Open SSMS and connect to SQL Server.</li>
 	<li>Go to Root &gt; Server Objects &gt; Linked Servers node. Right click and click <strong>New Linked Server...
</strong>
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/03/create-new-linked-server-ssms.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/03/create-new-linked-server-ssms.png" alt="Add Linked Server in SQL Server" />
</a>
<p class="wp-caption-text">Add Linked Server in SQL Server</p>

</div></li>
 	<li> Now enter linked server name, select Provider as SQL Native Client</li>
 	<li>Enter data source as <strong><span class="lang:default decode:true crayon-inline">GatewayServerName,PORT_NUMBER</span></strong> where server name is where ZappySys Gateway is running (Can be same as SQL Server machine or remote machine). Default PORT_NUMBER is 5000 but confirm on Data gateway &gt; General tab incase its different.</li>
 	<li>Enter Catalog Name. This must match name from Data gateway Data sources grid &gt; Name column
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/ssms-sql-server-configure-linked-server-2.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/ssms-sql-server-configure-linked-server-2.png" alt="Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection" />
</a>
<p class="wp-caption-text">Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection</p>
</div>
<div style="color: #31708f;background-color: #d9edf7;border-color: #bce8f1;padding: 15px;margin-bottom: 20px;border: 1px solid transparent;border-radius: 4px;">
<strong>INFO:</strong><br/>
<ul>
    <li>
      For <strong>SQL Server 2012, 2014, 2016, 2017, and 2019</strong>, use the <em>SQL Server Native Client 11.0</em> as the Provider.
    </li>
    <li>
      For <strong>SQL Server 2022 or higher</strong>, use the <em>Microsoft OLE DB Driver for SQL Server</em> as the Provider.
    </li>
  </ul>
</div></li>
 	<li>Click on Security Tab and select last option "<strong>Be made using this security context</strong>". Enter your gateway user account here.</li>
<li>
        <p>Optional: Under the Server Options Tab, Enable <b>RPC</b> and <b>RPC Out</b> and Disable Promotion of Distributed Transactions<b>(MSDTC)</b>.</p>
		<div class="wp-caption alignnone">
			<img decoding="async" class="block margin-bottom-10 img-thumbnail" src="https://zappysys.com/blog/wp-content/uploads/2018/11/linked-server-options-rpc-msdtc.png" title="RPC and MSDTC Settings" alt="RPC and MSDTC Settings" />
			<p class="wp-caption-text">RPC and MSDTC Settings</p>
		</div>
        <hr />
        <p>
            You need to enable RPC Out if you plan to use <b><i>EXEC(...) AT [MY_LINKED_SERVER_NAME]</i></b> rather than OPENQUERY.
            <br />
            If don't enabled it, you will encounter the <i>'Server "MY_LINKED_SERVER_NAME" is not configured for RPC'</i> error.
        </p>
        <p>
            Query Example:
            <code class="sql">EXEC('Select * from Products') AT [MY_LINKED_SERVER_NAME]</code>
        </p>
        <hr />
        <p>
            If you plan to use <b><i>'INSERT INTO...EXEC(....) AT [MY_LINKED_SERVER_NAME]'</i></b> in that case you need to Disable Promotion of Distributed Transactions(MSDTC).
            <br />
            If don't disabled it, you will encounter the <i>'The operation could not be performed because OLE DB provider "SQLNCLI11/MSOLEDBSQL" for linked server "MY_LINKED_SERVER_NAME" was unable to begin a distributed transaction.'</i> error.
        </p>
        <p>
            Query Example:
<pre class="">Insert Into dbo.Products 
EXEC('Select * from Products') AT [MY_LINKED_SERVER_NAME]</pre>
        </p>
        <hr />
</li>
 	<li>Click OK to save Linked Server</li>
 	<li>In SSMS execute below SQL query to test your connectivity.
<pre class="">SELECT * FROM OPENQUERY( MY_LINKED_SERVER_NAME, 'SELECT * FROM $')</pre>
--OR--
<pre class="">SELECT * FROM OPENQUERY( MY_LINKED_SERVER_NAME, 
'SELECT * FROM $
 WITH (Src=''https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json''
 ,Filter=''$.value[*]''
 ,DataFormat=''OData''
)');</pre>
</li>
 	<li>Here is the preview after you run some REST API query in SQL Server. Notice that you can override default configuration by supplying <a href="https://zappysys.com/onlinehelp/odbc-powerpack/scr/json-odbc-driver-connectionstring.htm" target="_blank" rel="noopener">many parameters</a> in WITH clause (second query example in screenshot).
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/query-rest-api-sql-server-linked-server-openquery-zappysys-data-gateway.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/query-rest-api-sql-server-linked-server-openquery-zappysys-data-gateway.png" alt="SSMS Output - Query REST API via Linked Server OPENQUERY statement (Connect to ZappySys Data Gateway)" />
</a>
<p class="wp-caption-text">SSMS Output - Query REST API via Linked Server OPENQUERY statement (Connect to ZappySys Data Gateway)</p>

</div></li>
 	<li>You can wrap your queries inside View or wrap inside Stored procedure to parameterize. Here is an example of create view which calls REST API queries. Below View can be consumed like a normal table from any Tools or Programming Language which supports connectivity to SQL Server.
<pre class="lang:tsql decode:true ">CREATE VIEW dbo.vwApiInvoices 
AS 
/*Call REST API inside SQL Server View*/
SELECT * FROM OPENQUERY( LS , 
'SELECT * FROM $
WITH (Src=''https://services.odata.org/V3/Northwind/Northwind.svc/Invoices?$format=json''
	 ,Filter=''$.value[*]''
	 ,DataFormat=''OData''
)');

GO
</pre>
&nbsp;</li>
 	<li>Notice in above approach if you parameterize Stored Procedure then <a href="https://zappysys.com/blog/create-csv-list-sql-server-table-columns-datatypes/" target="_blank" rel="noopener">check this article to understand Dynamic Metadata</a>.</li>
 	<li>That's it. We are now ready to move forward with more interesting things in next section.</li>
</ol></div>
<h3>Import Google Analytics Data into SQL Server Table (T-SQL Code)</h3>
<p>Now lets see how to run sample query to import Google Analytics Data into SQL Server. Notice that how we have escaped quotes in <strong>OPENQUERY</strong>.<br />
<strong>NOTE:</strong> Change id 11223344 with your own Id (<a href="https://ga-dev-tools.appspot.com/query-explorer/" target="_blank" rel="noopener">use this tool</a> to create URL)</p><pre class="crayon-plain-tag">select * into GaApiLoad from OPENQUERY([GOOGLE_ANALYTICS_LS] ,
'SELECT * FROM "rows"
WITH 
 (
   SRC=''https://www.googleapis.com/analytics/v3/data/ga?ids=ga:11223344&amp;start-date=30daysAgo&amp;end-date=yesterday&amp;metrics=ga:avgSessionDuration,ga:newUsers&amp;dimensions=ga:date''
  ,IncludeParentColumns=''False''
 )
')
select * from GaApiLoad</pre><p>
<div id="attachment_7046" style="width: 649px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/05/import-google-analytics-data-into-sql-server.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7046" class="size-full wp-image-7046" src="https://zappysys.com/blog/wp-content/uploads/2019/05/import-google-analytics-data-into-sql-server.png" alt="Import Google Analytics Data into SQL Server Table (using T-SQL Code)" width="639" height="538" srcset="https://zappysys.com/blog/wp-content/uploads/2019/05/import-google-analytics-data-into-sql-server.png 639w, https://zappysys.com/blog/wp-content/uploads/2019/05/import-google-analytics-data-into-sql-server-300x253.png 300w" sizes="(max-width: 639px) 100vw, 639px" /></a><p id="caption-attachment-7046" class="wp-caption-text">Import Google Analytics Data into SQL Server Table (using T-SQL Code)</p></div>
<h2>Expose Google Analytics Data as View</h2>
<p>To make it simple you can expose above query as SQL Server views so you can access them from any Reporting / ETL Tools.</p><pre class="crayon-plain-tag">CREATE VIEW vw_Google_Analytics_BounceRate_PageViews_Last30Days
AS
--change ids to your own Profile ID
select * from OPENQUERY([GOOGLE_ANALYTICS_LS] ,
'SELECT * FROM "rows"
WITH 
 (
   SRC=''https://www.googleapis.com/analytics/v3/data/ga?ids=ga:11223344&amp;start-date=2019-04-01&amp;end-date=2019-04-30&amp;metrics=ga:bounceRate,ga:uniquePageviews&amp;dimensions=ga:date''
  ,IncludeParentColumns=''False''
 )
')
GO</pre><p>
<h2>Making things Dynamic using Stored Procedure with Parameters</h2>
<p>Now let&#8217;s make few things dynamic. We will change above query so we can pass Id, Dimensions and Metrics as parameters.</p>
<p>Run below script to Create a stored proc and fetch google analytics data in SQL Server.</p><pre class="crayon-plain-tag">use MyDatabase
go
create proc usp_GoogleAnalyticsData
	@ids varchar(1000),
	@startDate varchar(50)='30daysAgo',
	@endDate varchar(50)='yesterday',
	@metrics varchar(200)='ga:avgSessionDuration,ga:newUsers',
	@dimensions varchar(200)='ga:date'	
as

declare @sql varchar(4000)

set @sql='select * from OPENQUERY([GOOGLE_ANALYTICS_LS] ,
''SELECT * FROM "rows"
WITH 
 (
   SRC=''''https://www.googleapis.com/analytics/v3/data/ga?ids=ga:' + @ids 
   +'&amp;start-date='+ @startDate 
   +'&amp;end-date='+ @endDate 
   +'&amp;metrics='+ @metrics 
   +'&amp;dimensions='+ @dimensions 
   +'''''
  ,IncludeParentColumns=''''False''''
 )
'')'

print @sql
execute(@sql)

go

--Example: query google analytics data
exec usp_GoogleAnalyticsData 
	@ids='11223344',  --Change this ID - Obtain from here https://ga-dev-tools.appspot.com/query-explorer/
	@startDate ='30daysAgo',  --or like this 2019-04-01
	@endDate   ='yesterday', --or like this 2019-04-30
	@dimensions='ga:date', 
	@metrics   ='ga:bounceRate,ga:uniquePageviews'</pre><p>
<h3>Insert Google Analytics Data into table (Save Stored Procedure Output)</h3>
<p>Now what if you like to save Stored Proc output into a table? Well for that you must create table with same structure as stored proc output and then use <strong>INSERT INTO</strong> sql like below.</p><pre class="crayon-plain-tag">--import google analytics data in a table
if(object_id('GaDataLoad') is not null)
	drop table GaDataLoad
create table GaDataLoad([Date] date, BounceRate numeric(10,5), PageViews numeric(10,5))  

insert into GaDataLoad
exec usp_GoogleAnalyticsData 
	@ids='11223344',  --Change this ID - Obtain from here https://ga-dev-tools.appspot.com/query-explorer/
	@startDate ='30daysAgo',  --or like this 2019-04-01
	@endDate   ='yesterday', --or like this 2019-04-30
	@dimensions='ga:date', 
	@metrics='ga:bounceRate,ga:uniquePageviews'

select * from GaDataLoad</pre><p>
&nbsp;</p>
<h2>Performance Tips / Handling data errors due to missing rows</h2>
<p>By default ZappySys API Drivers sends minimum 2 API requests. First one to fetch metadata and second, third&#8230; for Data. There will be a time when you wont have any data and it may throw error about no records found because it fails to parse metadata. You can avoid such issue by supplying metadata before hand so you can avoid expensive API calls. <a href="https://zappysys.com/blog/caching-metadata-odbc-drivers-performance/" target="_blank" rel="noopener">Check this article</a> see how you can supply cached metadata in your SQL Query as below. This will avoid Metadata call and speedup significantly. It will also avoid errors due to no rows found for specified criteria.</p><pre class="crayon-plain-tag">select * from OPENQUERY([GOOGLE_ANALYTICS_LS] ,
'SELECT * FROM "rows"
WITH 
 (
   SRC=''https://www.googleapis.com/analytics/v3/data/ga?ids=ga:11223344&amp;start-date=30daysAgo&amp;end-date=yesterday&amp;metrics=ga:bounceRate,ga:uniquePageviews&amp;dimensions=ga:date''
  ,IncludeParentColumns=''False''
  ,Meta=''[ 
     {"Name": "ga:date","Type": "String", "Length": 16 },
     {"Name": "ga:bounceRate", "Type": "String", "Length": 36 },
     {"Name": "ga:uniquePageviews", "Type": "String", "Length": 10 }
    ]''
 )
')</pre><p>
&nbsp;</p>
<h2>ODBC Connection &#8211; Google Analytics Data in Other Apps (e.g. SSRS / Power BI / Excel / Tableau)</h2>
<p>So far we have talked accessing data inside SQL Server using Data Gateway Approach but what if you like to access in other apps ? Well you have three options.</p>
<ol>
<li>Use Microsoft SQL Server Driver to call Linked Server Queries (OPENQUERY approach we saw earlier)</li>
<li>Access Google Analytics Data using ODBC connectivity</li>
<li>Use Microsoft SQL Server Driver to send direct SQL queries to Gateway (Bypass Linked Server &#8211; Use inner SQL query without OPENQUERY in this case)</li>
</ol>
<h3><strong>Method-1 : Linked Server Approach</strong></h3>
<p>First approach most likely works in all cases because most apps will support connecting to SQL Server using OLEDB / ADO.net / ODBC / JDBC Drivers. So calling SQL Queries which uses Linked Server (i.e. OPENQUERY statement)  is advisable.</p>
<h3><strong>Method-2 : ODBC Driver Approach</strong></h3>
<p>However in some cases this may not be possible (e.g. You don&#8217;t have SQL Server inhouse or you don&#8217;t want to rely on SQL Server to access API). In such case you can use ODBC connectivity in your app. Since ODBC is widely adopted standard most app out there (Except JAVA apps) should support ODBC Drivers. If you like to use this approach then create ODBC DSN rather than Data Gateway Data source and use it in your Reporting / ETL / Custom Apps.</p>
<p>&nbsp;</p>
<div id="attachment_6213" style="width: 404px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/01/how-to-open-odbc-data-source-administrator-2.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-6213" class="wp-image-6213 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/01/how-to-open-odbc-data-source-administrator-2.png" alt="Open ODBC Data Sources (Create DSN)" width="394" height="542" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/how-to-open-odbc-data-source-administrator-2.png 394w, https://zappysys.com/blog/wp-content/uploads/2019/01/how-to-open-odbc-data-source-administrator-2-218x300.png 218w" sizes="(max-width: 394px) 100vw, 394px" /></a><p id="caption-attachment-6213" class="wp-caption-text">Open ODBC Data Sources (Create DSN)</p></div>
<div id="attachment_3993" style="width: 1067px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-user-dsn-select-driver.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3993" class="size-full wp-image-3993" src="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-user-dsn-select-driver.png" alt="ODBC User DSN Tab: Add new Driver Screen" width="1057" height="422" srcset="https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-user-dsn-select-driver.png 1057w, https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-user-dsn-select-driver-300x120.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-user-dsn-select-driver-768x307.png 768w, https://zappysys.com/blog/wp-content/uploads/2018/06/odbc-user-dsn-select-driver-1024x409.png 1024w" sizes="(max-width: 1057px) 100vw, 1057px" /></a><p id="caption-attachment-3993" class="wp-caption-text">ODBC User DSN Tab: Add new Driver Screen</p></div>
<p>&nbsp;</p>
<h3><strong>Method-3 : Direct connection to Data Gateway (By pass Linked Server)</strong></h3>
<p>Last option we suggest for cases like JAVA Apps / Linux / Mac machines where you cannot install ZappySys ODBC Drivers and you dont have option to use SQL Server Linked Server either. In such case you can try to send SQL Queries to Gateway directly using Microsoft SQL Server Compatible Drivers (i.e. ODBC /JDBC). <a href="https://zappysys.com/blog/connect-java-to-rest-api-json-soap-xml/" target="_blank" rel="noopener">See this example</a> how we called API Queries inside JAVA Apps.</p>
<h3>Google Analytics / REST API Integration in various apps</h3>
<div class="content_block" id="custom_post_widget-7051">ZappySys ODBC Drivers built using ODBC standard which is widely adopted by industry for a long time. Which mean the majority of BI Tools / Database Engines / ETL Tools already there will support native / 3rd party ODBC Drivers. Below is the small list of most popular tools / programming languages our Drivers support. If your tool / programming language doesn't appear in the below list, which means we have not documented use case but as long as your tool supports ODBC Standard, our drivers should work fine.

&nbsp;

<img loading="lazy" decoding="async" class="" src="//zappysys.com/images/odbc-powerpack/odbc-powerpack-integration.jpg" alt="ZappySys ODBC Drivers for REST API, JSON, XML - Integrate with Power BI, Tableau, QlikView, QlikSense, Informatica PowerCenter, Excel, SQL Server, SSIS, SSAS, SSRS, Visual Studio / WinForm / WCF, Python, C#, VB.net, PHP. PowerShell " width="750" height="372" />
<table style="valign: top;">
<tbody>
<tr>
<td>
<p style="text-align: center;"><strong>BI / Reporting Tools
Integration</strong></p>
</td>
<td style="text-align: center;"><strong>ETL Tools
Integration
</strong></td>
<td style="text-align: center;"><strong>Programming Languages</strong>
<strong>Integration</strong></td>
</tr>
<tr>
<td>
<ul>
 	<li><a href="https://zappysys.com/blog/howto-import-json-rest-api-power-bi/" target="_blank" rel="noopener">Microsoft Power BI</a></li>
 	<li><a href="https://zappysys.com/blog/import-rest-api-tableau-read-json-soap-xml-csv/">Tableau</a></li>
 	<li><a href="https://zappysys.com/blog/read-rest-api-using-ssrs-reports-call-json-xml-web-service/" target="_blank" rel="noopener">SSRS (SQL Reporting Services)</a></li>
 	<li><a href="https://zappysys.com/blog/qlik-rest-connector-examples-read-json-xml-api/" target="_blank" rel="noopener">QlikView /Qlik Sense</a></li>
 	<li><a href="https://zappysys.com/blog/call-rest-api-in-microstrategy-json-soap-xml/" target="_blank" rel="noopener">MicroStrategy</a></li>
 	<li><a href="https://zappysys.com/blog/import-rest-api-google-sheet-call-appscript-load-json-soap-xml-csv/" target="_blank" rel="noopener">Google Sheet</a></li>
 	<li><a href="https://zappysys.com/blog/import-json-excel-load-file-rest-api/" target="_blank" rel="noopener">Microsoft Excel</a></li>
 	<li><a href="https://zappysys.com/api/integration-hub/rest-api-connector/access?context=connector" target="_blank" rel="noopener">Microsoft Access</a></li>
 	<li>Oracle OBIEE</li>
 	<li>Many more (not in this list).....</li>
</ul>
</td>
<td>
<ul>
 	<li><a href="https://zappysys.com/blog/read-json-informatica-import-rest-api-json-file/" target="_blank" rel="noopener">Informatica PowerCenter</a> (Windows)</li>
 	<li>Informatica Cloud</li>
 	<li>SSIS (SQL Integration Services)</li>
 	<li><a href="https://zappysys.com/blog/import-rest-api-json-sql-server/" target="_blank" rel="noopener">SQL Server</a></li>
 	<li><a href="https://zappysys.com/blog/read-write-rest-api-data-in-talend-json-xml-soap/" target="_blank" rel="noopener">Talend Data Studio</a></li>
 	<li><a href="https://zappysys.com/blog/pentaho-read-rest-api-in-pentaho/" target="_blank" rel="noopener">Pentaho Kettle</a></li>
 	<li>Oracle OBIEE</li>
 	<li>Many more (not in this list).....</li>
</ul>
</td>
<td>
<ul>
 	<li>Visual Studio</li>
 	<li><a href="https://zappysys.com/blog/calling-rest-api-in-c/" target="_blank" rel="noopener">C#</a></li>
 	<li>C++</li>
 	<li><a href="https://zappysys.com/blog/connect-java-to-rest-api-json-soap-xml/" target="_blank" rel="noopener">JAVA</a></li>
 	<li><a href="https://zappysys.com/blog/set-rest-python-client/" target="_blank" rel="noopener">Python</a></li>
 	<li>PHP</li>
 	<li><a href="https://zappysys.com/blog/call-rest-api-powershell-script-export-json-csv/" target="_blank" rel="noopener">PowerShell</a></li>
 	<li><a href="https://zappysys.com/blog/import-rest-api-json-sql-server/" target="_blank" rel="noopener">T-SQL (Using Linked Server)</a></li>
</ul>
</td>
</tr>
</tbody>
</table>
&nbsp;</div>
<p>&nbsp;</p>
<h2>Conclusion</h2>
<p>In this article we explored many ideas of JSON / API integration in SQL Server.  We saw how to create OAuth App for Google API and import Google Analytics data into SQL Server Table without doing any ETL using pure T-SQL code (Query / Views /Stored Procs). You can <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">Download  FREE Trial of ODBC PowerPack</a> and try yourself see how easy it is to query any API inside SQL Server and avoid expensive ETL processes.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The post <a href="https://zappysys.com/blog/import-google-analytics-data-sql-server-reporting-etl/">Import Google Analytics data into SQL Server / Reporting / ETL</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Read data from QuickBooks Online into SQL Server via ODBC Driver</title>
		<link>https://zappysys.com/blog/read-data-from-quickbooks-online-to-sql-server/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Wed, 23 Jan 2019 12:12:20 +0000</pubDate>
				<category><![CDATA[JSON File / REST API Driver]]></category>
		<category><![CDATA[REST API Integration]]></category>
		<category><![CDATA[T-SQL (SQL Server)]]></category>
		<category><![CDATA[json driver]]></category>
		<category><![CDATA[oauth]]></category>
		<category><![CDATA[oauth2]]></category>
		<category><![CDATA[odbc]]></category>
		<category><![CDATA[odbc json driver]]></category>
		<category><![CDATA[quickbooks]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=5133</guid>

					<description><![CDATA[<p>Introduction QuickBooks Online is a well-known Cloud-based Accounting Software. In this post, you will learn how to implement QuickBooks Online API Integration with SQL Server or any other RDBMS (e.g. Oracle, MySQL, Postgresql) using ODBC in few clicks. We will use ODBC JSON / REST API Driver to read data from QuickBooks Online and Load into SQL Server / other targets (Using OAuth [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/read-data-from-quickbooks-online-to-sql-server/">Read data from QuickBooks Online into SQL Server via ODBC Driver</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p><a href="https://zappysys.com/blog/wp-content/uploads/2019/01/QuickBookLogo.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="alignleft wp-image-6399 " src="https://zappysys.com/blog/wp-content/uploads/2019/01/QuickBookLogo.png" alt="QuickBooks Online Logo" width="164" height="164" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/QuickBookLogo.png 225w, https://zappysys.com/blog/wp-content/uploads/2019/01/QuickBookLogo-150x150.png 150w" sizes="(max-width: 164px) 100vw, 164px" /></a>QuickBooks Online is a well-known Cloud-based Accounting Software. In this post, you will learn how to implement <a href="https://developer.intuit.com/docs/00_quickbooks_online/1_get_started/00_get_started" target="_blank" rel="noopener">QuickBooks Online API</a> Integration with SQL Server or any other RDBMS (e.g. Oracle, MySQL, Postgresql) using <strong>ODBC</strong> in few clicks. We will use <a href="https://zappysys.com/products/odbc-powerpack/odbc-json-rest-api-driver/" target="_blank" rel="noopener">ODBC JSON / REST API Driver</a> to read data from QuickBooks Online and Load into SQL Server / other targets (Using OAuth Connection). We will discuss on How to Create an Intuit Developer Account, How to Create QuickBooks Online App for OAuth.</p>
<p>In nutshell, this post will focus on how to call QuickBooks Online API using ODBC.<br />
So let’s get started.</p>
<p>&nbsp;</p>
<h2><span id="Prerequisites">Prerequisites</span></h2>
<p>Before we look into Step-By-Step section to extract and read data from <strong>QuickBooks Online to SQL Server</strong> let’s make sure you met the following requirements.</p>
<ol>
<li>A first requirement will be to SQL Server Database Engine Installed</li>
<li>The second requirement will be SSMS installed</li>
<li>Finally, make sure to have <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> installed.</li>
</ol>
<div class="content_block" id="custom_post_widget-6478"><h2>What is QuickBooks Online</h2>
<b>QuickBooks</b> is an accounting software package developed and marketed by Intuit. QuickBooks products are geared mainly toward small and medium-sized businesses and offer on-premises accounting applications as well as cloud-based versions that accept business payments, manage and pay bills, and payroll functions.
<h2>Getting Started</h2>
In order to start, we will show several examples. ZappySys includes an <a href="https://zappysys.com/products/odbc-powerpack/odbc-json-rest-api-driver/" target="_blank" rel="noopener">ODBC JSON / REST API Driver</a> that will help you to call QuickBooks Online API, read various data from QuickBooks Online with ODBC. To learn more about QuickBooks Online API <a href="https://developer.intuit.com/docs/00_quickbooks_online/1_get_started/00_get_started" target="_blank" rel="noopener">check this help file</a>.

To access QuickBooks Online data using REST API call, you need to create an Intuit Developer Account and then create QuickBooks Online App.
<h3>Create an Intuit Developer Account</h3>
Follow the mentioned steps below to create an Intuit developer account:
<ol>
 	<li>you can visit this site <a class="link-https" title="https://developer.intuit.com" href="https://developer.intuit.com/" target="_blank" rel="noopener">developer.intuit.com</a>, and click on Sign up from the menu bar.</li>
 	<li>A registration form will be opened in a Popup. you can fill up and then click on Create Account.
<div class="wp-caption alignnone">

<a href="https://zappysys.com/blog/wp-content/uploads/2018/09/intuit-developer-account-signup-page-e1551710928190.png" target="_blank" rel="noopener"><img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/09/intuit-developer-account-signup-page-e1551710928190.png" alt="Signup Form: Intuit Developer Account" /></a>
<p class="wp-caption-text">Signup Form: Intuit Developer Account</p>

</div></li>
 	<li>Complete the validation check and click <strong>Continue</strong>.</li>
 	<li>On the confirmation dialog, provide a few details to fill out your profile and click <strong>All set</strong>.</li>
</ol>
<div class="locale-US style-wrap">

Your account is created! You'll automatically be redirected to the <a title="3. Create an app" href="https://developer.intuit.com/docs/00_quickbooks_online/1_get_started/30_create_an_app" target="_blank" rel="internal noopener">app creation page</a> to get coding on your app.
<div class="su-note-inner su-clearfix" style="background-color: #fff4b7;border-color: #fffdf1;color: #333333;padding: 8px">

<strong>Note:</strong>

Choose the user ID of your account carefully. Once an app is created in a given account it cannot be moved to another account or deleted. If you are building apps for a client, we recommend you create a dedicated account for that client that stays with them, leaving them full access.

</div>
<h3>Create a QuickBooks Online App</h3>
Follow the steps below to start creating your QuickBooks Online app.
<ol>
 	<li>From the <a class="link-https" title="https://developer.intuit.com" href="https://developer.intuit.com/" target="_blank" rel="external nofollow noopener">developer</a> portal, click on <strong>My Apps</strong>.</li>
 	<li>after that, Click <strong>Create a new app.
</strong>
<div class="wp-caption alignnone">

<a href="https://zappysys.com/blog/wp-content/uploads/2018/09/create-new-app-intuit-e1551711044554.png" target="_blank" rel="noopener"><img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/09/create-new-app-intuit-e1551711044554.png" alt="Create new App: Select APIS" /></a>
<p class="wp-caption-text">Create a new App: Select APIS</p>

</div></li>
 	<li>Click the <strong>Select APIs</strong> button under Just start coding.</li>
 	<li>Select the APIs you wish to use. This selection can always be changed later via your <a title="Configure app settings" href="https://developer.intuit.com/docs/00_quickbooks_online/4_go_live/30_publish_to_app_store/45_configure_app_settings" target="_blank" rel="internal noopener">app's settings</a>.</li>
 	<li>Your new app opens to its Dashboard tab.</li>
 	<li>Click the <strong>Keys</strong> tab. This is where you can find all keys related to your app.
<div class="wp-caption alignnone">

<a href="https://zappysys.com/blog/wp-content/uploads/2018/09/intuit-myapps-credentials-for-oauth2-e1551711138195.png" target="_blank" rel="noopener"><img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/09/intuit-myapps-credentials-for-oauth2-e1551711138195.png" alt="Intuit App: Client Id,Secret Keys for OAuth Connection" /></a>
<p class="wp-caption-text">Intuit App: Client Id, Secret Keys for OAuth Connection</p>

</div></li>
 	<li>To copy a key or token, click its <strong>Copy</strong> button.</li>
</ol>
Finally, we are ready with an App. Let´s start with an example. In this example, we will show how to retrieve all Invoices data from QuickBooks Online with ODBC.

</div></div>
<h3><span id="Create_ODBC_Native_Zappysys_JSON_Driver_Data_Source"><span id="Create_ODBC_DSN_8211_JSON_Driver">Create ODBC – Native Zappysys JSON Driver Data Source</span></span></h3>
<ol>
<li>To do this, first of all, we will open the ZappySys Data Gateway Configuration:
<div id="attachment_5283" style="width: 410px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5283" class="wp-image-5283 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png" alt="Open ZappySys Data Gateway" width="400" height="315" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png 400w, https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway-300x236.png 300w" sizes="(max-width: 400px) 100vw, 400px" /></a><p id="caption-attachment-5283" class="wp-caption-text">Open ZappySys Data Gateway</p></div></li>
<li>Add the Native &#8211; ZappySys JSON Driver Data source.
<div id="attachment_5284" style="width: 568px" class="wp-caption aligncenter"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5284" class="wp-image-5284 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source.png" alt="Add Gateway Data Source (Native JSON Driver)" width="558" height="533" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source.png 558w, https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source-300x287.png 300w" sizes="(max-width: 558px) 100vw, 558px" /><p id="caption-attachment-5284" class="wp-caption-text">Add Gateway Data Source (Native JSON Driver)</p></div></li>
<li>Now it&#8217;s time to connect with QuickBooks. Let&#8217;s use JSON Driver Data source with the following URL:<br />
<pre class="crayon-plain-tag">https://{RequestURL}/v3/company/{realmID}/query?query={selectStatement}</pre>
here, We have used 3 placeholders<strong>.<br />
* {RequestURL}</strong>is either a SandBox base URL or Production base URL.<br />
<pre class="crayon-plain-tag">Sandbox Base URL: https://sandbox-quickbooks.api.intuit.com
Production Base URL: https://quickbooks.api.intuit.com</pre>
* <strong>{realmID} </strong>is your QuickBooks Online sandbox/production <strong>company ID</strong>.<br />
* <strong>{selectStatement} </strong>can be any query something like <strong>Select * From Invoice (*Note: select statement must be URL encoded first)<br />
For more information on Query, an Invoice Request API <a href="https://developer.intuit.com/docs/api/accounting/invoice">see this</a><br />
</strong>I am using my sandbox URL like this:<br />
<pre class="crayon-plain-tag">https://sandbox-quickbooks.api.intuit.com/v3/company/193514799372394/query?query=SELECT * FROM Invoice STARTPOSITION &lt;%startposition%&gt; MAXRESULTS 1000</pre>
<div id="attachment_10598" style="width: 666px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/read-data-from-quickbooks-online-to-sql-server/reading-data-from-intuit-quickbooks-via-odbc-driver-2/#main"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-10598" class="wp-image-10598 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/01/Reading-data-from-Intuit-QuickBooks-via-ODBC-driver-1.png" alt="" width="656" height="806" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/Reading-data-from-Intuit-QuickBooks-via-ODBC-driver-1.png 656w, https://zappysys.com/blog/wp-content/uploads/2019/01/Reading-data-from-Intuit-QuickBooks-via-ODBC-driver-1-244x300.png 244w" sizes="(max-width: 656px) 100vw, 656px" /></a><p id="caption-attachment-10598" class="wp-caption-text">Setup QuickBooks ODBC-based data source configuration</p></div></li>
<li>Configure the new OAuth Connection for <strong>QuickBooks Online</strong> as below.<br />
Basically, you need to configure the configurations of App on the General tab (i.e. OAuth Provider, Client ID, Client Secret, Scopes, etc.)</p>
<div id="attachment_4776" style="width: 781px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/read-data-quickbooks-online-using-ssis/ssis-oauth-connection-manager-for-intuit-quickbooks-online-api-general-tab/#main" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4776" class="wp-image-4776 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/09/ssis-oauth-connection-manager-for-intuit-quickbooks-online-api-general-tab.png" alt="SSIS OAuth Connection Manager: General Tab Configurations" width="771" height="697" srcset="https://zappysys.com/blog/wp-content/uploads/2018/09/ssis-oauth-connection-manager-for-intuit-quickbooks-online-api-general-tab.png 771w, https://zappysys.com/blog/wp-content/uploads/2018/09/ssis-oauth-connection-manager-for-intuit-quickbooks-online-api-general-tab-300x271.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/09/ssis-oauth-connection-manager-for-intuit-quickbooks-online-api-general-tab-768x694.png 768w" sizes="(max-width: 771px) 100vw, 771px" /></a><p id="caption-attachment-4776" class="wp-caption-text">OAuth Connection Manager: General Tab Configurations</p></div></li>
<li>Most importantly, you also need to Enter your Callback URL in Advanced Tab.
<div id="attachment_4777" style="width: 781px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/read-data-quickbooks-online-using-ssis/ssis-oauth-connection-manager-for-intuit-quickbooks-online-api-advanced-tab/#main" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4777" class="wp-image-4777 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/09/ssis-oauth-connection-manager-for-intuit-quickbooks-online-api-advanced-tab.png" alt="SSIS OAuth Connection Manager: Advanced Tab Configurations" width="771" height="697" srcset="https://zappysys.com/blog/wp-content/uploads/2018/09/ssis-oauth-connection-manager-for-intuit-quickbooks-online-api-advanced-tab.png 771w, https://zappysys.com/blog/wp-content/uploads/2018/09/ssis-oauth-connection-manager-for-intuit-quickbooks-online-api-advanced-tab-300x271.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/09/ssis-oauth-connection-manager-for-intuit-quickbooks-online-api-advanced-tab-768x694.png 768w" sizes="(max-width: 771px) 100vw, 771px" /></a><p id="caption-attachment-4777" class="wp-caption-text">OAuth Connection Manager: Advanced Tab Configurations</p></div></li>
<li>Similarly, you need to check &#8220;<strong>Do not include credentials in header</strong>&#8221;
<div id="attachment_4778" style="width: 781px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/read-data-quickbooks-online-using-ssis/ssis-oauth-connection-manager-for-intuit-quickbooks-online-api-oauth-2-grant-options-tab/#main" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-4778" class="wp-image-4778 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/09/ssis-oauth-connection-manager-for-intuit-quickbooks-online-api-oauth-2-grant-options-tab.png" alt="SSIS OAuth Connection Manager: OAuth2 Grant Options Tab Configurations" width="771" height="697" srcset="https://zappysys.com/blog/wp-content/uploads/2018/09/ssis-oauth-connection-manager-for-intuit-quickbooks-online-api-oauth-2-grant-options-tab.png 771w, https://zappysys.com/blog/wp-content/uploads/2018/09/ssis-oauth-connection-manager-for-intuit-quickbooks-online-api-oauth-2-grant-options-tab-300x271.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/09/ssis-oauth-connection-manager-for-intuit-quickbooks-online-api-oauth-2-grant-options-tab-768x694.png 768w" sizes="(max-width: 771px) 100vw, 771px" /></a><p id="caption-attachment-4778" class="wp-caption-text">OAuth Connection Manager: OAuth2 Grant Options Tab Configurations</p></div></li>
<li>Click on Generate Token button to Generate token and then click on Test Connection button and click on OK to save the connection manager configurations settings.
<div id="attachment_6415" style="width: 781px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/read-data-from-quickbooks-online-to-sql-server/odbc-quickbooks-oauth-test/#main" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-6415" class="wp-image-6415 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-quickbooks-oauth-test.png" alt="" width="771" height="738" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-quickbooks-oauth-test.png 771w, https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-quickbooks-oauth-test-300x287.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-quickbooks-oauth-test-768x735.png 768w" sizes="(max-width: 771px) 100vw, 771px" /></a><p id="caption-attachment-6415" class="wp-caption-text">Generate Token and Test Connection</p></div></li>
<li>Let&#8217;s continue on, and enable pagination by configuring it like in the image below in the <em>Pagination</em> tab. In the <em>Page Num Indicator</em> field input this value: <code>&lt;%startposition%&gt;</code> Then set <em>Increment By</em> value to a maximum number of results possible: <code>1000</code><a href="https://zappysys.com/blog/wp-content/uploads/2019/01/Pagination-reading-data-from-Intuit-QuickBooks-via-ODBC-driver.png"><br />
</a></p>
<div id="attachment_10595" style="width: 668px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/read-data-from-quickbooks-online-to-sql-server/pagination-reading-data-from-intuit-quickbooks-via-odbc-driver/#main"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-10595" class="wp-image-10595 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/01/Pagination-reading-data-from-Intuit-QuickBooks-via-ODBC-driver.png" alt="" width="658" height="508" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/Pagination-reading-data-from-Intuit-QuickBooks-via-ODBC-driver.png 658w, https://zappysys.com/blog/wp-content/uploads/2019/01/Pagination-reading-data-from-Intuit-QuickBooks-via-ODBC-driver-300x232.png 300w" sizes="(max-width: 658px) 100vw, 658px" /></a><p id="caption-attachment-10595" class="wp-caption-text">Configuring pagination to get QuickBooks all rows in ODBC JSON-based driver data source</p></div></li>
<li>Finally, now using Code Generator we will generate the query.
<div id="attachment_6416" style="width: 766px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/read-data-from-quickbooks-online-to-sql-server/odbc-json-driver-generate-quickbooks-query/#main" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-6416" class="wp-image-6416 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-generate-quickbooks-query.png" alt="odbc-json-driver-generate-quickbooks-query" width="756" height="432" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-generate-quickbooks-query.png 756w, https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-generate-quickbooks-query-300x171.png 300w" sizes="(max-width: 756px) 100vw, 756px" /></a><p id="caption-attachment-6416" class="wp-caption-text">Generate Query</p></div></li>
</ol>
<h3>Load QuickBooks Invoices data in MS SQL Server</h3>
<div class="content_block" id="custom_post_widget-6457">Once you configured the data source in Gateway, we can now setup Linked Server in SQL Server to query API data.
<ol style="margin-left: 10px;">
 	<li>Assuming you have installed SQL Server and SSMS. If not then get both for FREE from here: <a href="https://www.microsoft.com/en-us/sql-server/sql-server-editions-express" target="_blank" rel="noopener">Get SQL Server Express</a> and  <a href="https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms" target="_blank" rel="noopener">Get SSMS</a></li>
 	<li>Open SSMS and connect to SQL Server.</li>
 	<li>Go to Root &gt; Server Objects &gt; Linked Servers node. Right click and click <strong>New Linked Server...</strong>
<div class="wp-caption alignnone">

<a href="https://i1.wp.com/zappysys.com/blog/wp-content/uploads/2018/03/create-new-linked-server-ssms.png?ssl=1" target="_blank" rel="noopener"><img loading="lazy" decoding="async" src="https://i1.wp.com/zappysys.com/blog/wp-content/uploads/2018/03/create-new-linked-server-ssms.png?w=720&amp;ssl=1" alt="Add Linked Server in SQL Server" width="420" height="262" /></a>
<p class="wp-caption-text">Add Linked Server in SQL Server</p>

</div></li>
 	<li> Now enter the linked server name, select Provider as SQL Native Client</li>
 	<li>Enter data source as <strong><span class="lang:default decode:true crayon-inline">GatewayServerName, PORT_NUMBER</span></strong> where server name is where ZappySys Gateway is running (Can be same as SQL Server machine or remote machine). Default PORT_NUMBER is 5000 but confirm on Data gateway &gt; General tab in case its different.</li>
 	<li>Enter Catalog Name. This must match name from Data gateway Data sources grid &gt; Name column
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/ssms-sql-server-configure-linked-server-2.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/ssms-sql-server-configure-linked-server-2.png" alt="Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection" />
</a>
<p class="wp-caption-text">Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection</p>
</div>
<div style="color: #31708f;background-color: #d9edf7;border-color: #bce8f1;padding: 15px;margin-bottom: 20px;border: 1px solid transparent;border-radius: 4px;">
<strong>INFO:</strong><br/>
<ul>
    <li>
      For <strong>SQL Server 2012, 2014, 2016, 2017, and 2019</strong>, use the <em>SQL Server Native Client 11.0</em> as the Provider.
    </li>
    <li>
      For <strong>SQL Server 2022 or higher</strong>, use the <em>Microsoft OLE DB Driver for SQL Server</em> as the Provider.
    </li>
  </ul>
</div></li>
 	<li>Click on Security Tab and select last option "<strong>Be made using this security context</strong>". Enter your gateway user account here.</li>
<li>
        <p>Optional: Under the Server Options Tab, Enable <b>RPC</b> and <b>RPC Out</b> and Disable Promotion of Distributed Transactions<b>(MSDTC)</b>.</p>
		<div class="wp-caption alignnone">
			<img decoding="async" class="block margin-bottom-10 img-thumbnail" src="https://zappysys.com/blog/wp-content/uploads/2018/11/linked-server-options-rpc-msdtc.png" title="RPC and MSDTC Settings" alt="RPC and MSDTC Settings" />
			<p class="wp-caption-text">RPC and MSDTC Settings</p>
		</div>
        <hr />
        <p>
            You need to enable RPC Out if you plan to use <b><i>EXEC(...) AT [MY_LINKED_SERVER_NAME]</i></b> rather than OPENQUERY.
            <br />
            If don't enabled it, you will encounter the <i>'Server "MY_LINKED_SERVER_NAME" is not configured for RPC'</i> error.
        </p>
        <p>
            Query Example:
            <code class="sql">EXEC('Select * from Products') AT [MY_LINKED_SERVER_NAME]</code>
        </p>
        <hr />
        <p>
            If you plan to use <b><i>'INSERT INTO...EXEC(....) AT [MY_LINKED_SERVER_NAME]'</i></b> in that case you need to Disable Promotion of Distributed Transactions(MSDTC).
            <br />
            If don't disabled it, you will encounter the <i>'The operation could not be performed because OLE DB provider "SQLNCLI11/MSOLEDBSQL" for linked server "MY_LINKED_SERVER_NAME" was unable to begin a distributed transaction.'</i> error.
        </p>
        <p>
            Query Example:
<pre class="">Insert Into dbo.Products 
EXEC('Select * from Products') AT [MY_LINKED_SERVER_NAME]</pre>
        </p>
        <hr />
</li>
 	<li>Click OK to save Linked Server</li>
 	<li>In SSMS execute below SQL query to test your connectivity.
<pre class="">SELECT * FROM OPENQUERY( MY_LINKED_SERVER_NAME, 'SELECT * FROM $')</pre>
</li>
 	<li>Here is the preview after you run some REST API query in SQL Server. Notice that you can override default configuration by supplying <a href="https://zappysys.com/onlinehelp/odbc-powerpack/scr/json-odbc-driver-connectionstring.htm" target="_blank" rel="noopener">many parameters</a> in WITH clause (second query example in the screenshot).
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc_json_driver__api_query_data_in_mssqlserver.png" target="_blank" rel="noopener">
<img loading="lazy" decoding="async" width="750" height="354" class="wp-image-6455 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc_json_driver__api_query_data_in_mssqlserver.png" alt="odbc_json_driver_api_query_data_in_mssqlserver" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc_json_driver__api_query_data_in_mssqlserver.png 750w, https://zappysys.com/blog/wp-content/uploads/2019/01/odbc_json_driver__api_query_data_in_mssqlserver-300x142.png 300w" sizes="(max-width: 750px) 100vw, 750px" />
</a>
<p class="wp-caption-text">SSMS Output - Query REST API via Linked Server OPENQUERY statement (Connect to ZappySys Data Gateway)</p>

</div></li>
 	<li>You can wrap your queries inside View or wrap inside Stored procedure to parameterize. Here is an example of creating the view which calls REST API queries.
<pre class="lang:tsql decode:true">CREATE VIEW dbo.vw_MyAPICall_View 
AS 
/*Call REST API inside SQL Server View*/
SELECT * FROM OPENQUERY( MY_LINKED_SERVER_NAME , 'SELECT * FROM $');

GO
</pre>
</li>
 	<li>Notice in above approach if you parameterize Stored Procedure then <a href="https://zappysys.com/blog/create-csv-list-sql-server-table-columns-datatypes/" target="_blank" rel="noopener">check this article to understand Dynamic Metadata</a>.</li>
 	<li>Now let's insert API data into the new data table "tblMyAPiData" in the SQL server database. For that, we need to execute below SQL query.
<pre class="lang:tsql decode:true ">Select * into tblMyAPiData FROM OPENQUERY( MY_LINKED_SERVER_NAME , 'SELECT * FROM $')</pre>
<div class="wp-caption alignnone">

<a href="https://zappysys.com/blog/wp-content/uploads/2019/02/odbc_json_driver_insert_data_in_sql.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" width="681" height="571" class="wp-image-6469 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/02/odbc_json_driver_insert_data_in_sql.png" alt="odbc_json_driver_insert_data_in_sql" srcset="https://zappysys.com/blog/wp-content/uploads/2019/02/odbc_json_driver_insert_data_in_sql.png 681w, https://zappysys.com/blog/wp-content/uploads/2019/02/odbc_json_driver_insert_data_in_sql-300x252.png 300w" sizes="(max-width: 681px) 100vw, 681px" /></a>
<p class="wp-caption-text">Insert data into the new table</p>

</div></li>
 	<li>Let's insert and update records into the already created table <span class="lang:default decode:true crayon-inline">"tblMyAPiData"</span>
<ul>
 	<li>To do that first we need to insert the new API data into the <span class="lang:default decode:true crayon-inline">"#temp_tblMyAPiData"</span> temporary database table.</li>
 	<li>Now let's delete the old records from the database table which are updated.</li>
 	<li>At the last insert all new API data into the database table.</li>
 	<li>To do that, we need to query like below SQL queries.</li>
</ul>
<pre class="lang:default decode:true">SELECT * into #temp_tblMyAPiData FROM OPENQUERY(MY_LINKED_SERVER_NAME, 'SELECT * FROM $')

DELETE FROM [dbo].[tblMyAPiData] WHERE id in (SELECT id FROM #temp_tblMyAPiData)

INSERT INTO tblMyAPiData
SELECT * FROM #temp_tblMyAPiData</pre>
&nbsp;</li>
 	<li>In the upper step, we see how to insert and update new records. Now if you want to update particular fields records only then you need to query like this.
<pre class="lang:default decode:true">Update dbtbl_1
set dbtbl_1.field1 = dbtbl_2.field1,
    dbtbl_1.field2 = dbtbl_2.field2
FROM tblMyAPiData dbtbl_1
JOIN (SELECT * FROM OPENQUERY(MY_LINKED_SERVER_NAME, 'SELECT * FROM $')) dbtbl_2 on dbtbl_1.id=dbtbl_2.id</pre>
<div class="su-note-inner su-clearfix" style="background-color: #fff4b7;border-color: #fffdf1;color: #333333">
<blockquote>*NOTE: If you are getting error like : "<strong>Cannot resolve the collation conflict between “Latin1_General_CI_AI” and “SQL_Latin1_General_CP1_CI_AS” in the equal to operation</strong>" then you need to query like this :
<pre class="lang:default decode:true">Update dbtbl_1
set dbtbl_1.field1 = dbtbl_2.field1,
    dbtbl_1.field2 = dbtbl_2.field2
FROM tblMyAPiData dbtbl_1
JOIN (SELECT * FROM OPENQUERY(MY_LINKED_SERVER_NAME, 'SELECT * FROM $')) dbtbl_2 
on dbtbl_1.id=dbtbl_2.id 
<strong>COLLATE SQL_Latin1_General_CP1_CI_AS</strong></pre>
&nbsp;</blockquote>
</div></li>
</ol></div>
<h2><span id="Step-by-Step_Import_REST_API_into_Power_BI">Conclusion</span></h2>
<p>So in this blog, we learned how to generate a QuickBooks API Token, Load QuickBooks Invoices data in MS SQL Server table using <a href="https://zappysys.com/products/odbc-powerpack/odbc-json-rest-api-driver/" target="_blank" rel="noopener">ODBC JSON / REST API Driver</a> in a very simple way. You can achieve many more functionalities with this tool. Check our blogs/articles on <strong>JSON / REST API Driver</strong> <a href="https://zappysys.com/blog/category/odbc-powerpack/odbc-drivers/json-rest-api-driver/" target="_blank" rel="noopener">https://zappysys.com/blog/category/odbc-powerpack/odbc-drivers/json-rest-api-driver/</a> to find out what <em>this tool</em> is capable of more.</p>
<h2><span id="References">References</span></h2>
<p>Finally, you can use the following links for more information about the use of QuickBooks API with our tools:</p>
<ul>
<li><a href="https://developer.atlassian.com/cloud/jira/platform/rest/" target="_blank" rel="noopener">QuickBooks Documentation for API</a></li>
<li><strong>Landing Page</strong> for <a href="https://zappysys.com/products/odbc-powerpack/odbc-json-rest-api-driver/" target="_blank" rel="noopener">ODBC JSON / REST API Driver</a>, you can also find <a href="https://youtu.be/iwezz0Z3D4U" target="_blank" rel="noopener">Tutorial Video</a> here.</li>
<li><strong>Help File:</strong> Documentation of <a href="https://zappysys.com/onlinehelp/odbc-powerpack/index.htm#page=json-odbc-driver-intro.htm" target="_blank" rel="noopener">JSON Driver</a>.</li>
<li><strong>Blog/articles link</strong>: <a href="https://zappysys.com/blog/category/odbc-powerpack/odbc-drivers/json-rest-api-driver/" target="_blank" rel="noopener">https://zappysys.com/blog/category/odbc-powerpack/odbc-drivers/json-rest-api-driver/</a></li>
</ul>
<p>The post <a href="https://zappysys.com/blog/read-data-from-quickbooks-online-to-sql-server/">Read data from QuickBooks Online into SQL Server via ODBC Driver</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Insert, Update and Delete JIRA Issue in SQL Server</title>
		<link>https://zappysys.com/blog/insert-update-delete-jira-issue-sql-server/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Wed, 09 Jan 2019 08:44:01 +0000</pubDate>
				<category><![CDATA[JSON File / REST API Driver]]></category>
		<category><![CDATA[ODBC Gateway]]></category>
		<category><![CDATA[ODBC PowerPack]]></category>
		<category><![CDATA[REST API]]></category>
		<category><![CDATA[T-SQL (SQL Server)]]></category>
		<category><![CDATA[jira]]></category>
		<category><![CDATA[odbc]]></category>
		<category><![CDATA[rest api]]></category>
		<category><![CDATA[sql query]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=5946</guid>

					<description><![CDATA[<p>Introduction In our previous blog we saw how to read JIRA data in SQL Server. In this blog, we will learn how to Insert, Update and Delete Issue in JIRA using ZappySys JSON Driver. We will also read data from SQL Server data table in stored-procedure and insert JIRA issues in bulk, along with few other [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/insert-update-delete-jira-issue-sql-server/">Insert, Update and Delete JIRA Issue in SQL Server</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2><span id="Introduction">Introduction</span></h2>
<div class="su-note"  style="border-color:#e5de9d;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><div class="su-note-inner su-u-clearfix su-u-trim" style="background-color:#FFF8B7;border-color:#ffffff;color:#333333;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><strong>UPDATE:</strong> ZappySys has released a brand new <a href="https://zappysys.com/api/integration-hub/jira-connector/odbc">API Connector for Jira Online</a> which makes it much simpler to <strong>Read/Write Jira Data in ODBC</strong> compared to the steps listed in this article. You can still use steps from this article but if you are new to API or want to avoid learning curve with API then use newer approach.</p>
<p>Please visit <a href="https://zappysys.com/api/integration-hub/">this page to see all</a> Pre-Configured ready to use API connectors which you can use in <a href="https://zappysys.com/products/ssis-powerpack/ssis-api-source/">SSIS API Source</a> / <a href="https://zappysys.com/products/ssis-powerpack/ssis-api-destination/">SSIS API Destination</a> OR <a href="https://zappysys.com/products/odbc-powerpack/odbc-api-driver/">API ODBC Driver</a> (for non-SSIS Apps such as Excel, Power BI, Informatica).</p>
</div></div>
<a href="https://zappysys.com/blog/wp-content/uploads/2019/01/write-in-jira.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="alignleft wp-image-5958 " src="https://zappysys.com/blog/wp-content/uploads/2019/01/write-in-jira-150x150.png" alt="Write in JIRA" width="138" height="138" /></a>In our previous blog we saw how to <a href="https://zappysys.com/blog/load-jira-data-sql-server-odbc-call-rest-api/" target="_blank" rel="noopener">read JIRA data in SQL Server</a>. In this blog, we will learn how to <strong>Insert, Update and Delete Issue in JIRA using ZappySys JSON Driver. </strong>We will also read data from SQL Server data table in stored-procedure and insert JIRA issues in bulk, along with few other topics such as how to generate an API Token using Atlassian Account for <strong>JIRA REST API Call</strong>, how to update and delete Issue data in JIRA using REST API calls.</p>
<p>So, let’s get started.</p>
<h2></h2>
<h2><span id="Requirements">Requirements</span></h2>
<ol>
<li>A first requirement will be to SQL Server Database Engine Installed</li>
<li>The second requirement will be SSMS installed</li>
<li>Finally, make sure to have <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> installed.</li>
</ol>
<h2>What is JIRA</h2>
<p>JIRA is Atlassian’s popular project- and issue-tracking platform used by development and technical support teams to get more work done and faster.</p>
<p>It combines:</p>
<p><strong>issue tracking</strong> &#8211; a software application that allows to record and follow the progress of every problem or &#8220;issue&#8221; that user identifies until the problem is resolved.<br />
<strong>agile project management</strong> &#8211; an iterative approach to planning and guiding project processes. customizable workflow, and a pluggable integration &#8211; integrates with Freshdesk, GitHub, Zendesk, Zapbook, Asana and so on.</p>
<h2>Getting Started</h2>
<p>First of all, we will see several examples. ZappySys includes an <a href="https://zappysys.com/products/odbc-powerpack/odbc-json-rest-api-driver/" target="_blank" rel="noopener">ODBC JSON Source Connector</a> that will help you to call JIRA API, Insert issue in JIRA using static data from the SQL server using ODBC JSON driver REST API Call. Update and Delete JIRA issue data From the SQL Server. Insert Bulk JIRA issues from the stored procedure. To learn more about JIRA API <a href="https://developer.atlassian.com/cloud/jira/platform/rest/v3/?utm_source=%2Fcloud%2Fjira%2Fplatform%2Frest%2F&amp;utm_medium=302" target="_blank" rel="noopener">check this help file</a>.</p>
<div class="content_block" id="custom_post_widget-4816"><h2>Generate API Token</h2>
To access JIRA data using REST API call you need to generate an API Token in your Atlassian account. Follow the steps mentioned below to generate API Token:
<ol>
 	<li>you can directly login to the <a href="https://id.atlassian.com" target="_blank" rel="noopener">JIRA Atlassian Cloud site</a> with your credentials, and redirect to the <a href="https://id.atlassian.com/profile/profile.action" target="_blank" rel="noopener">JIRA Atlassian Cloud Account's Profile Page</a> for generating an API Token.</li>
 	<li>Click <strong>API tokens</strong>, then <strong>Create API token</strong>.
<div class="wp-caption aligncenter">

<a href="https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-1.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-4315 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-1.png" alt="Generate API Token - Step - 1" width="1600" height="605" srcset="https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-1.png 1600w, https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-1-300x113.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-1-768x290.png 768w, https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-1-1024x387.png 1024w" sizes="(max-width: 1600px) 100vw, 1600px" /></a>
<p class="wp-caption-text">Generate API Token - Step - 1</p>

</div></li>
 	<li>Create API Token - Give Label name to your API token which you are generating now
<div class="wp-caption aligncenter">

<a href="https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-2.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="size-full wp-image-4316" src="https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-2.png" alt="Generate API Token - Step - 2" width="1599" height="603" srcset="https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-2.png 1599w, https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-2-300x113.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-2-768x290.png 768w, https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-2-1024x386.png 1024w" sizes="(max-width: 1599px) 100vw, 1599px" /></a>
<p class="wp-caption-text">Generate API Token - Step - 2</p>

</div></li>
 	<li>Use <strong>Copy to the clipboard</strong>, and paste the token into your or elsewhere:
<div class="su-note-inner su-clearfix" style="background-color:#fff4b7;border-color:#fffdf1;color:#333333"><blockquote>Note:  * For security reasons it isn't possible to view the token after closing the creation dialog; if necessary, create a new token. * You should store the token securely, just as for any password.</blockquote></div>
<div class="wp-caption aligncenter">

<a href="https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-3.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="size-full wp-image-4321" src="https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-3.png" alt="Generate API Token - Step - 3" width="1600" height="602" srcset="https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-3.png 1600w, https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-3-300x113.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-3-768x289.png 768w, https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-3-1024x385.png 1024w" sizes="(max-width: 1600px) 100vw, 1600px" /></a>
<p class="wp-caption-text">Generate API Token - Step - 3</p>

</div></li>
 	<li>If you forgot API token, then you can Revoke your old API token and create new API token OR you can create multiple API tokens too.
<div class="wp-caption aligncenter">

<a href="https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-4.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-4326 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-4.png" alt="Generate API token - Step - 4" width="1600" height="601" srcset="https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-4.png 1600w, https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-4-300x113.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-4-768x288.png 768w, https://zappysys.com/blog/wp-content/uploads/2018/07/jira-generate-api-token-step-4-1024x385.png 1024w" sizes="(max-width: 1600px) 100vw, 1600px" /></a>
<p class="wp-caption-text">Generate API token - Step - 4</p>

</div></li>
</ol>
Now we have successfully generated an API token. Let´s start with an example. In this example, we will show how to read Tasks/Issues data from JIRA and store that data into a SQL table with SSIS.</div>
<h2>About JIRA REST API</h2>
<p>JIRA On-premises and Cloud Version both offers REST API. Here are some examples of JIRA REST API. For inserting issue in JIRA we will use <a href="https://docs.atlassian.com/software/jira/docs/api/REST/7.13.0/?_ga=2.35527399.715857694.1546329197-716615697.1528110605#api/2/issue-createIssue" target="_blank" rel="noopener">JIRA REST API create issue method</a>. We can also insert issues in bulk using <a href="https://docs.atlassian.com/software/jira/docs/api/REST/7.13.0/?_ga=2.35527399.715857694.1546329197-716615697.1528110605#api/2/issue-createIssues" target="_blank" rel="noopener">Create issues bulk method</a>. To update issue we will use this PUT method: <a href="https://developer.atlassian.com/server/jira/platform/updating-an-issue-via-the-jira-rest-apis-6848604/" target="_blank" rel="noopener">Updating an Issue via the JIRA REST APIs</a>. To delete issue we will use this <a href="https://docs.atlassian.com/software/jira/docs/api/REST/7.13.0/#api/2/issue-deleteIssue" target="_blank" rel="noopener">DELETE method</a>. You can find JIRA Rest API example on this link: <a href="https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/" target="_blank" rel="noopener">Jira REST API examples</a></p>
<h2><span id="Step-by-Step_Import_REST_API_into_Power_BI">Step-by-Step: Write in JIRA from SQL Server</span></h2>
<p>Now once you have API token in the JIRA Atlassian Cloud website we can move to ODBC JSON Driver Configuration Part. For this example purpose you can use the following URL:</p><pre class="crayon-plain-tag">https://YOUR-DOMAIN.atlassian.net/rest/api/2/issue/</pre><p>
hence, <strong>your-domain is your Atlassian Cloud account’s domain name (we are using zappysys2.atlassian.net).</strong></p>
<p>Above all, each API endpoint may have a different limit for the number of items returned, and these limits may change without notice. (For more See this <a href="https://docs.atlassian.com/software/jira/docs/api/REST/7.13.0/" target="_blank" rel="noopener">JIRA REST API reference</a>)</p>
<h3><span id="Create_ODBC_DSN_8211_JSON_Driver">Configure ZappySys Gateway data Source for JIRA</span></h3>
<ol>
<li>To do this, first of all, we will open the ZappySys Data Gateway Configuration:
<div id="attachment_5283" style="width: 410px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5283" class="wp-image-5283 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png" alt="Open ZappySys Data Gateway" width="400" height="315" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png 400w, https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway-300x236.png 300w" sizes="(max-width: 400px) 100vw, 400px" /></a><p id="caption-attachment-5283" class="wp-caption-text">Open ZappySys Data Gateway</p></div></li>
<li>Add the Native &#8211; ZappySys JSON Driver Data source.
<div id="attachment_5284" style="width: 568px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5284" class="wp-image-5284 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source.png" alt="Add Gateway Data Source (Native JSON Driver)" width="558" height="533" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source.png 558w, https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-data-source-300x287.png 300w" sizes="(max-width: 558px) 100vw, 558px" /></a><p id="caption-attachment-5284" class="wp-caption-text">Add Gateway Data Source (Native JSON Driver)</p></div></li>
<li>Now it&#8217;s time to connect with JIRA. Let&#8217;s use JSON Driver Data source with the following URL:<br />
<pre class="crayon-plain-tag">https://YOUR-DOMAIN.atlassian.net/rest/api/2/issue/</pre>
<div id="attachment_9233" style="width: 730px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-jira-post.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-9233" class="wp-image-9233 size-medium_large" src="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-jira-post-768x672.png" alt="ODBC JSON Driver: Enter Request URL" width="720" height="630" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-jira-post-768x672.png 768w, https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-jira-post-300x263.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-jira-post.png 802w" sizes="(max-width: 720px) 100vw, 720px" /></a><p id="caption-attachment-9233" class="wp-caption-text">ODBC JSON Driver: Enter Request URL</p></div></li>
<li>It is time to configure the Other Settings. Select HTTP Connection Type from the Connection Type drop-down and Click on Click to Configure Link to Configure the Connection Manager.
<div id="attachment_5596" style="width: 1149px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/jira-odbc-json-driver-configure-http-api-connection-e1548802192303.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5596" class="wp-image-5596 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/11/jira-odbc-json-driver-configure-http-api-connection-e1548802192303.png" alt="JIRA REST API Connection - Use ZappySys JSON Driver HTTP Connection" width="1139" height="631" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/jira-odbc-json-driver-configure-http-api-connection-e1548802192303.png 1139w, https://zappysys.com/blog/wp-content/uploads/2018/11/jira-odbc-json-driver-configure-http-api-connection-e1548802192303-300x166.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/11/jira-odbc-json-driver-configure-http-api-connection-e1548802192303-768x425.png 768w, https://zappysys.com/blog/wp-content/uploads/2018/11/jira-odbc-json-driver-configure-http-api-connection-e1548802192303-1024x567.png 1024w" sizes="(max-width: 1139px) 100vw, 1139px" /></a><p id="caption-attachment-5596" class="wp-caption-text">JIRA REST API Connection &#8211; Use ZappySys JSON Driver HTTP Connection</p></div></li>
<li>Now, Let&#8217;s Add request body input data of issue.<br />
<pre class="crayon-plain-tag">{
    "fields": {
       "project":
       {
          "id": "&lt;YOUR-PROJECT-ID&gt;"
       },
       "summary": "No REST for the Wicked.",
       "description": "Creating of an issue using IDs for projects and issue types using the REST API",
       "issuetype": {
          "id": "&lt;ISSUE-TYPE-ID&gt;"
       }
   }
}</pre>
<div id="attachment_5954" style="width: 730px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/01/ODBC-input-request-data.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5954" class="wp-image-5954 size-medium_large" src="https://zappysys.com/blog/wp-content/uploads/2019/01/ODBC-input-request-data-768x423.png" alt="odbc-Issue Input Data" width="720" height="397" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/ODBC-input-request-data-768x423.png 768w, https://zappysys.com/blog/wp-content/uploads/2019/01/ODBC-input-request-data-300x165.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/01/ODBC-input-request-data-1024x563.png 1024w, https://zappysys.com/blog/wp-content/uploads/2019/01/ODBC-input-request-data.png 1276w" sizes="(max-width: 720px) 100vw, 720px" /></a><p id="caption-attachment-5954" class="wp-caption-text">Issue Input Data</p></div></li>
<li>Now using Query Builder we will generate the query.
<div id="attachment_5991" style="width: 730px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/01/ODBC-json-generate-query.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5991" class="wp-image-5991 size-medium_large" src="https://zappysys.com/blog/wp-content/uploads/2019/01/ODBC-json-generate-query-768x448.png" alt="ODBC-json-generate-query" width="720" height="420" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/ODBC-json-generate-query-768x448.png 768w, https://zappysys.com/blog/wp-content/uploads/2019/01/ODBC-json-generate-query-300x175.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/01/ODBC-json-generate-query-1024x598.png 1024w, https://zappysys.com/blog/wp-content/uploads/2019/01/ODBC-json-generate-query.png 1472w" sizes="(max-width: 720px) 100vw, 720px" /></a><p id="caption-attachment-5991" class="wp-caption-text">Generate JIRA Rest API Post Method Query</p></div></li>
<li>Now Let&#8217;s Test Connection and it will prompt the message &#8220;Connection is OK!&#8221;</li>
<li>That&#8217;s it we have successfully configured JIRA Rest API in ODBC JSON Driver.</li>
</ol>
<h3>Setup Linked Server <span id="Create_ODBC_DSN_8211_JSON_Driver">in MS SQL Server for JIRA</span></h3>
<p>Once you configured the data source in Gateway, we can now setup Linked Server in SQL Server to query API Calls.</p>
<ol>
<li>Assuming you have installed SQL Server and SSMS. If not then get both for FREE from here: <a href="https://www.microsoft.com/en-us/sql-server/sql-server-editions-express" target="_blank" rel="noopener">Get SQL Server Express</a> and  <a href="https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms" target="_blank" rel="noopener">Get SSMS</a></li>
<li>Open SSMS and connect to SQL Server.</li>
<li>Go to Root &gt; Server Objects &gt; Linked Servers node. Right click and click <strong>New Linked Server&#8230;</strong>
<div class="wp-caption alignnone">
<p><a href="https://i1.wp.com/zappysys.com/blog/wp-content/uploads/2018/03/create-new-linked-server-ssms.png?ssl=1" target="_blank" rel="noopener"><img loading="lazy" decoding="async" src="https://i1.wp.com/zappysys.com/blog/wp-content/uploads/2018/03/create-new-linked-server-ssms.png?w=720&amp;ssl=1" alt="Add Linked Server in SQL Server" width="420" height="262" /></a></p>
<p class="wp-caption-text">Add Linked Server in SQL Server</p>
</div>
</li>
<li> Now enter the linked server name, select Provider as SQL Native Client</li>
<li>Enter data source as <strong><pre class="crayon-plain-tag">GatewayServerName, PORT_NUMBER</pre></strong> where server name is where ZappySys Gateway is running (Can be same as SQL Server machine or remote machine). Default PORT_NUMBER is 5000 but confirm on Data gateway &gt; General tab in case its different.</li>
<li>Enter Catalog Name. This must match name from Data gateway Data sources grid &gt; Name column
<div class="wp-caption alignnone">
<p><a href="https://i1.wp.com/zappysys.com/blog/wp-content/uploads/2018/11/ssms-sql-server-configure-linked-server-1.png?ssl=1" target="_blank" rel="noopener"><img loading="lazy" decoding="async" src="https://i1.wp.com/zappysys.com/blog/wp-content/uploads/2018/11/ssms-sql-server-configure-linked-server-1.png?w=720&amp;ssl=1" alt="Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection" width="643" height="496" /></a></p>
<p class="wp-caption-text">Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection</p>
</div>
</li>
<li>Click on Security Tab and select last option &#8220;<strong>Be made using this security context</strong>&#8220;. Enter your gateway user account here.</li>
<li>Click OK to save Linked Server</li>
</ol>
<h3>Insert data in JIRA from SQL Server (Call POST API Method)</h3>
<ol>
<li>To Insert the issue in JIRA we need to execute the query like this. Please refer to this link for more information: <a href="https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/#creating-an-issue-examples" target="_blank" rel="noopener">Creating an issue example.</a><br />
<div class="su-note"  style="border-color:#e5de9d;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><div class="su-note-inner su-u-clearfix su-u-trim" style="background-color:#fff8b7;border-color:#ffffff;color:#333333;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;">Important Note*: If you don&#8217;t pass META='{xxxx}&#8217; in query driver call REST API 2 times first time to parse metadata and second time to get actual data. So that you find some odd thing in JIRA project if you execute the query without Meta then you will find two same issues created in your JIRA project as the driver makes two calls as mentioned above.</div></div>
<pre class="crayon-plain-tag">SELECT * FROM OPENQUERY([MY_LINKED_SERVER_NAME], 
'SELECT * FROM $
WITH( META=''[{"Name": "Success","Type": "Int32"}]''
     ,Src=''https://zappysys2.atlassian.net/rest/api/2/issue/''
     ,RequestData=''{
       "fields": {
        "project":
        {
          "id": "10110"
        },
        "summary": "No REST for the Wicked.",
        "description": "Creating of an issue using IDs for projects and issue types using the REST API",
        "issuetype": {
          "id": "1"
       }
     }
}''
,Header=''Content-Type: application/json || Accept: */*''
,RequestMethod=''POST''
)')</pre>
</li>
<li>Here is the preview after you run REST API query in SQL Server. It will return created issue id, key, and Link. Now let&#8217;s note down this response to update and delete the same issue if you want to. Notice that you can override default configuration by supplying <a href="https://zappysys.com/onlinehelp/odbc-powerpack/scr/json-odbc-driver-connectionstring.htm" target="_blank" rel="noopener">many parameters</a> in WITH clause.
<div id="attachment_5993" style="width: 730px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-insert-issue-in-jira.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5993" class="wp-image-5993 size-medium_large" src="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-insert-issue-in-jira-768x607.png" alt="odbc-insert-issue-in-jira" width="720" height="569" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-insert-issue-in-jira-768x607.png 768w, https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-insert-issue-in-jira-300x237.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-insert-issue-in-jira.png 831w" sizes="(max-width: 720px) 100vw, 720px" /></a><p id="caption-attachment-5993" class="wp-caption-text">Insert Issue In JIRA Using SQL Query</p></div></li>
<li>You can also find this created issue in your JIRA project.
<div id="attachment_5994" style="width: 730px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/01/jira-issue-preview-in-browser.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5994" class="wp-image-5994 size-medium_large" src="https://zappysys.com/blog/wp-content/uploads/2019/01/jira-issue-preview-in-browser-768x402.png" alt="jira-issue-preview-in-browser" width="720" height="377" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/jira-issue-preview-in-browser-768x402.png 768w, https://zappysys.com/blog/wp-content/uploads/2019/01/jira-issue-preview-in-browser-300x157.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/01/jira-issue-preview-in-browser-1024x536.png 1024w, https://zappysys.com/blog/wp-content/uploads/2019/01/jira-issue-preview-in-browser.png 1384w" sizes="(max-width: 720px) 100vw, 720px" /></a><p id="caption-attachment-5994" class="wp-caption-text">Created Issue in JIRA</p></div></li>
</ol>
<h3>Update data in JIRA from SQL Server (Call PUT API Method)</h3>
<ol>
<li>Let&#8217;s update the issue which we created in the previous step using id. I Added Extra Meta details in Query to prevent driver to make two calls and also to prevent error as JIRA Rest API Response is a blank <pre class="crayon-plain-tag">Status code of "204 No Content"</pre>. Please refer to this link for more information: <a href="https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/#editing-an-issue-examples" target="_blank" rel="noopener">Updating an Issue via the JIRA REST APIs</a><br />
<pre class="crayon-plain-tag">SELECT * FROM OPENQUERY([MY_LINKED_SERVER_NAME]
, 'SELECT * FROM $
   WITH(META=''[{"Name": "Success","Type": "Int32"}]'' ,
	 Src=''https://zappysys2.atlassian.net/rest/api/2/issue/10391''
	,DataConnectionType=''HTTP''
	,RequestData=''{
    "fields": {
       "summary": "Updated One!...Ye merry gentlemen."
   }
}''
	,Header=''Content-Type: application/json || Accept: */*''
	,RequestMethod=''PUT''
)')</pre>
</li>
<li>Let&#8217;s is the preview after you running update query in SQL Server.
<div id="attachment_6004" style="width: 541px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-update-jira-issue.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-6004" class="wp-image-6004 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-update-jira-issue.png" alt="odbc-update-jira-issue" width="531" height="433" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-update-jira-issue.png 531w, https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-update-jira-issue-300x245.png 300w" sizes="(max-width: 531px) 100vw, 531px" /></a><p id="caption-attachment-6004" class="wp-caption-text">Update Jira Issue From SQL Server</p></div></li>
<li>Now, Let&#8217;s see the updated issue in JIRA project.
<div id="attachment_5997" style="width: 730px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/01/updated-issue-in-jira.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5997" class="wp-image-5997 size-medium_large" src="https://zappysys.com/blog/wp-content/uploads/2019/01/updated-issue-in-jira-768x413.png" alt="https://zappysys.com/blog/wp-content/uploads/2019/01/updated-issue-in-jira.png" width="720" height="387" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/updated-issue-in-jira-768x413.png 768w, https://zappysys.com/blog/wp-content/uploads/2019/01/updated-issue-in-jira-300x161.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/01/updated-issue-in-jira-1024x550.png 1024w, https://zappysys.com/blog/wp-content/uploads/2019/01/updated-issue-in-jira.png 1600w" sizes="(max-width: 720px) 100vw, 720px" /></a><p id="caption-attachment-5997" class="wp-caption-text">Updated Issue In JIRA Project</p></div></li>
<li>One Import note if you don&#8217;t add that metadata then you will get an error like below as JIRA Rest API Response is a blank &#8220;Status code of &#8216;204 No Content'&#8221;. If you don&#8217;t set META the REST API Make Two calls First to parse metadata and for the second time to get actual data.<br />
<div class="su-note"  style="border-color:#e5ae9d;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><div class="su-note-inner su-u-clearfix su-u-trim" style="background-color:#ffc8b7;border-color:#ffffff;color:#333333;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;">Query execution error: No data returned for specified table name or filter expression. Make sure table name or filter is typed correctly (it is case sensitive) and input data contains a corresponding element(s).</div></div></li>
</ol>
<h3>Delete data in JIRA from SQL Server (Call DELETE API Method)</h3>
<ol>
<li>Now let&#8217;s delete the issue which we created by executing following query in SQL Server. We also need to add extra meta details in query same as update one as JIRA Rest API Response is a blank <pre class="crayon-plain-tag">Status code of "204 No Content"</pre>. Please refer to this link for more information: <a href="https://docs.atlassian.com/software/jira/docs/api/REST/7.13.0/?_ga=2.35527399.715857694.1546329197-716615697.1528110605#api/2/issue-deleteIssue" target="_blank" rel="noopener">Delete an Issue via the JIRA REST API</a><br />
<pre class="crayon-plain-tag">SELECT * FROM OPENQUERY([MY_LINKED_SERVER_NAME]
, 'SELECT * FROM $
   WITH(META=''[{"Name": "Success","Type": "Int32"}]'' ,
	 Src=''https://zappysys2.atlassian.net/rest/api/2/issue/10391''
	,DataConnectionType=''HTTP''
	,Header=''Content-Type: application/json || Accept: */*''
	,RequestMethod=''DELETE''
)')</pre>
</li>
<li>Now, Let&#8217;s check the deleted issue in JIRA project.
<div id="attachment_6006" style="width: 730px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/01/deleted-issue-in-jira.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-6006" class="wp-image-6006 size-medium_large" src="https://zappysys.com/blog/wp-content/uploads/2019/01/deleted-issue-in-jira-768x412.png" alt="deleted-issue-in-jira" width="720" height="386" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/deleted-issue-in-jira-768x412.png 768w, https://zappysys.com/blog/wp-content/uploads/2019/01/deleted-issue-in-jira-300x161.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/01/deleted-issue-in-jira-1024x549.png 1024w, https://zappysys.com/blog/wp-content/uploads/2019/01/deleted-issue-in-jira.png 1599w" sizes="(max-width: 720px) 100vw, 720px" /></a><p id="caption-attachment-6006" class="wp-caption-text">Issue Deleted in JIRA Project</p></div></li>
</ol>
<h3>Create multiple JIRA issues using SQL Server Stored Proc</h3>
<p>Now lets put all previous things to more practical use. We will create a stored procedure which will read Issues stored in a SQL Table and Submit it to JIRA to create new Issue via REST API call. This will make it totally dynamic so SQL Table can act as your Source of information for API call.</p>
<ol>
<li>Let&#8217;s create stored procedure to read data from &#8220;tblIssues&#8221; data table and create bulk issues in JIRA.<br />
<pre class="crayon-plain-tag">alter PROCEDURE usp_AddMultipleJiraIssues
AS
BEGIN

Declare @issueTemp nvarchar(2000)
Declare @PostQuery nvarchar(MAX)
Declare @strIssues nvarchar(MAX)
set @PostQuery='';
set @strIssues='';

---- Template 
set @issueTemp=	'{
			"fields": {
				"project": {
					"key": "&lt;YOUR-JIRA-PROJECT-KEY&gt;"
				},
				"summary": "[ISSUE-SUMMARY]",
				"description": "[ISSUE-DESCRIPTION]",
			        "issuetype": {
					  "id": "&lt;YOUR-JIRA-ISSUE-TYPE&gt;"
				}
			}
		}';

-----Generate issues JSON String from the data table 
Select @strIssues = @strIssues
                    + REPLACE(REPLACE(@issueTemp,'[ISSUE-SUMMARY]',isnull(i.summary,''))
                                             ,'[ISSUE-DESCRIPTION]',isnull(i.description,''))
                    + ',' 
from tblissues i

-----Trim last , comma from the string otherwise you will get an error 
SET @strIssues = LEFT(@strIssues,(LEN(@strIssues)-1))

-----JIRA Post Query
SET @PostQuery= 'SELECT * FROM OPENQUERY([UPDATE_JIRA_DATA_JSON_DRIVER]
					, ''SELECT * FROM $
					WITH(
						META=''''[{"Name": "Success","Type": "Int32"}]''''
                                                ,Src=''''https://zappysys2.atlassian.net/rest/api/2/issue/bulk''''
						,DataConnectionType=''''HTTP''''
						,RequestData=''''{
						   "issueUpdates": [' + @strIssues + ']
					        }''''
						,Header=''''Content-Type: application/json || Accept: */*''''
						,RequestMethod=''''POST''''
					)'')'

--Print(@PostQuery)

----Posting issues data in JIRA
Execute(@PostQuery)

END
GO</pre>
</li>
<li>That&#8217;s it now executes the stored procedure and you will find bulk issues created in your JIRA project.
<div id="attachment_6132" style="width: 730px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/01/created-issue-in-jira.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-6132" class="wp-image-6132 size-medium_large" src="https://zappysys.com/blog/wp-content/uploads/2019/01/created-issue-in-jira-768x416.png" alt="Bulk Issues Created In Jira" width="720" height="390" srcset="https://zappysys.com/blog/wp-content/uploads/2019/01/created-issue-in-jira-768x416.png 768w, https://zappysys.com/blog/wp-content/uploads/2019/01/created-issue-in-jira-300x162.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/01/created-issue-in-jira-1024x554.png 1024w, https://zappysys.com/blog/wp-content/uploads/2019/01/created-issue-in-jira.png 1349w" sizes="(max-width: 720px) 100vw, 720px" /></a><p id="caption-attachment-6132" class="wp-caption-text">Bulk Issues Created In Jira</p></div></li>
</ol>
<h2><span id="Step-by-Step_Import_REST_API_into_Power_BI">Conclusion</span></h2>
<p>In this blog, we learned how to generate a JIRA API Token and how to configure it,  Insert, Update and delete Issue in JIRA using <a href="https://zappysys.com/products/odbc-powerpack/odbc-json-rest-api-driver/" target="_blank" rel="noopener">ODBC JSON / REST API Driver</a> from the SQL server. You can achieve many more functionalities with this tool. Check our blogs/articles on <a href="https://zappysys.com/blog/category/odbc-powerpack/odbc-drivers/json-rest-api-driver/"><strong>JSON / REST API Driver</strong></a> to find out what <em>this tool</em> is capable of more.</p>
<h2><span id="References">References</span></h2>
<p>Finally, you can use the following links for more information about the use of JIRA API with our tools:</p>
<ul>
<li><a href="https://docs.atlassian.com/software/jira/docs/api/REST/7.13.0/" target="_blank" rel="noopener">JIRA Documentation for API</a></li>
<li><strong>Landing Page</strong> for <a href="https://zappysys.com/products/odbc-powerpack/odbc-json-rest-api-driver/" target="_blank" rel="noopener">ODBC JSON / REST API Driver</a>, you can also find <a href="https://youtu.be/iwezz0Z3D4U" target="_blank" rel="noopener">Tutorial Video</a> here.</li>
<li><strong>Help File:</strong> Documentation of <a href="https://zappysys.com/onlinehelp/odbc-powerpack/index.htm#page=json-odbc-driver-intro.htm" target="_blank" rel="noopener">JSON Driver</a>.</li>
<li><strong>Blog/articles link</strong>: <a href="https://zappysys.com/blog/category/odbc-powerpack/odbc-drivers/json-rest-api-driver/" target="_blank" rel="noopener">https://zappysys.com/blog/category/odbc-powerpack/odbc-drivers/json-rest-api-driver/</a></li>
</ul>
<p>The post <a href="https://zappysys.com/blog/insert-update-delete-jira-issue-sql-server/">Insert, Update and Delete JIRA Issue in SQL Server</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Push data into a Power BI dataset from SQL Server</title>
		<link>https://zappysys.com/blog/push-data-into-power-bi-dataset-from-sql-server/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Tue, 27 Nov 2018 16:31:05 +0000</pubDate>
				<category><![CDATA[JSON File / REST API Driver]]></category>
		<category><![CDATA[ODBC Gateway]]></category>
		<category><![CDATA[T-SQL (SQL Server)]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[power bi]]></category>
		<category><![CDATA[rest api]]></category>
		<category><![CDATA[sql server]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=5408</guid>

					<description><![CDATA[<p>Introduction In this article, you will learn how to push data into a Power BI dataset from SQL Server. Power BI is a Microsoft reporting product that can get data from virtually any source and display it nicely in a report or a dashboard. Among its dataset types, it has a streaming dataset into which [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/push-data-into-power-bi-dataset-from-sql-server/">Push data into a Power BI dataset from SQL Server</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p style="text-align: justify;"><img loading="lazy" decoding="async" class="alignleft wp-image-3951" src="https://zappysys.com/blog/wp-content/uploads/2018/06/power-bi-logo-310x310-150x150.png" alt="Power BI Integration" width="100" height="100" srcset="https://zappysys.com/blog/wp-content/uploads/2018/06/power-bi-logo-310x310-150x150.png 150w, https://zappysys.com/blog/wp-content/uploads/2018/06/power-bi-logo-310x310-300x300.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/06/power-bi-logo-310x310.png 310w" sizes="(max-width: 100px) 100vw, 100px" />In this article, you will learn how to push data into a <a href="https://powerbi.microsoft.com/en-us/" target="_blank" rel="noopener">Power BI</a> dataset from SQL Server. Power BI is a Microsoft reporting product that can get data from virtually any source and display it nicely in a report or a dashboard. Among its dataset types, it has a streaming dataset into which you can push data from a <a href="https://docs.microsoft.com/en-us/rest/api/power-bi/" target="_blank" rel="noopener">Power BI REST API</a>. Once pushed, data will be immediately refreshed in a visual, pinned to a dashboard. Thus this approach of sending data to a streaming dataset is a perfect way for displaying real-time data. Yet it is not possible to push data to a dataset straight from SQL Server out of the box. However, with <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> it is possible to achieve that quite easily. We will employ one of its apps &#8211; <a href="https://zappysys.com/products/odbc-powerpack/data-gateway/" target="_blank" rel="noopener">ZappySys Data Gateway</a> &#8211; to make HTTP requests and push data to a streaming dataset.</p>
<p>The use cases when you may want to push data to a streaming dataset from a SQL Server are:</p>
<ul>
<li>Displaying real-time data from many SQL Server instances at once (and you cannot use the <em>DirectQuery</em> option in a report).</li>
<li>Displaying real-time data when many sources write to a dataset, and a SQL Server is one of them.</li>
<li>Any other case.</li>
</ul>
<p>Let&#8217;s begin and write some data to a Power BI streaming dataset!</p>
<h2>Prerequisites</h2>
<ol>
<li>You have a Power BI account and you have basic Power BI skills.</li>
<li>SQL Server instance installed (can be a <a href="https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-2016-express-localdb" target="_blank" rel="noopener">SQL Server Express LocalDB</a> instance).</li>
<li><a href="https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms" target="_blank" rel="noopener">SQL Server Management Studio</a> (SSMS) installed.</li>
<li><a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> installed (must be installed on a Windows machine; can be a different machine than SQL Server is installed on).</li>
</ol>
<h2>Step By Step &#8211; Push data into a Power BI dataset from a SQL Server</h2>
<div class="content_block" id="custom_post_widget-5441"><h3>Create a streaming dataset in Power BI</h3>
The first thing you need to do is to create a streaming dataset. We will create a simple dataset for demo purposes which will have two columns: <strong>Timestamp</strong> and <strong>Temperature</strong>.
<ol style="margin-left: 0;">
 	<li>Go to Power BI portal, hit <strong>My Workspace</strong>, <strong>+ Create</strong> and then click <strong>Streaming dataset</strong>:
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-5424" src="https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-streaming-dataset-1.png" alt="" width="945" height="443" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-streaming-dataset-1.png 945w, https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-streaming-dataset-1-300x141.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-streaming-dataset-1-768x360.png 768w" sizes="(max-width: 945px) 100vw, 945px" /></li>
 	<li>Then select <strong>API</strong> and click <strong>Next</strong>:
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-5425" src="https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-streaming-dataset-2-select-api.png" alt="" width="550" height="419" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-streaming-dataset-2-select-api.png 550w, https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-streaming-dataset-2-select-api-300x229.png 300w" sizes="(max-width: 550px) 100vw, 550px" /></li>
 	<li>Give dataset a name, add two columns and check <strong>Historic data analysis</strong> to enable data history and the ability to create report easily (otherwise you will be able to create a tile in a dashboard only):
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-5426" src="https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-streaming-dataset-3-give-a-name.png" alt="" width="550" height="740" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-streaming-dataset-3-give-a-name.png 550w, https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-streaming-dataset-3-give-a-name-223x300.png 223w" sizes="(max-width: 550px) 100vw, 550px" /></li>
 	<li>Once a dataset is created, copy <strong>Push URL</strong> to a notepad so we can use it later. Also, note the structure of the JSON we will have to use to submit live data into the created dataset:<img loading="lazy" decoding="async" class="alignnone size-full wp-image-5427" src="https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-streaming-dataset-4-created.png" alt="" width="547" height="462" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-streaming-dataset-4-created.png 547w, https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-streaming-dataset-4-created-300x253.png 300w" sizes="(max-width: 547px) 100vw, 547px" /></li>
</ol></div>
<div class="content_block" id="custom_post_widget-5411"><h3><span style="font-size: 14pt;">Configure ZappySys Data Gateway</span></h3>
Now let's look at steps to configure Data Gateway after installation.
<ol style="margin-left: 0;">
 	<li style="text-align: left;">Assuming you have installed <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> using default options (Which also enables Data Gateway Service)</li>
 	<li style="text-align: left;">Search "Gateway" in your start menu and click ZappySys Data Gateway
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png" alt="Open ZappySys Data Gateway" /></a>
<p class="wp-caption-text">Opening ZappySys Data Gateway</p>

</div></li>
 	<li>First, make sure Gateway Service is running (Verify Start icon is disabled)</li>
 	<li>Also, verify Port on General Tab
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/03/ZappySys-data-gateway-port-5000.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/03/ZappySys-data-gateway-port-5000.png" alt="Port Number setting on ZappySys Data Gateway" /></a>
<p class="wp-caption-text">Checking port number setting on ZappySys Data Gateway</p>

</div></li>
 	<li>Now go to Users tab. <strong>Click Add</strong> icon to add a new user. Check Is admin to give access to all data sources you add in future. If you don't check admin then you have to manually configure user permission for each data source.
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-user.png">
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-5453" src="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-configure-add-user.png" alt="" width="564" height="438" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-configure-add-user.png 564w, https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-configure-add-user-300x233.png 300w" sizes="(max-width: 564px) 100vw, 564px" /></a>
<p class="wp-caption-text">Adding the Gateway user</p>

</div></li>
</ol>
&nbsp;</div>
<h3>Add a data source in the Gateway</h3>
<p>It&#8217;s time to add a data source, which we will use to POST data to Power BI REST API:</p>
<ol>
<li>In the Gateway, click on <strong>Data sources</strong> tab, click <strong>Add</strong>, give data source a name and set <em>Connector Type</em> to <strong>Native &#8211; ZappySys JSON Driver</strong>:<img loading="lazy" decoding="async" class="alignnone size-full wp-image-5439" src="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-1-1.png" alt="" width="562" height="573" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-1-1.png 562w, https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-1-1-294x300.png 294w" sizes="(max-width: 562px) 100vw, 562px" /></li>
<li>Then click <strong>Edit</strong> to modify the data source:<br />
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-5440" src="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-2-2.png" alt="" width="562" height="385" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-2-2.png 562w, https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-2-2-300x206.png 300w" sizes="(max-width: 562px) 100vw, 562px" /></li>
<li>Finally, paste into <em>Url </em>textbox <strong>Push URL</strong> of the dataset which we saved in a previous step. Also, set <em>HTTP Request Method</em> to <strong>POST</strong>:
<div id="attachment_5430" style="width: 812px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5430" class="wp-image-5430 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-3.png" alt="Configure REST API Connection for Power BI dataset insert (Using ZappySys JSON / REST Driver)" width="802" height="702" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-3.png 802w, https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-3-300x263.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/11/gateway-create-datasource-3-768x672.png 768w" sizes="(max-width: 802px) 100vw, 802px" /><p id="caption-attachment-5430" class="wp-caption-text">Configure REST API Connection for Power BI dataset insert (Using ZappySys JSON / REST Driver)</p></div></li>
</ol>
<h3>Add a Linked Server to the Gateway</h3>
<div class="content_block" id="custom_post_widget-5432">Once you configured the data source in Gateway, we can now set up a Linked Server in a SQL Server.
<ol style="margin-left: 10px;">
 	<li>Open SSMS and connect to a SQL Server.</li>
 	<li>Go to Root &gt; Server Objects &gt; Linked Servers node. Right click and click <strong>New Linked Server...
</strong>
<div class="wp-caption alignnone">
<a href="https://zappysys.com/blog/wp-content/uploads/2018/03/create-new-linked-server-ssms.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/03/create-new-linked-server-ssms.png" alt="Add Linked Server in SQL Server" />
</a>
<p class="wp-caption-text">Adding Linked Server in SQL Server</p>

</div></li>
 	<li>Now enter the linked server name, select Provider as SQL Native Client.</li>
 	<li>Enter data source as <strong><span class="lang:default decode:true crayon-inline">GatewayServerName,PORT_NUMBER</span></strong> where server name is where ZappySys Gateway is running (can be the same as SQL Server machine or a remote machine). Default PORT_NUMBER is 5000 but confirm that on the Gateway &gt; General tab in case it's different.</li>
 	<li>Enter Catalog Name. This must match name from Data gateway Data sources grid &gt; Name column
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/ssms-sql-server-configure-linked-server-2.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/ssms-sql-server-configure-linked-server-2.png" alt="Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection" />
</a>
<p class="wp-caption-text">Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection</p>
</div>
<div style="color: #31708f;background-color: #d9edf7;border-color: #bce8f1;padding: 15px;margin-bottom: 20px;border: 1px solid transparent;border-radius: 4px;">
<strong>INFO:</strong><br/>
<ul>
    <li>
      For <strong>SQL Server 2012, 2014, 2016, 2017, and 2019</strong>, use the <em>SQL Server Native Client 11.0</em> as the Provider.
    </li>
    <li>
      For <strong>SQL Server 2022 or higher</strong>, use the <em>Microsoft OLE DB Driver for SQL Server</em> as the Provider.
    </li>
  </ul>
</div></li>
 	<li>Click on Security Tab and select the last option "<strong>Be made using this security context</strong>". Enter your gateway user account here.
<div class="wp-caption alignnone">
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-5456" src="https://zappysys.com/blog/wp-content/uploads/2018/11/add-linked-server-sql-server-3-security-2.png" alt="" width="690" height="625" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/add-linked-server-sql-server-3-security-2.png 690w, https://zappysys.com/blog/wp-content/uploads/2018/11/add-linked-server-sql-server-3-security-2-300x272.png 300w" sizes="(max-width: 690px) 100vw, 690px" />
<p class="wp-caption-text">Configuring Linked Server credentials</p>
</li>
<li>
        <p>Optional: Under the Server Options Tab, Enable <b>RPC</b> and <b>RPC Out</b> and Disable Promotion of Distributed Transactions<b>(MSDTC)</b>.</p>
		<div class="wp-caption alignnone">
			<img decoding="async" class="block margin-bottom-10 img-thumbnail" src="https://zappysys.com/blog/wp-content/uploads/2018/11/linked-server-options-rpc-msdtc.png" title="RPC and MSDTC Settings" alt="RPC and MSDTC Settings" />
			<p class="wp-caption-text">RPC and MSDTC Settings</p>
		</div>
        <hr />
        <p>
            You need to enable RPC Out if you plan to use <b><i>EXEC(...) AT [MY_LINKED_SERVER_NAME]</i></b> rather than OPENQUERY.
            <br />
            If don't enabled it, you will encounter the <i>'Server "MY_LINKED_SERVER_NAME" is not configured for RPC'</i> error.
        </p>
        <p>
            Query Example:
            <code class="sql">EXEC('Select * from Products') AT [MY_LINKED_SERVER_NAME]</code>
        </p>
        <hr />
        <p>
            If you plan to use <b><i>'INSERT INTO...EXEC(....) AT [MY_LINKED_SERVER_NAME]'</i></b> in that case you need to Disable Promotion of Distributed Transactions(MSDTC).
            <br />
            If don't disabled it, you will encounter the <i>'The operation could not be performed because OLE DB provider "SQLNCLI11/MSOLEDBSQL" for linked server "MY_LINKED_SERVER_NAME" was unable to begin a distributed transaction.'</i> error.
        </p>
        <p>
            Query Example:
<pre class="">Insert Into dbo.Products 
EXEC('Select * from Products') AT [MY_LINKED_SERVER_NAME]</pre>
        </p>
        <hr />
</li>
 	<li>Click OK to save the Linked Server.</li>
</ol></div>
<h3>Writing data into Power BI dataset from SQL Server</h3>
<p>Once you add a Linked Server you can execute a query to push data into a Power BI streaming dataset:</p>
<ol style="margin-left: 0;">
<li>In the same SQL Server Management Studio create a new query and paste the code below. In <em>Body</em> attribute, we pass the JSON in the same format which was shown when we created a Power BI dataset:<br />
<pre class="crayon-plain-tag">SELECT * FROM
OPENQUERY([GATEWAY], 'SELECT * FROM $
WITH (Body=''[ 
	{ "Timestamp" :"2018-11-15T02:57:04.547Z", "Temperature" : 50.5 },
	{ "Timestamp" :"2018-11-16T02:57:04.547Z", "Temperature" : 55.5 },
	{ "Timestamp" :"2018-11-17T02:57:04.547Z", "Temperature" : 60.5 },
	{ "Timestamp" :"2018-11-18T02:57:04.547Z", "Temperature" : 57.5 },
	{ "Timestamp" :"2018-11-19T02:57:04.547Z", "Temperature" : 62.3 }
]''
,meta=''[ { "Name": "Dummy", "Type": "String" }]'' )')</pre>
<div class="su-note"  style="border-color:#e5da9d;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><div class="su-note-inner su-u-clearfix su-u-trim" style="background-color:#fff4b7;border-color:#ffffff;color:#333333;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><strong>Note:</strong> Use the same Linked Server name you created in a previous step. In our case, it is &#8220;GATEWAY&#8221;.</div></div></li>
<li>Execute the query.</li>
</ol>
<h2>The results: creating a Power BI report</h2>
<p>Now it&#8217;s time to check the results and see if data went through:</p>
<ol style="margin-left: 0;">
<li>Go to Power BI portal.</li>
<li>Select <strong>Datasets </strong>and click on the add new report icon:
<div id="attachment_5447" style="width: 705px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5447" class="wp-image-5447 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-report-from-streaming-dataset-1.png" alt="Create new Power BI Report for real time dataset" width="695" height="384" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-report-from-streaming-dataset-1.png 695w, https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-report-from-streaming-dataset-1-300x166.png 300w" sizes="(max-width: 695px) 100vw, 695px" /><p id="caption-attachment-5447" class="wp-caption-text">Create new Power BI Report for real time dataset</p></div></li>
<li>Add a Line Chart, a Table and link them to the dataset.</li>
<li>You should see the data we pushed to the dataset:
<div id="attachment_5448" style="width: 596px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-5448" class="wp-image-5448 size-full" src="https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-report-from-streaming-dataset-2.png" alt="Showing real time data in Power BI dashboard" width="586" height="343" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-report-from-streaming-dataset-2.png 586w, https://zappysys.com/blog/wp-content/uploads/2018/11/powerbi-create-report-from-streaming-dataset-2-300x176.png 300w" sizes="(max-width: 586px) 100vw, 586px" /><p id="caption-attachment-5448" class="wp-caption-text">Showing real time data in Power BI dashboard</p></div></li>
</ol>
<div class="su-note"  style="border-color:#e5da9d;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><div class="su-note-inner su-u-clearfix su-u-trim" style="background-color:#fff4b7;border-color:#ffffff;color:#333333;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><strong>Note:</strong> To see real-time data, pin a visual to a dashboard. Live data can be seen only in a dashboard since only there data is refreshed when a new piece of data is received. However, it does not work with reports &#8211; if you pin a whole report to a dashboard it won&#8217;t update data in real-time. </div></div>
<h2>Conclusion</h2>
<p style="text-align: justify;">You learned how to push data into a Power BI streaming dataset directly from SQL Server. It was possible to achieve that with ZappySys Data Gateway and SQL Server Linked Server option. At first, we created a streaming dataset in Power BI, then configured a datasource in the Gateway, followed with adding a Linked Server to the Gateway, executed T-SQL query in SSMS and pushed some data to the dataset and finally created a Power BI report to check the received data.</p>
<p style="text-align: justify;">When we set <strong>Historic data analysis</strong> option when creating a dataset, we, in turn, created a dataset of type <strong>Push </strong>(if we left it off, it would be of type <strong>Streaming</strong>). It allowed us to create a report easily on top of it, but it has certain <a href="https://docs.microsoft.com/en-us/power-bi/developer/api-rest-api-limitations" target="_blank" rel="noopener">limitations</a>. Just be aware when using this option and check <a href="https://docs.microsoft.com/en-us/power-bi/service-real-time-streaming" target="_blank" rel="noopener">Power BI service documentation</a> for more info.</p>
<p style="text-align: justify;">Finally, in SSMS, we executed a query with predefined data. Therefore in real life, if you want to push data from an existing table, you will have to build JSON from it. Make sure you construct <a href="https://jsonlint.com/" target="_blank" rel="noopener">a valid JSON</a> and escape the symbols that need to be escaped (<a href="https://www.json.org/" target="_blank" rel="noopener">such as a double-quote or a backslash</a>).</p>
<h2>References</h2>
<p><a href="https://powerbi.microsoft.com/en-us/" target="_blank" rel="noopener">https://powerbi.microsoft.com/en-us/</a></p>
<p><a href="https://docs.microsoft.com/en-us/rest/api/power-bi/" target="_blank" rel="noopener">https://docs.microsoft.com/en-us/rest/api/power-bi/</a></p>
<p><a href="https://docs.microsoft.com/en-us/power-bi/service-real-time-streaming" target="_blank" rel="noopener">https://docs.microsoft.com/en-us/power-bi/service-real-time-streaming</a></p>
<p><a href="https://docs.microsoft.com/en-us/power-bi/developer/api-rest-api-limitations" target="_blank" rel="noopener">https://docs.microsoft.com/en-us/power-bi/developer/api-rest-api-limitations</a></p>
<p>The post <a href="https://zappysys.com/blog/push-data-into-power-bi-dataset-from-sql-server/">Push data into a Power BI dataset from SQL Server</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to import REST API in SQL Server (Call JSON / XML SOAP Service)</title>
		<link>https://zappysys.com/blog/import-rest-api-json-sql-server/</link>
		
		<dc:creator><![CDATA[ZappySys Team]]></dc:creator>
		<pubDate>Fri, 09 Mar 2018 20:23:23 +0000</pubDate>
				<category><![CDATA[JSON File / REST API Driver]]></category>
		<category><![CDATA[ODBC Gateway]]></category>
		<category><![CDATA[ODBC PowerPack]]></category>
		<category><![CDATA[T-SQL (SQL Server)]]></category>
		<category><![CDATA[XML File / SOAP API Driver]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[linked server]]></category>
		<category><![CDATA[odbc]]></category>
		<category><![CDATA[polybase]]></category>
		<category><![CDATA[rest api]]></category>
		<category><![CDATA[soap]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[xml]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=2921</guid>

					<description><![CDATA[<p>Introduction In this article, you will see few Examples to import REST API in SQL Server Table (Call JSON / XML SOAP API).  You will also learn how to load JSON Files into SQL Server Table using T-SQL Stored procedure code.  So let&#8217;s get ready for fun 🙂 JSON File format and REST API (i.e. RESTful [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/import-rest-api-json-sql-server/">How to import REST API in SQL Server (Call JSON / XML SOAP Service)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p><a href="https://zappysys.com/blog/wp-content/uploads/2018/03/json-to-sql-server-import-export.png"><img loading="lazy" decoding="async" class="alignleft wp-image-2924 size-thumbnail" src="https://zappysys.com/blog/wp-content/uploads/2018/03/json-to-sql-server-import-export-150x150.png" alt="JSON to SQL Server" width="150" height="150" /></a>In this article, you will see few <strong>Examples to import REST API in SQL Server Table (Call JSON / XML SOAP API). </strong> You will also learn <strong>how to load JSON Files into SQL Server Table using T-SQL Stored procedure</strong> code.  So let&#8217;s get ready for fun 🙂</p>
<p>JSON File format and REST API (i.e. RESTful API ) is becoming more and more popular each day. You may already have some data integration scenarios to <strong>read/write From REST API services in SQL Server</strong> or maybe API integration in other Apps such as Power BI, Tableau, SSIS, Informatica.</p>
<p>REST API integration can be challenging without the right set of tools. Even for highly skilled programmer sometimes its difficult to achieve the desired result.  But not to worry at the end of this article you will find out how easy it is to <strong>pull data from JSON / XML based web service using familiar SQL Query Language.</strong>  In the next few sections, you will learn how to call REST API inside SQL Server using familiar T-SQL code.</p>
<h2>Steps to Import JSON / XML REST API in SQL Server</h2>
<p>Here is the summary of steps to query REST API / JSON File in SQL Server (Using T-SQL code). For detailed steps read the full article and watch the video tutorial.</p>
<ol>
<li>Install <strong>ZappySys ODBC PowerPack </strong> <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">from here</a> (it contains drivers for JSON / XML API)</li>
<li>Create <strong>ODBC DSN</strong> for JSON / XML API Source</li>
<li>Configure <strong>ZappySys Data Gateway Service</strong> so SQL Server can use ZappySys Drivers in T-SQL code</li>
<li>Create and <strong>Configure Linked Server</strong> to connect to JSON / REST API Service</li>
<li>Write some <strong>T-SQL code</strong> in your stored procedure like below to import data from JSON / REST Service
<div id="attachment_3278" style="width: 866px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/03/example-import-json-rest-api-sql-server-tsql-stored-procedure.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3278" class="size-full wp-image-3278" src="https://zappysys.com/blog/wp-content/uploads/2018/03/How-to-import-REST-API-in-SQL-Server-1.png" alt="Example - Import JSON Files / REST API Data inside SQL Server ( Call API using T-SQL Stored Procedure)" width="856" height="687" /></a><p id="caption-attachment-3278" class="wp-caption-text">Example &#8211; Import JSON / XMLFiles / REST API Data into SQL Server Table ( Call API using T-SQL Stored Procedure)</p></div></li>
</ol>
<p>&nbsp;</p>
<h2>Video Tutorial &#8211; Read from JSON / XML / REST API in SQL Server (T-SQL code)</h2>
<p>If you want to save time and go quick then check out following video tutorial on calling JSON / REST API Service in SQL Server code. Steps The following video will be useful to configure your Linked Server and query REST API. It shows how to configure ODBC DSN, ZappySys Data Gateway Server (Used for Linked Server). To see other use cases of ZappySys Data Gateway <a href="https://zappysys.com/blog/category/odbc-powerpack/odbc-gateway/" target="_blank" rel="noopener">click here</a></p>
[youtube url=&#8221;https://www.youtube.com/watch?v=fLx6_C39LOQ&#8221;]
<p>&nbsp;</p>
[youtube url=&#8221;https://www.youtube.com/watch?v=M_Pm02ZQT8A&#8221;]
<h2>Requirements</h2>
<ol>
<li>A first requirement will be to SQL Server Database Engine Installed</li>
<li>The second requirement will be SSMS installed</li>
<li>Make sure to have <a href="https://zappysys.com/products/odbc-powerpack/">ZappySys ODBC PowerPack</a> installed.</li>
<li> Another important requirement is the internet connection to connect to REST API information using a URL.</li>
</ol>
<h2>Step-By-Step : Load REST API in SQL Server</h2>
<p>In next few sections, you will see step-by-step approach to consume REST API / JSON data in SQL Server using T-SQL code.</p>
<h3>Configure ZappySys Data Gateway Service</h3>
<p>To call external Drivers (e.g. ZappySys JSON/REST API Driver) in SQL Server we have to use <a href="https://docs.microsoft.com/en-us/sql/relational-databases/linked-servers/linked-servers-database-engine?view=sql-server-2017" target="_blank" rel="noopener">Linked Server feature</a>. We will use <a href="https://zappysys.com/products/odbc-powerpack/data-gateway/" target="_blank" rel="noopener">ZappySys Data Gateway Service</a> along with SQL Linked Server to call ZappySys Drivers (e.g. JSON / XML API Drivers) using T-SQL Code in Stored Procedures.</p>
<div class="content_block" id="custom_post_widget-5282">Now let's look at how to configure <a href="https://zappysys.com/products/odbc-powerpack/data-gateway/" target="_blank" rel="noopener">ZappySys Data Gateway</a>. This feature acts as a bridge between Client App and ZappySys Drivers. Using data gateway you can use ZappySys Drivers inside applications / operating systems where ZappySys drivers may not be available directly for some reason (e.g. You don't have access to Server for Installation or System does not support ODBC drivers like JAVA programs). <a href="https://zappysys.com/blog/category/odbc-powerpack/odbc-gateway/">Click here to read more</a> on various use cases of Data Gateway.
<h4><span style="font-size: 14pt;">Configure Data Gateway User / Port</span></h4>
Now let's look at steps to configure Data Gateway after installation. We will also create a sample data source for ODATA API (i.e. JSON based REST API Service).
<ol>
 	<li>Assuming you have installed <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> using default options (Which also enables Data Gateway Service)</li>
 	<li>Search "Gateway" in your start menu and click ZappySys Data Gateway
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png" alt="Open ZappySys Data Gateway" /></a>
<p class="wp-caption-text">Open ZappySys Data Gateway</p>

</div></li>
 	<li>First make sure Gateway Service is running (Verify Start icon is disabled)</li>
 	<li>Also verify Port on General Tab
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc-configure-data-gateway-json-1.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc-configure-data-gateway-json-1.png" alt="Port Number setting on ZappySys Data Gateway" /></a>
<p class="wp-caption-text">Port Number setting on ZappySys Data Gateway</p>

</div></li>
 	<li>Now go to Users tab. <strong>Click Add</strong> icon to add a new user. Check Is admin to give access to all data sources you add in future. If you don't check admin then you have to manually configure user permission for each data source.
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc-configure-data-gateway-json-2.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc-configure-data-gateway-json-2.png" alt="Add Data Gateway User" /></a>
<p class="wp-caption-text">Add Data Gateway User</p>

</div></li>
</ol>
&nbsp;
<h4><span style="font-size: 14pt;">Configure Data Source</span></h4>
<ol>
 	<li>After user is added, go to Data Sources tab. <strong>Click Add</strong> icon to create new data source. Select appropriate driver based on your API / File format. You can choose Generic ODBC option to read data from ODBC DSN or use Native Driver option.
<pre class=""><strong>NOTE:</strong> Whenever possible use native driver option for better performance / security and ease of use.</pre>
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc-configure-data-gateway-json-3.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc-configure-data-gateway-json-3.png" alt="Add Gateway Data Source (Native JSON Driver)" /></a>
<p class="wp-caption-text">Add Gateway Data Source (Native JSON Driver)</p>

</div></li>
 	<li>Click on "Edit" under Data source and configure as per your need (e.g. Url, Connection, Request Method, Content Type, Body, Pagination etc.). For this demo we are going to pick simple JSON REST API which doesn't need any authentication.  Enter following URL.
<pre class="">https://services.odata.org/V3/Northwind/Northwind.svc/Invoices?$format=json</pre>
</li>
 	<li>You can also view response structure and select default hierarchy (i.e. Filter) like below (Select Array Icon) for data extraction.
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc-configure-data-gateway-json-4.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc-configure-data-gateway-json-4.png" alt="Configure JSON API Data source" /></a>
<p class="wp-caption-text">Configure JSON API Data source</p>

</div></li>
</ol>
<h4><span style="font-size: 14pt;">Test SQL Query / Preview Data</span></h4>
<ol>
 	<li>Now go to Preview Tab. You can click Preview button to execute default query
OR
Select Table name from dropdown to generate SQL with column names.
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc-configure-data-gateway-json-5.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc-configure-data-gateway-json-5.png" alt="JSON / REST API Driver Query Preview / Query Examples (Read REST API or JSON Files)" /></a>
<p class="wp-caption-text">JSON / REST API Driver Query Preview / Query Examples (Read REST API or JSON Files)</p>

</div></li>
 	<li>You can also click Query Builder to generate SQL using different options in WITH clause. ANy setting you specify in WITH clause will override UI settings we applied in previous steps.
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc-configure-data-gateway-json-6.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc-configure-data-gateway-json-6.png" alt="Using SQL Query Builder (For Files or REST / SOAP API - JSON / XML / CSV Format)" /></a>
<p class="wp-caption-text">Using SQL Query Builder (For Files or REST / SOAP API - JSON / XML / CSV Format)</p>

</div></li>
 	<li>There is another useful option for code generation. Select your Language and quickly copy code snippet. See below Example of XML Driver Query to call SOAP API.
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc-configure-data-gateway-json-7.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/odbc-configure-data-gateway-json-7.png" alt="Generate Example Code for ZappySys Driver" /></a>
<p class="wp-caption-text">Generate Example Code for ZappySys Driver</p>

</div></li>
 	<li><strong>Click OK</strong> to Close Data Source UI</li>
 	<li>Once data source is tested and configured you can <strong>click Save </strong>button in the Gateway UI toolbar and click <strong>Yes</strong> for <strong>Restart Service</strong>.</li>
</ol>
&nbsp;</div>
<h4>Why use ZappySys Data Gateway Service?</h4>
<p>Gateway Service is useful to call ZappySys driver from any other machine without installing ZappySys driver. For example your Unix server can consume API data by connecting to ZappySys Data Gateway (which can be running on Remote Windows OS). Many times you cannot access remote server but like to Query API data (<a href="https://zappysys.com/api/integration-hub/google-sheets-connector/sql-server?context=connector" target="_blank" rel="noopener">Google SpreadSheet Use case).</a> To learn more about other use cases <a href="https://zappysys.com/blog/category/odbc-powerpack/odbc-gateway/" target="_blank" rel="noopener">click here</a>.</p>
<div class="su-note"  style="border-color:#e5dd9d;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;"><div class="su-note-inner su-u-clearfix su-u-trim" style="background-color:#FFF7B7;border-color:#ffffff;color:#333333;border-radius:3px;-moz-border-radius:3px;-webkit-border-radius:3px;">ZappySys has made API integration in SQL Server extremely easy, fast and secure by using very <strong>innovative approach</strong> for Microsoft SQL Server. Unlike other ODBC drivers available in the market we use very different approach. We use lightweight proxy service called <strong>ZappySys Data Gateway</strong> which runs outside the SQL Server Process / Memory Space. There are many advantages of this approach.</p>
<ul>
<li>Unlike other ODBC drivers, our drivers don&#8217;t affect SQL Server performance because it&#8217;s never loaded in the same SQL Server Process giving you total process isolation.</li>
<li>ZappySys Data Gateway Service acts like a small SQL Server itself. So any machine or any process can send SQL query to read/write data from API services or JSON files as long as communication happens using <a href="https://msdn.microsoft.com/en-us/library/dd304523.aspx" target="_blank" rel="noopener"><strong>TDS Protocol</strong></a>.</li>
<li>You can connect to ZappySys Data Gateway service using any  <a href="https://msdn.microsoft.com/en-us/library/dd304523.aspx" target="_blank" rel="noopener"><strong>TDS Protocol</strong></a> compatible driver (e.g. Microsoft native drivers for SQL Server such as ODBC, JDBC, OLEDB, ADO.net) ).</li>
<li>You can connect from any platform (e.g. <strong>Linux, Mac or Windows</strong>) using standard SQL Server Driver (many times already installed with OS).</li>
<li>You don&#8217;t have to install ZappySys Driver on the client machine with this approach.</li>
</ul>
</div></div>
<h3>Call REST API in SQL Server (T-SQL Code) using Linked Server</h3>
<div class="content_block" id="custom_post_widget-5289">Once you configured data source in Gateway, we can now setup Linked Server in SQL Server to query API data.
<ol style="margin-left: 10px;">
 	<li>Assuming you have installed SQL Server and SSMS. If not then get both for FREE from here: <a href="https://www.microsoft.com/en-us/sql-server/sql-server-editions-express">Get SQL Server Express</a> and  <a href="https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms" target="_blank" rel="noopener">Get SSMS</a></li>
 	<li>Open SSMS and connect to SQL Server.</li>
 	<li>Go to Root &gt; Server Objects &gt; Linked Servers node. Right click and click <strong>New Linked Server...
</strong>
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/03/create-new-linked-server-ssms.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/03/create-new-linked-server-ssms.png" alt="Add Linked Server in SQL Server" />
</a>
<p class="wp-caption-text">Add Linked Server in SQL Server</p>

</div></li>
 	<li> Now enter linked server name, select Provider as SQL Native Client</li>
 	<li>Enter data source as <strong><span class="lang:default decode:true crayon-inline">GatewayServerName,PORT_NUMBER</span></strong> where server name is where ZappySys Gateway is running (Can be same as SQL Server machine or remote machine). Default PORT_NUMBER is 5000 but confirm on Data gateway &gt; General tab incase its different.</li>
 	<li>Enter Catalog Name. This must match name from Data gateway Data sources grid &gt; Name column
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/ssms-sql-server-configure-linked-server-2.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/ssms-sql-server-configure-linked-server-2.png" alt="Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection" />
</a>
<p class="wp-caption-text">Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection</p>
</div>
<div style="color: #31708f;background-color: #d9edf7;border-color: #bce8f1;padding: 15px;margin-bottom: 20px;border: 1px solid transparent;border-radius: 4px;">
<strong>INFO:</strong><br/>
<ul>
    <li>
      For <strong>SQL Server 2012, 2014, 2016, 2017, and 2019</strong>, use the <em>SQL Server Native Client 11.0</em> as the Provider.
    </li>
    <li>
      For <strong>SQL Server 2022 or higher</strong>, use the <em>Microsoft OLE DB Driver for SQL Server</em> as the Provider.
    </li>
  </ul>
</div></li>
 	<li>Click on Security Tab and select last option "<strong>Be made using this security context</strong>". Enter your gateway user account here.</li>
<li>
        <p>Optional: Under the Server Options Tab, Enable <b>RPC</b> and <b>RPC Out</b> and Disable Promotion of Distributed Transactions<b>(MSDTC)</b>.</p>
		<div class="wp-caption alignnone">
			<img decoding="async" class="block margin-bottom-10 img-thumbnail" src="https://zappysys.com/blog/wp-content/uploads/2018/11/linked-server-options-rpc-msdtc.png" title="RPC and MSDTC Settings" alt="RPC and MSDTC Settings" />
			<p class="wp-caption-text">RPC and MSDTC Settings</p>
		</div>
        <hr />
        <p>
            You need to enable RPC Out if you plan to use <b><i>EXEC(...) AT [MY_LINKED_SERVER_NAME]</i></b> rather than OPENQUERY.
            <br />
            If don't enabled it, you will encounter the <i>'Server "MY_LINKED_SERVER_NAME" is not configured for RPC'</i> error.
        </p>
        <p>
            Query Example:
            <code class="sql">EXEC('Select * from Products') AT [MY_LINKED_SERVER_NAME]</code>
        </p>
        <hr />
        <p>
            If you plan to use <b><i>'INSERT INTO...EXEC(....) AT [MY_LINKED_SERVER_NAME]'</i></b> in that case you need to Disable Promotion of Distributed Transactions(MSDTC).
            <br />
            If don't disabled it, you will encounter the <i>'The operation could not be performed because OLE DB provider "SQLNCLI11/MSOLEDBSQL" for linked server "MY_LINKED_SERVER_NAME" was unable to begin a distributed transaction.'</i> error.
        </p>
        <p>
            Query Example:
<pre class="">Insert Into dbo.Products 
EXEC('Select * from Products') AT [MY_LINKED_SERVER_NAME]</pre>
        </p>
        <hr />
</li>
 	<li>Click OK to save Linked Server</li>
 	<li>In SSMS execute below SQL query to test your connectivity.
<pre class="">SELECT * FROM OPENQUERY( MY_LINKED_SERVER_NAME, 'SELECT * FROM $')</pre>
--OR--
<pre class="">SELECT * FROM OPENQUERY( MY_LINKED_SERVER_NAME, 
'SELECT * FROM $
 WITH (Src=''https://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json''
 ,Filter=''$.value[*]''
 ,DataFormat=''OData''
)');</pre>
</li>
 	<li>Here is the preview after you run some REST API query in SQL Server. Notice that you can override default configuration by supplying <a href="https://zappysys.com/onlinehelp/odbc-powerpack/scr/json-odbc-driver-connectionstring.htm" target="_blank" rel="noopener">many parameters</a> in WITH clause (second query example in screenshot).
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/11/query-rest-api-sql-server-linked-server-openquery-zappysys-data-gateway.png">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/query-rest-api-sql-server-linked-server-openquery-zappysys-data-gateway.png" alt="SSMS Output - Query REST API via Linked Server OPENQUERY statement (Connect to ZappySys Data Gateway)" />
</a>
<p class="wp-caption-text">SSMS Output - Query REST API via Linked Server OPENQUERY statement (Connect to ZappySys Data Gateway)</p>

</div></li>
 	<li>You can wrap your queries inside View or wrap inside Stored procedure to parameterize. Here is an example of create view which calls REST API queries. Below View can be consumed like a normal table from any Tools or Programming Language which supports connectivity to SQL Server.
<pre class="lang:tsql decode:true ">CREATE VIEW dbo.vwApiInvoices 
AS 
/*Call REST API inside SQL Server View*/
SELECT * FROM OPENQUERY( LS , 
'SELECT * FROM $
WITH (Src=''https://services.odata.org/V3/Northwind/Northwind.svc/Invoices?$format=json''
	 ,Filter=''$.value[*]''
	 ,DataFormat=''OData''
)');

GO
</pre>
&nbsp;</li>
 	<li>Notice in above approach if you parameterize Stored Procedure then <a href="https://zappysys.com/blog/create-csv-list-sql-server-table-columns-datatypes/" target="_blank" rel="noopener">check this article to understand Dynamic Metadata</a>.</li>
 	<li>That's it. We are now ready to move forward with more interesting things in next section.</li>
</ol></div>
<p>Optionally, use these lines of code to create the linked server using T-SQL instead of using the UI:</p><pre class="crayon-plain-tag">/* Add Linked Server called RESTAPI-SV (change if needed) to access REST API via Data Gateway - JSON/REST Driver */
/* customer_api is just an example data source name - created on Data gateway UI */

EXEC master.dbo.sp_addlinkedserver 
	@server = N'RESTAPI-SV', 
	@srvproduct=N'', 
--- For MSSQL 2012, 2014, 2016, 2017, and 2019 use below (SQL Server Native Client 11.0)---
    @provider=N'SQLNCLI11',
--- For MSSQL 2022 or higher use below (Microsoft OLE DB Driver for SQL Server)---
--- @provider=N'MSOLEDBSQL',
	@datasrc=N'localhost,5000', 
	@catalog=N'customer_api'

/* Add login for Linked Server - This is same user account and password which you define on Users tab on ZappySys Data Gateway Config Tool */
EXEC master.dbo.sp_addlinkedsrvlogin 
	@rmtsrvname=N'RESTAPI-SV',
	@useself=N'False',
	@locallogin=NULL,
	@rmtuser=N'admin',
	@rmtpassword='adminP@ss!23'
GO
--//OTHER IMPORTANT OPTIONS
EXEC master.dbo.sp_serveroption @server=N'RESTAPI-SV', @optname=N'rpc', @optvalue=N'true'
GO

EXEC master.dbo.sp_serveroption @server=N'RESTAPI-SV', @optname=N'rpc out', @optvalue=N'true'
GO

--Increase default timeout for long running query (default is 600 sec)
--EXEC master.dbo.sp_serveroption @server=N'RESTAPI-SV', @optname=N'query timeout', @optvalue=N'1200'
GO

--Below needed to support EXEC + INSERT (dynamic query)
EXEC master.dbo.sp_serveroption @server=N'RESTAPI-SV', @optname=N'remote proc transaction promotion', @optvalue=N'false'
GO</pre><p>
&nbsp;</p>
<ol>
<li>Now it is time to create some queries. Let&#8217;s run a simple query to REST API:<br />
<pre class="crayon-plain-tag">select * from OPENQUERY([RESTAPI-SV] , 'SELECT * FROM value' )</pre>
</li>
<li>The query will show all the data from REST API:
<div id="attachment_2945" style="width: 684px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/03/query-resp-api-results.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-2945" class="size-full wp-image-2945" src="https://zappysys.com/blog/wp-content/uploads/2018/03/query-resp-api-results.png" alt="Linked server query results" width="674" height="214" srcset="https://zappysys.com/blog/wp-content/uploads/2018/03/query-resp-api-results.png 674w, https://zappysys.com/blog/wp-content/uploads/2018/03/query-resp-api-results-300x95.png 300w" sizes="(max-width: 674px) 100vw, 674px" /></a><p id="caption-attachment-2945" class="wp-caption-text">REST API QUERY IN SQL SERVER</p></div>
<p>&nbsp;</li>
<li>Also, the following query can be used when you need to use filters (Notice that we escaped single tick with double tick)</p><pre class="crayon-plain-tag">select * from OPENQUERY([RESTAPI-SV] , 'SELECT * FROM value where ContactTitle=''Owner''' )</pre><p>
</li>
<li>Store the data in a temporary table using the following query:</p><pre class="crayon-plain-tag">select * INTO #tmpcustomer from OPENQUERY([RESTAPI-SV] , 'SELECT * FROM value' )</pre><p>
</li>
<li>And now you can query and use the SQL table:</p><pre class="crayon-plain-tag">SELECT * FROM #tmpcustomer t</pre><p>
</li>
<li>You can also check the metadata, values and odata_next link:</p><pre class="crayon-plain-tag">select * from OPENQUERY([RESTAPI-SV] , 'SELECT * FROM $' )</pre><p>
&nbsp;</li>
</ol>
<h3>Call REST API in SQL Server (T-SQL Code) using Polybase (For SQL 2019 or higher)</h3>
<div class="content_block" id="custom_post_widget-8745"><div style="padding: 0px 0px 10px 0px;">

Once you configured data source in Gateway or in ODBC DSN Data Source, we can now Configure PolyBase to access external data in SQL Server.

</div>
<div style="padding: 0px 0px 10px 0px;">

PolyBase in SQL Server 2019 allows you to connect to ODBC-compatible data sources through the ODBC connector. For more details refer to <a href="https://docs.microsoft.com/en-us/sql/relational-databases/polybase/polybase-configure-odbc-generic?view=sql-server-ver15" target="_blank" rel="noopener">this link</a>.

</div>
<div style="padding: 0px 0px 10px 0px;">

If you haven't installed PolyBase, Please refer to this <a href="https://docs.microsoft.com/en-us/sql/relational-databases/polybase/polybase-installation?view=sql-server-ver15" target="_blank" rel="noopener" data-linktype="relative-path">PolyBase installation instruction</a>.

</div>
<ol>
 	<li>Assuming you have installed SQL Server, SSMS and Polybase. If not then get both SQL Server and SSMS for FREE from here: <a href="https://www.microsoft.com/en-us/sql-server/sql-server-editions-express">Get SQL Server Express</a> and  <a href="https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms" target="_blank" rel="noopener">Get SSMS.</a></li>
 	<li>Open SSMS and connect to SQL Server.</li>
 	<li>After installing Polybase make sure you have an SSIS Catalog created. If you don't, create it in SSMS:
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-8843" src="https://zappysys.com/blog/wp-content/uploads/2020/02/call-rest-api-in-polybase-create-ssis-catalog-0.png" alt="" width="428" height="336" srcset="https://zappysys.com/blog/wp-content/uploads/2020/02/call-rest-api-in-polybase-create-ssis-catalog-0.png 428w, https://zappysys.com/blog/wp-content/uploads/2020/02/call-rest-api-in-polybase-create-ssis-catalog-0-300x236.png 300w" sizes="(max-width: 428px) 100vw, 428px" /></li>
 	<li>Configure the required settings:
<img loading="lazy" decoding="async" class="alignnone wp-image-8844 size-full" src="https://zappysys.com/blog/wp-content/uploads/2020/02/call-rest-api-in-polybase-create-ssis-catalog-e1583329508357.png" alt="" width="515" height="522" srcset="https://zappysys.com/blog/wp-content/uploads/2020/02/call-rest-api-in-polybase-create-ssis-catalog-e1583329508357.png 515w, https://zappysys.com/blog/wp-content/uploads/2020/02/call-rest-api-in-polybase-create-ssis-catalog-e1583329508357-296x300.png 296w" sizes="(max-width: 515px) 100vw, 515px" /></li>
 	<li>Also, make sure the SQL Server is configured to support TCP/IP protocol:
<img loading="lazy" decoding="async" class="alignnone size-full wp-image-8845" src="https://zappysys.com/blog/wp-content/uploads/2020/02/call-rest-api-in-polybase-enable-tcp-ip-in-sql-server.png" alt="" width="644" height="349" srcset="https://zappysys.com/blog/wp-content/uploads/2020/02/call-rest-api-in-polybase-enable-tcp-ip-in-sql-server.png 644w, https://zappysys.com/blog/wp-content/uploads/2020/02/call-rest-api-in-polybase-enable-tcp-ip-in-sql-server-300x163.png 300w" sizes="(max-width: 644px) 100vw, 644px" /></li>
 	<li><strong>(optional)</strong> If in later steps you get a <em>Login</em> error, try connecting to your database using <em><strong>SQL Server Authentication</strong></em> instead of <em>Windows Authentication</em>.</li>
 	<li>Now, in SSMS open the new query window and select the desired database in which you want to call an external ODBC data source.</li>
 	<li>First, we need to create the MASTER KEY in the database where you are trying to create the External Data Source
<pre class="">--1
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'My$tr0ngP@$$w0rd';</pre>
</li>
 	<li>Now we need to create a database scoped credential for accessing the ODBC source in the database.
<pre class="">--2
CREATE DATABASE SCOPED CREDENTIAL SqlServerCredentials WITH IDENTITY = 'username', Secret = 'password';</pre>
</li>
 	<li>Now go to our configured ZS Driver data source which one we created using Gateway or ODBC DSN Data Source and copy the connection string from there.
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/12/copy-connection-string-of-odbc-datasource-for-office-365-e1547488424263.png" target="_blank" rel="noopener">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/12/copy-connection-string-of-odbc-datasource-for-office-365-e1547488424263.png" alt="" />
</a>
<p class="wp-caption-text">Copy Connection String from the ZS Driver</p>

</div></li>
 	<li>Now Using that ZS Driver connection string and credentials we need to create the external data source.
<pre class=""><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">EXTERNAL</span> <span class="hljs-keyword">DATA</span> <span class="hljs-keyword">SOURCE</span> external_data_source_name
<span class="hljs-keyword">WITH</span> (LOCATION = odbc://&lt;ODBC <span class="hljs-keyword">server</span> address&gt;[:&lt;port&gt;],
CONNECTION_OPTIONS = <span class="hljs-string">'&lt;zs-driver-conection-string&gt;;
ServerNode = &lt;name of server  address&gt;:&lt;Port&gt;'</span>,
CREDENTIAL = &lt;credential_name&gt; );</pre>
So that our query looks like this, we need to use the same credentials name which one we created.
<pre class="">--3
CREATE EXTERNAL DATA SOURCE [ZappySys_Ext_CSV_Data_source] WITH (LOCATION = N'ODBC://127.0.0.1:5000', CREDENTIAL = [SqlServerCredentials],
CONNECTION_OPTIONS= 'DRIVER={ZappySys CSV Driver};DataPath='E:\zsTemp\Mydata.csv'')
</pre>
Or If you have created the ODBC System DSN Data Source
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2020/02/odbc-system-dsn-zs-csv-driver.png" target="_blank" rel="noopener">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2020/02/odbc-system-dsn-zs-csv-driver.png" alt="" />
</a>
<p class="wp-caption-text">ODBC System DSN : ZappySys CSV Driver</p>

</div>
We can pass the DSN Name also in the query instead of Zs driver connection string, in that case, we need to query like below to create the external data source
<pre class="">--3
CREATE EXTERNAL DATA SOURCE [ZappySys_Ext_CSV_Data_source] WITH (LOCATION = N'ODBC://127.0.0.1:5000', CREDENTIAL = [SqlServerCredentials],
CONNECTION_OPTIONS= 'DSN=zsDSN_MyCSVDriver')
</pre>
</li>
 	<li>Furthermore, we need to create the External Data Table for that external data source.
<pre class="">--4
CREATE EXTERNAL TABLE extTblPersons (
ID bigint NULL,
Name nvarchar(250) NULL
)
WITH (
LOCATION='_root_',
DATA_SOURCE = [ZappySys_Ext_CSV_Data_source] ,
)</pre>
For Location value, we need to pass the table name, from the ZS Driver Preview Tab we can download get the table name.
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2020/02/odbc-preview-tab-table-list.png" target="_blank" rel="noopener">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2020/02/odbc-preview-tab-table-list.png" alt="" />
</a>
<p class="wp-caption-text">ZS Driver Query Preview -Table List</p>

</div></li>
 	<li>That's it now execute the query using that external data table, it will retrieve the data from the external ODBC Data source. So here it will read the data from the Mydata.csv csv file and load the query data in the SQL Server.
<pre class="">--5
Select * From extTblPersons</pre>
<div class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2020/02/sql-server-query-result.png" target="_blank" rel="noopener">
<img decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2020/02/sql-server-query-result.png" alt="" />
</a>
<p class="wp-caption-text">SQL Server Query Result</p>

</div></li>
</ol></div>
<h2>How to use Dynamic SQL with parameters</h2>
<p>So far we saw how to use OPENQUERY statement with a static SQL query. Now let&#8217;s look at the dynamic Query approach to Read REST API data and Load into SQL Table. For Dynamic SQL you have to use EXEC rather than OPENQUERY.</p><pre class="crayon-plain-tag">--MSDTC option must be off for INSERT + EXEC pattern (Find Linked Server Properties | Server Options | Enable Promotion of Distributed Transaction - [Set to false]
--OR-- run via code like below
--EXEC master.dbo.sp_serveroption 'MyLinkedServer', 'remote proc transaction promotion', false;

declare @tbl nvarchar(100) = 'value'
--Just output the query data (no insert)
EXEC('select col1,col2 from ' + @tbl) AT [MyLinkedServer]

--Load into table (dont output)
insert into _tmp_invoices(col1,col2) 
EXEC('select col1,col2 from ' + @tbl) AT [MyLinkedServer]

--We recommend using column names in the list rather than * (all) to avoid metdata issue
--Use Data Source &gt; Preview UI &gt; Table dropdown to generate column names</pre><p>
&nbsp;</p>
<h2>How to parameterize API calls in SQL Server</h2>
<p>Now you know how to write simple SQL queries to fetch data from API. In real world you will have a need to pass parameters to your API. You can pass parameters to your API following ways.  Notice that how we have escaped single tick. In this example we have passed Header, Body and URL using Dynamic approach. In your case you may need to pass only one way (e.g. Pass parameter via URL only)</p><pre class="crayon-plain-tag">declare @url varchar(100)='http://httpbin.org/post' 
declare @body varchar(100)='{id:1,notes:"Line1\r\nLine2"}'
declare @header varchar(100)='Content-Type:text/plain||x-hdr1:AAA'

declare @sql varchar(1000)
declare @sqlForLs  varchar(1000) = 
'SELECT * FROM $
WITH  (
SRC='''+ replace(@url,'''', '''''')  +''' ,
METHOD=''POST'' ,
HEADER='''+ replace(@header,'''', '''''')  +''' ,
BODY='''+ replace(@body,'''', '''''')  +''' 
)'
 
set @sql = 'SELECT * into #tmp from OPENQUERY(LS,''' + replace(@sqlForLs,'''', '''''') + ''')'
print @sql

EXECUTE(@sql);</pre><p>
&nbsp;</p>
<h2>How to Import JSON File to SQL Server (Single or Multiple)</h2>
<p>Not only you can query REST API in SQL Server but also you can query a JSON file. The steps are all the same except in one step. Instead of specifying a URL in the ZappySys ODBC driver (see Add the ZappySys driver in the Windows ODBC Administrator section, step 7) and specify the <strong>file path</strong> and set the format to <strong>Default:</strong></p>
<div id="attachment_2953" style="width: 621px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/03/How-to-import-REST-API-in-SQL-Server-2.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-2953" class="size-full wp-image-2953" src="https://zappysys.com/blog/wp-content/uploads/2018/03/How-to-import-REST-API-in-SQL-Server-2.png" alt="JSON file properties" width="611" height="595" /></a><p id="caption-attachment-2953" class="wp-caption-text">Add properties JSON file</p></div>
<p>If you dont want to hard code file name in the DSN then you can also use following Query syntax to specify URL or File Path inside SQL Query</p><pre class="crayon-plain-tag">select * into #tmp from OPENQUERY([JSON-SV], 'SELECT * FROM value WITH (SRC=''C:\test\cust2012.json'')' )</pre><p>
<h2>How to load multiple JSON files into SQL Server Table</h2>
<p>Let&#8217;s say that you have multiple JSON files in a folder (similar structure). The file names are customer_2012.json, customer_2013.json, customer_2014.json and they are all in the same folder. Is it possible to query all of them in SQL Server without any extra looping code?</p>
<p>The answer is yes. You just need to create the linked server to a single JSON file and then run this query (JSON-SV is the name of the linked server):</p><pre class="crayon-plain-tag">select * into #tmp from OPENQUERY([JSON-SV], 'SELECT * FROM value WITH (SRC=''C:\test\cust*.json'')' )</pre><p>
We are just using this code:</p><pre class="crayon-plain-tag">(SRC=''C:\test\cust*.json'')' )</pre><p>
SRC means source and it will search all the files with json extension starting with the word &#8220;cust&#8221;.</p>
<h2>How to read and parse JSON string in T-SQL</h2>
<p>In SQL Server 2016 and later, it is possible to read JSON data. However in older versions, it was not possible. The following example will show how to parse JSON data using a Linked Server named JSON-SV.</p>
<ol>
<li style="list-style-type: none;">
<ol>
<li>We will first store JSON values in a SQL Server table in a column named MyData:<br />
<pre class="crayon-plain-tag">create table #tmp(MyData nvarchar(max))

insert into #tmp values(
'{ 
rows:[ 
{id:1, name:"Sam''s Club"}, 
{id:2, name:"Walmart"}, 
{id:3, name: "Facebook"} 
]
}')</pre>
</li>
<li>We just created a temporary table named tmp and in the column MyData, we stored JSON values. In the next step, we will store the values of the temporary table in a variable named json and store and parse the values en the variable sql:<br />
<pre class="crayon-plain-tag">declare @json nvarchar(max)
declare @sql nvarchar(max)

select @json = MyData from #tmp


set @sql='select * from OPENQUERY([JSON-SV] , ''SELECT * FROM rows WITH
(DATA=@'''''+ Replace(@json ,'''','''''''''') +''''')'' );'
print(@sql)
execute(@sql)</pre>
</li>
<li>If everything is OK, you will be able to see the JSON values parsed in a nice table format:
<div id="attachment_2960" style="width: 200px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/03/parse-json-sql-server.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-2960" class="size-full wp-image-2960" src="https://zappysys.com/blog/wp-content/uploads/2018/03/parse-json-sql-server.png" alt="Parse JSON values" width="190" height="111" /></a><p id="caption-attachment-2960" class="wp-caption-text">JSON values parsed</p></div></li>
</ol>
</li>
</ol>
<h2>How to Call REST API from a SQL Stored Procedure</h2>
<p>How can we call REST API using a stored procedure? We need to use dynamic queries to pass parameters. The following example will run a query where the city is specified in a variable.</p>
<ol>
<li>We will create the stored procedure first:<br />
<pre class="crayon-plain-tag">CREATE PROCEDURE getcity 
@City NVARCHAR(50) 
AS 
DECLARE @sql NVARCHAR(500)='select * from OPENQUERY([RESTAPI-SV] , 
''SELECT * FROM value where City=''''' + @City + ''''''')' 
EXECUTE(@sql)</pre>
</li>
<li>The stored procedure name is getcity. We will call the RESTAPI-SV that calls the REST API and pass the parameter City in the query. We finally execute the query stored in the variable using the Execute statement.</li>
<li>Finally, we just invoke the stored procedure:<br />
<pre class="crayon-plain-tag">EXECUTE getcity @City = N'Berlin'</pre>
The query will display all the data with the city equal to Berlin.</li>
</ol>
<h2>How to POST data to REST API in SQL Server (Send data to URL)</h2>
<p>The following example shows how to POST data to API service where data is coming from an embedded string in SQL Server using a Linked Server. I am assuming that you already created a linked server following previews steps explained before.</p>
<h3>POST data to URL (embedded Body)</h3>
<p>In SSMS run this query:</p><pre class="crayon-plain-tag">select * from OPENQUERY([RESTAPI-SV] , 'SELECT * FROM $ 
WITH (
 METHOD=''POST''
,HEADER=''Content-Type: application/json || x-hdr1: AAA''
,SRC=''http://httpbin.org/post''
,BODY=''{ id:2,  notes2:"Line1\r\nLine2" }''
)' 
)</pre><p>
The query will invoke the Linked Server for REST API, created before and use the POST Method with the embedded strings.</p>
<h3>POST data to URL (read body from file)</h3>
<p>Here is an example to POST data to URL where Body is read from Local file. Notice two additional attributes in below.  We set IsMultiPart=true and also Body has @ symbol before file path.</p><pre class="crayon-plain-tag">select * from OPENQUERY([RESTAPI-SV] , 'SELECT * FROM $ 
WITH (
 METHOD=''POST''
,HEADER=''Content-Type: application/json || x-hdr1: AAA''
,SRC=''http://httpbin.org/post''
,BODY=''@c:\data\api_call_body.json''
,IsMultiPart='True'
)' 
)</pre><p>
<h3>Avoiding errors with POST / PUT / DELETE  requests to create / modify /delete data</h3>
<p>There will be a time you may get error when you issue POST requests because same request sent multiple times and duplicate records got created. To avoid such situation <a href="https://zappysys.com/blog/caching-metadata-odbc-drivers-performance/" target="_blank" rel="noopener">refer to this article</a> (Read Handling POST request section)</p>
<h2>Pagination Concepts for REST API / SOAP XML  in SQL Server</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 for REST API / SOAP XML in SQL Server</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>OAuth / HTTP Connection in SQL Server</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 Tips for REST API / XML SOAP 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 Calling Web API in SQL Server</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>Calling XML SOAP Web Service in SQL Server</h2>
<p>So far we have looked at examples to consume data using JSON driver. Now let&#8217;s look at an example, to call XML SOAP Web Service.</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>OPENQUERY vs EXEC AT (Handling Larger SQL Text)</h2>
<p>So far we have seen examples of using OPENQUERY. It allows us to send pass-through query at remote server. The biggest limitation of OPENQUERY is it doesnt allow you to use variables inside SQL so often we have to use unpleasant looking dynamic SQL (Lots of tick, tick &#8230;.  and escape  hell). Well there is good news. With SQL 2005 and later you can use <pre class="crayon-plain-tag">EXEC( your_sql ) AT your_linked_server syntax</pre> .</p>
<p>Disadvantage of EXEC AT is you cannot do SELECT INTO like OPENQUERY. Also you cannot perform JOIN like below in EXEC AT</p><pre class="crayon-plain-tag">SELECT a.* FROM OPENQUERY(ls_json,'select * from $') a 
JOIN  OPENQUERY(ls_json,'select * from $') b ON a.id=b.id</pre><p>
However you can always do INSERT INTO MyTable EXEC(&#8230;) AT LINKEDSRV. So table must exists when you do that way.</p>
<p>Here is how to use it. To use EXEC AT you must turn on <strong>RPC OUT</strong> option. Notice how we used variable in SQL to make it dynamic. This is much cleaner than previous approach we saw.</p><pre class="crayon-plain-tag">USE [master]
GO

EXEC master.dbo.sp_addlinkedserver @server = N'ls_Json', @srvproduct=N'', @provider=N'SQLNCLI', @datasrc=N'localhost,5000', @provstr=N'Network Library=DBMSSOCN;', @catalog=N'JsonApi'
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'ls_Json',@useself=N'False',@locallogin=NULL,@rmtuser=N'tdsuser',@rmtpassword='########'
GO

EXEC sp_serveroption 'ls_Json', 'rpc out', true;  
go

declare @tbl varchar(100)='$'
EXEC('select * from ' + @tbl ) AT ls_Json</pre><p>
Here is the difference between OPENQUERY vs EXEC approaches.</p>
<div id="attachment_7968" style="width: 721px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/03/openquery-vs-exec-sql-server-linked-server-text-limit.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7968" class="size-full wp-image-7968" src="https://zappysys.com/blog/wp-content/uploads/2018/03/openquery-vs-exec-sql-server-linked-server-text-limit.png" alt="SQL Server OPENQUERY vs EXEC for Linked Server - Handling Larger SQL Text (More than 8000 chars)" width="711" height="485" srcset="https://zappysys.com/blog/wp-content/uploads/2018/03/openquery-vs-exec-sql-server-linked-server-text-limit.png 711w, https://zappysys.com/blog/wp-content/uploads/2018/03/openquery-vs-exec-sql-server-linked-server-text-limit-300x205.png 300w" sizes="(max-width: 711px) 100vw, 711px" /></a><p id="caption-attachment-7968" class="wp-caption-text">SQL Server OPENQUERY vs EXEC for Linked Server &#8211; Handling Larger SQL Text (More than 8000 chars)</p></div>
<p>&nbsp;</p>
<p>If you decide to use EXEC instead of OPENQUERY then make sure below setting is ON else you will get an error.</p>
<p>Under the Linked Server Options, Enable <b>RPC</b> and <b>RPC Out</b> and Disable Promotion of Distributed Transactions<b>(MSDTC)</b>.</p>
<div id="attachment_10949" style="width: 700px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/03/linked-server-options-rpc-msdtc.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-10949" class="size-full wp-image-10949" src="https://zappysys.com/blog/wp-content/uploads/2018/03/linked-server-options-rpc-msdtc.png" alt="linked-server-options-rpc-msdtc" width="690" height="625" srcset="https://zappysys.com/blog/wp-content/uploads/2018/03/linked-server-options-rpc-msdtc.png 690w, https://zappysys.com/blog/wp-content/uploads/2018/03/linked-server-options-rpc-msdtc-300x272.png 300w" sizes="(max-width: 690px) 100vw, 690px" /></a><p id="caption-attachment-10949" class="wp-caption-text">RPC OUT setting for EXEC AT statement in SQL Server Linked Server</p></div>
<p>&nbsp;</p>
<h2>Configure Firewall Settings</h2>
<p>So far we have assumed that Gateway is running on the same machine as SQL Server. However there will be a case when ZappySys ODBC PowerPack is installed on a different machine than SQL Server.  In such case you may have to perform additional Firewall configurations. On most computers firewall settings wont allow outside traffic to ZappySys Data Gateway. In such case perform following steps to allow other machines to connect to Gateway.</p>
<ol>
<li>Search for Windows Firewall Advanced Security in start menu.</li>
<li>Under Inbound Rules &gt; Right click and click [New Rule] &gt;&gt; Click Next</li>
<li>Select Port on Rule Type &gt;&gt; Click Next</li>
<li>Click on TCP and enter port number under specified local port as 5000 (use different one if you changed Default port) &gt;&gt; Click Next</li>
<li>Select Profile (i.e. Private, Public) &gt;&gt; Click Next</li>
<li>Enter Rule name [i.e. ZappySys Data Gateway &#8211; Allow Inbound ] &gt;&gt; Click Next</li>
<li>Click OK to save the rule</li>
</ol>
<div id="attachment_7250" style="width: 826px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/03/zappysys-data-gateway-firewall-rule-allow-traffic.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7250" class="size-full wp-image-7250" src="https://zappysys.com/blog/wp-content/uploads/2018/03/zappysys-data-gateway-firewall-rule-allow-traffic.png" alt="ZappySys Datagateway - Allow Inbound Traffic on Port 5000 Firewall Rule" width="816" height="319" srcset="https://zappysys.com/blog/wp-content/uploads/2018/03/zappysys-data-gateway-firewall-rule-allow-traffic.png 816w, https://zappysys.com/blog/wp-content/uploads/2018/03/zappysys-data-gateway-firewall-rule-allow-traffic-300x117.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/03/zappysys-data-gateway-firewall-rule-allow-traffic-768x300.png 768w" sizes="(max-width: 816px) 100vw, 816px" /></a><p id="caption-attachment-7250" class="wp-caption-text">ZappySys Datagateway &#8211; Allow Inbound Traffic on Port 5000 Firewall Rule</p></div>
<h2>Known Issues</h2>
<p>In this section we will discuss some known issues when using OPENQUERY / Data Gateway Connectivity</p>
<h3>Error: The data is invalid</h3>
<p>There will be a time when you start facing odd errors such as below. Possible</p><pre class="crayon-plain-tag">OLE DB provider "SQLNCLI11/MSOLEDBSQL" for linked server "Zs_Csv" returned message "Deferred prepare could not be completed.".
OLE DB provider "SQLNCLI11/MSOLEDBSQL" for linked server "Zs_Csv" returned message "Communication link failure".
Msg 13, Level 16, State 1, Line 0

Session Provider: The data is invalid.</pre><p>
<strong>Possible Cause:</strong></p>
<p>There are few reasons for such error but below are two main reasons</p>
<ul>
<li>If query length is more than 2000 Characters long such as below then you might get such error<br />
<pre class="crayon-plain-tag">SELECT * FROM OPENQUERY(LS, '--some really long text more than 2000 chars--')</pre>
</li>
<li>If query contains multiple OPENQUERY statements for JOIN / UNION like below then also it might fail (Gateway doesnt support parallel queries on a single connection &#8211; MARS compatibility issue).<br />
<pre class="crayon-plain-tag">select a.id, b.name from OPENQUERY(LS, 'select * from tbl1') a join OPENQUERY(LS, 'select * from tbl2') b on a.id=b.id</pre>
</li>
</ul>
<p><strong>Possible Fix:</strong></p>
<p>There are few ways to fix above error based on reason why you getting this error (i.e. Query Length issue OR JOIN/UNION in the same statement)</p>
<ul>
<li>If your query has long SQL (more than 2000 chars ) then reduce SQL length using different techniques
<ul>
<li>e.g. use SELECT * FROM MyTable rather than SELECT col1,col2&#8230; FROM MyTable</li>
<li>Use Meta Option in WITH clause if you must use column name. (e.g. SELECT * FROM MyTable WITH(META=&#8217;c:\meta.txt&#8217;) this way you can define column in Meta file rather than SELECT query. <a href="https://zappysys.com/blog/caching-metadata-odbc-drivers-performance/" target="_blank" rel="noopener">Check this article</a></li>
<li>Consider using EXECT (&#8230;.) AT [Linked_Server_name] option rather than OPENQUERY so you can use very long SQL (See next section on EXEC..AT usecase)</li>
<li>Consider <a href="https://zappysys.com/blog/odbc-drivers-custom-objects-feature/" target="_blank" rel="noopener">using Virtual Table / Stored Proc</a> to wrap long SQL so your call is very small (where usp_GetOrdersByYear is custom proc created on ZappySys Driver UI)<br />
<pre class="crayon-plain-tag">SELECT * FROM OPENQUERY(LS, 'EXEC usp_GetOrdersByYear 2021')</pre>
</li>
</ul>
</li>
<li>If your query uses JOIN  / UNION with multiple OPENQUERY in same SQL then use multiple Linked servers (one for each OPENQUERY clause) as below.<br />
<pre class="crayon-plain-tag">select a.id, b.name from OPENQUERY(LS_1, 'select * from tbl1') a join OPENQUERY(LS_2, 'select * from tbl2') b on a.id=b.id</pre>
</li>
</ul>
<h3>Error: Unable to begin a distributed transaction (When INSERT + EXEC used)</h3>
<p>If you try to use EXEC statement and try to insert data into table (like below) you might get below error unless MSDTC option is turned off.</p><pre class="crayon-plain-tag">INSERT INTO MyTable EXEC('select * from tbl') AT MyLinkedServer</pre><p>
</p><pre class="crayon-plain-tag">"Protocol error in TDS stream"
The operation could not be performed because OLE DB provider "SQLNCLI11" for linked server "ls_Json2" was unable to begin a distributed transaction.
--OR--
The operation could not be performed because OLE DB provider "MSOLEDBSQL" for linked server "ls_Json" was unable to begin a distributed transaction.</pre><p>
<b>Solution:</b><br />
<strong>Method-1:</strong> Go to linked server properties | Server Options | <strong>Enable Promotion of Distributed Transaction</strong> | Change to false (Default is true)<br />
Now your try your INSERT with EXEC AT and it should work</p>
<p><strong>Method-2: </strong>Run the below command if you dont want to use UI</p><pre class="crayon-plain-tag">EXEC master.dbo.sp_serveroption @server=N'My_Linked_Server', @optname=N'remote proc transaction promotion', @optvalue=N'false'</pre><p>
<h3>Error: Cannot use OPENQUERY with JOIN / UNION</h3>
<p>When you perform JOIN  / UNION ALL on the same Linked Server it may fail to process sometimes because Datagateway doesnt support parallel query requests on the same connection. Workaround for that would be create multiple linked servers for the same datasource. See above section for the same workaround.</p>
<h3>Error: Truncation errors due to data length mismatch</h3>
<p>Many time you may receive truncation errors if Table column is length is less than actual column size from query column. To solve this issue use New version of Data gateway ( check &#8211; Use nvarchar(max) for string options &#8211; Found on General Tab)</p>
<h2>Performance Tips</h2>
<p>Now lets look at few performance tips</p>
<h3>Use INSERT INTO rather than SELECT INTO to avoid extra META request</h3>
<p>We discussed some Pros and Cons of <strong>OPENQUERY</strong> vs <strong>EXEC (&#8230;) AT</strong> in previous section. One obvious advantage of EXEC (&#8230;.) AT is it reduces number of requests to driver (It sends pass through query). With EXEC you cannot load data dynamically like SELECT INTO tmp FROM OPENQUERY. Table must exist before hand if you use EXEC.</p><pre class="crayon-plain-tag">INSERT INTO tmp_API_Report_Load(col1,col2)
EXEC('select col1,col2 from some_api_table') AT [API-LINKED-SERVER]
--OR--
INSERT INTO tmp_API_Report_Load(col1,col2)
select col1,col2 from OPENQUERY([API-LINKED-SERVER], 'select col1,col2 from some_api_table')</pre><p>
Advantage of this method is your Query speed will increase because system calls API only once when you call EXEC AT. In OPENROWSET it needs to call above query twice (Once to obtain metadata and once to get data).</p>
<h3>Use Cached Metadata if possible</h3>
<p>By default, most of the SQL sent to Data gateway need to invoke two phases. First, get metadata and second fetch data. You can bypass meta API call by supplying static metadata. Use META property in WITH clause as per <a href="https://zappysys.com/blog/caching-metadata-odbc-drivers-performance/" target="_blank" rel="noopener">this article</a> to speed up your SQL.</p>
<p>&nbsp;</p>
<h2>Conclusion</h2>
<p>To conclude, we can say that using ZappySys JSON / XML Drivers we can query JSON / XML Files and call REST API or SOAP Web Service using familiar SQL Language. All you need to do is install ZappySys ODBC Drivers, configure it in the ODBC DSN and use ZappySys Gateway as a Proxy. Finally, you add a Linked Server in SQL Server to connect to ZappySys Data Gateway. Feel free to download  <a href="https://zappysys.com/products/odbc-powerpack/">ZappySys Drivers here</a>. You can contact ZappySys Team <a href="https://zappysys.com/support/" target="_blank" rel="noopener">here</a> if you need any API integration help.</p>
<h2>References</h2>
<ul>
<li><a href="https://zappysys.com/onlinehelp/odbc-powerpack/">ZappySys ODBC PowerPack online help</a></li>
<li><a href="https://docs.microsoft.com/en-us/sql/relational-databases/json/json-data-sql-server">JSON data in SQL Server</a></li>
<li><a href="https://docs.microsoft.com/en-us/sql/relational-databases/linked-servers/linked-servers-database-engine">Linked Servers (Database Engine)</a></li>
</ul>
<p>Keywords: Call REST API, SQL SERVER, JSON</p>
<p>The post <a href="https://zappysys.com/blog/import-rest-api-json-sql-server/">How to import REST API in SQL Server (Call JSON / XML SOAP Service)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
