<?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>ODBC Gateway Archives | ZappySys Blog</title>
	<atom:link href="https://zappysys.com/blog/category/odbc-powerpack/odbc-gateway/feed/" rel="self" type="application/rss+xml" />
	<link>https://zappysys.com/blog/category/odbc-powerpack/odbc-gateway/</link>
	<description>SSIS / ODBC Drivers / API Connectors for JSON, XML, Azure, Amazon AWS, Salesforce, MongoDB and more</description>
	<lastBuildDate>Mon, 06 Apr 2026 11:45:09 +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>ODBC Gateway Archives | ZappySys Blog</title>
	<link>https://zappysys.com/blog/category/odbc-powerpack/odbc-gateway/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to add non-admin user access for linked servers</title>
		<link>https://zappysys.com/blog/how-to-add-non-admin-user-access-for-linked-servers/</link>
		
		<dc:creator><![CDATA[ZappySys Team]]></dc:creator>
		<pubDate>Thu, 19 Mar 2026 23:03:05 +0000</pubDate>
				<category><![CDATA[ODBC Gateway]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=11873</guid>

					<description><![CDATA[<p>Introduction When you create a linked server, the connection succeeds, but the query fails. By default, non-admin users do not have access to a Linked Server in SQL Server. When such users attempt to query a Linked Server, they may encounter errors similar to the following: [crayon-69d62bd6ea7eb292963216/] This issue occurs because the Linked Server does [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/how-to-add-non-admin-user-access-for-linked-servers/">How to add non-admin user access for linked servers</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p>When you create a linked server, the connection succeeds, but the query fails. By default, non-admin users do not have access to a Linked Server in SQL Server. When such users attempt to query a Linked Server, they may encounter errors similar to the following:</p><pre class="crayon-plain-tag">OLE DB provider &quot;SQLNCLI11&quot; 
for linked server &quot;ZappySysLink&quot; returned message &quot;Unable to open a logical session&quot;. 

Msg -1, Level 16, State 1, Line 0 

SMux Provider: Physical connection is not usable [xFFFFFFFF].</pre><p>
This issue occurs because the Linked Server does not have a login mapping configured for the user executing the query.</p>
<h2>Cause</h2>
<div>
<div>A Linked Server in SQL Server is treated similarly to a database for security purposes. Access is not automatically granted to all users.</div>
</div>
<p>1. Non-admin users do not inherit access to Linked Servers by default.<br />
2. No login mapping exists between the local SQL Server login and the remote Linked Server credentials.<br />
3. SQL Server cannot determine which remote credentials to use when the user connects.</p>
<p>For admin users, SQL Server often uses the default option &#8220;Be made using this security context&#8221;, which allows access without additional configuration.</p>
<h2>Solution</h2>
<div>
<div>To resolve this issue, you must explicitly map the local login to a remote login for the Linked Server. Follow these steps:</div>
</div>
<div>
<ol>
<li>Remove any existing incorrect login mapping (optional but recommended)
<div>
<pre class="crayon-plain-tag">EXEC sp_droplinkedsrvlogin
    @rmtsrvname = 'YourLinkedServerName',
    @locallogin = 'MyDomain\User1';</pre>
</div>
</li>
<li>Create a new login mapping for the Linked Server:
<div>
<pre class="crayon-plain-tag">EXEC sp_addlinkedsrvlogin
    @rmtsrvname = 'YourLinkedServerName', -- Linked Server name
    @useself = 'false',
    @locallogin = 'MyDomain\User1',       -- Local Windows user
    @rmtuser = 'gateway_Admin',           -- Remote (Linked Server) login
    @rmtpassword = 'gateway_pass123';     -- Remote password</pre>
</div>
</li>
<li>
<div>Verify the configuration:</p>
<div>
<div>&#8211; Open <strong>Linked Server Properties</strong> in SQL Server Management Studio (SSMS).</div>
<div>&#8211; Go to the <strong>Security</strong> tab.</div>
<div>&#8211; Confirm that your local login is mapped to the correct remote user.</p>
<div id="attachment_11881" style="width: 720px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2026/03/Linked-server-security-tab.png"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-11881" class="size-full wp-image-11881" src="https://zappysys.com/blog/wp-content/uploads/2026/03/Linked-server-security-tab.png" alt="" width="710" height="662" srcset="https://zappysys.com/blog/wp-content/uploads/2026/03/Linked-server-security-tab.png 710w, https://zappysys.com/blog/wp-content/uploads/2026/03/Linked-server-security-tab-300x280.png 300w" sizes="(max-width: 710px) 100vw, 710px" /></a><p id="caption-attachment-11881" class="wp-caption-text">Linked server &#8211; security tab</p></div>
</div>
</div>
</div>
</li>
<li>
<div>Test the Linked Server query again using the non-admin user.</div>
</li>
</ol>
<div>After completing these steps, SQL Server will use the specified remote credentials when the mapped user accesses the Linked Server.</div>
<h2>Conclusion</h2>
</div>
<div>
<div>Non-admin users cannot access Linked Servers by default because no login mapping is defined. SQL Server requires explicit credential mapping to determine which remote account to use.</div>
<div>By configuring login mappings using <code>sp_addlinkedsrvlogin</code>, you can grant controlled access to Linked Servers and ensure queries execute successfully without connection errors.</div>
<h2>Still need help?</h2>
<div>If the issue persists, please get in touch with our support team:</div>
<ul style="list-style-type: circle;">
<li><strong>Live Chat</strong>: Open the chat widget (bottom right of this page)</li>
<li><strong>Email</strong>: support@zappysys.com</li>
<li><strong>Support Center</strong>: https://zappysys.com/support/</li>
</ul>
</div>
<p>The post <a href="https://zappysys.com/blog/how-to-add-non-admin-user-access-for-linked-servers/">How to add non-admin user access for linked servers</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Secure ZappySys Data Gateway (Network Settings)</title>
		<link>https://zappysys.com/blog/secure-zappysys-data-gateway-network-settings/</link>
		
		<dc:creator><![CDATA[Sudhir Dandale]]></dc:creator>
		<pubDate>Tue, 19 Apr 2022 19:32:34 +0000</pubDate>
				<category><![CDATA[ODBC Gateway]]></category>
		<category><![CDATA[data gateway]]></category>
		<category><![CDATA[odbc]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=9588</guid>

					<description><![CDATA[<p>Introduction In our previous article we explored several powerful features of the ZappySys Data Gateway. This follow‑up post focuses on keeping the gateway secure. You’ll learn about the new options available in the Network Settings tab, how to restrict access by IP address, and how to grant dataset‑level permissions to non‑admin users. Network Settings Overview [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/secure-zappysys-data-gateway-network-settings/">How to Secure ZappySys Data Gateway (Network Settings)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2 class="versubtitle"><span id="Introduction">Introduction</span></h2>
<p>In our <a href="https://zappysys.com/blog/import-rest-api-json-sql-server/" target="_blank" rel="noopener">previous article</a> we explored several powerful features of the <strong>ZappySys Data Gateway</strong>. This follow‑up post focuses on keeping the gateway secure. You’ll learn about the new options available in the <em>Network Settings</em> tab, how to restrict access by IP address, and how to grant dataset‑level permissions to non‑admin users.</p>
<div class="content_block" id="custom_post_widget-9166"><h2>Requirements</h2>
In order to access API data inside your App using ODBC Driver you will need to make sure following requirements 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>
</ol></div>
<h2><span style="font-size: 14pt;">Network Settings Overview</span></h2>
<p>The <strong>Network Settings</strong> tab contains filters that control which clients can connect to the gateway. Two common scenarios are addressed below: allowing a range of IP addresses, or permitting only a single IP address.</p>
<p><strong>If your connection still fails even after opening port 5000, a third-party firewall is very likely blocking it.</strong></p>
<p>
The <strong>“Add Firewall Rule”</strong> option only creates a rule in Windows Defender Firewall and does not configure rules in third-party security software.
</p>
<p>
Common symptoms of this issue include:
</p>
<ul>
<li>Login timeout or connection timeout errors</li>
<li>OPENQUERY or Linked Server failing to connect</li>
<li>Port appears open in Windows Firewall but connection still fails</li>
</ul>
<h3>Third-Party Firewall Blocking Gateway Connection</h3>
<p>
When you click <strong>“Add Firewall Rule”</strong> in ZappySys Data Gateway, the rule is added to <strong>Windows Defender Firewall</strong> to allow inbound traffic on the configured port (default: 5000).
</p>
<p>In environments with third-party security software, this alone may not be sufficient.</p>
<h4>Why?</h4>
<p>
If your system is using third-party security software (such as <strong>ESET Endpoint Security</strong>, McAfee, Symantec, etc.), Many enterprise antivirus tools include their own firewall, which takes priority over or replaces Windows Defender Firewall.<br />
For example, in one case, the rule was added successfully in Windows Firewall, but traffic was still blocked by ESET Endpoint Security. Once the ESET firewall was paused, the connection worked immediately.<br />
In such cases:
</p>
<ul>
<li>Windows Defender rules may be ignored</li>
<li>Traffic can still be blocked even if the port is open in Windows Firewall</li>
<li>Connection attempts (e.g., Linked Server, ODBC queries) may fail with timeout errors</li>
</ul>
<h4>What to check</h4>
<p>
If you are unable to connect even after adding the firewall rule:
</p>
<ul>
<li>Verify whether any third-party firewall/antivirus is installed</li>
<li>Temporarily disable or pause it for testing</li>
<li>If the connection works after disabling, then the traffic is being blocked by that software</li>
</ul>
<h4>How to fix</h4>
<p>
To resolve this issue:
</p>
<ul>
<li>Add an <strong>inbound allow rule</strong> in your third-party firewall for the Gateway port (default: 5000)</li>
<li>Ensure the rule allows traffic from the required source machines</li>
<li>Ensure both <strong>inbound and outbound rules</strong> are allowed if required by your network policy</li>
<li>Ensure rules are applied under the correct network profile (Domain / Private / Public)</li>
<li>Contact your <strong>network/security administrator</strong> if needed</li>
</ul>
<h4>Test connectivity</h4>
<p>You can verify if the port is reachable using PowerShell:</p>
<pre class="crayon-plain-tag">Test-NetConnection -ComputerName &amp;lt;GatewayHost&amp;gt; -Port 5000</pre>
<p>If <strong>TcpTestSucceeded = False</strong>, the port is still blocked by a firewall or network security layer.</p>
<h4>Note</h4>
<p><strong>⚠️ Important:</strong> Opening a port in Windows Defender Firewall alone does not guarantee connectivity if a third-party firewall is active.</p>
<h3><span style="font-size: 14pt;">IP Range Filter</span></h3>
<ol>
<li>Ensure you have installed the <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> with the default options (this also installs the Data Gateway Service).</li>
<li>Open the gateway configuration app by typing <strong>&#8220;Gateway&#8221;</strong> in the Start menu and selecting <em>ZappySys Data Gateway Configuration</em>.
<div id="attachment_5283" style="width: 310px" class="wp-caption aligncenter"><img decoding="async" aria-describedby="caption-attachment-5283" class="wp-image-5283 size-medium" src="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway-300x236.png" alt="Open ZappySys Data Gateway" width="300" height="236" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway-300x236.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/11/start-menu-open-zappysys-data-gateway.png 400w" sizes="(max-width: 300px) 100vw, 300px" /><p id="caption-attachment-5283" class="wp-caption-text">Open ZappySys Data Gateway</p></div></li>
<li>Assuming the other tabs are already configured the way you want, switch to <strong>Network Settings</strong>.</li>
<li>Click the <strong>Edit IP Filters</strong> button (see screenshot below):
<div id="attachment_9592" style="width: 891px" class="wp-caption aligncenter"><img decoding="async" aria-describedby="caption-attachment-9592" class="wp-image-9592 size-full" src="https://zappysys.com/blog/wp-content/uploads/2022/04/datagateway-networksettings-ip-range.png" alt="Range IP Filters Network Settings for Data Gateway" width="881" height="660" srcset="https://zappysys.com/blog/wp-content/uploads/2022/04/datagateway-networksettings-ip-range.png 881w, https://zappysys.com/blog/wp-content/uploads/2022/04/datagateway-networksettings-ip-range-300x225.png 300w, https://zappysys.com/blog/wp-content/uploads/2022/04/datagateway-networksettings-ip-range-768x575.png 768w" sizes="(max-width: 881px) 100vw, 881px" /><p id="caption-attachment-9592" class="wp-caption-text">Range IP Filters Network Settings for Data Gateway</p></div></li>
<li>In the IP Filters dialog, set <strong>Enabled</strong> to <code>true</code>, then supply the <strong>From</strong> and <strong>To</strong> addresses that define the permitted range:</li>
</ol>
<p><strong>Single range example:</strong></p><pre class="crayon-plain-tag">[
  {
    "Name": "Network_1",
    "Enabled": true,
    "From": "192.168.1.1",
    "To": "192.168.1.255"
  }
]</pre><p>
<strong>Multiple ranges example:</strong></p><pre class="crayon-plain-tag">[
  {
    "Name": "Network_1",
    "Enabled": true,
    "From": "192.168.1.1",
    "To": "192.168.1.255"
  },
  {
    "Name": "Network_2",
    "Enabled": true,
    "From": "192.167.1.1",
    "To": "192.167.1.255"
  }
]</pre><p>
<ol start="6">
<li>Save the dialog, then click <strong>OK</strong> to apply the settings. Only clients whose IP addresses fall within the defined ranges will be allowed.</li>
</ol>
<h3><span style="font-size: 14pt;">Single IP Filter</span></h3>
<ol>
<li>Repeat steps 1‑3 from the previous section.</li>
<li>Open the IP Filters dialog and enable it.</li>
<li>Enter the same value for the <strong>From</strong> and <strong>To</strong> fields to restrict access to one address.</li>
<li>Save and close the dialog; only that address may connect to the gateway.</li>
</ol>
<div id="attachment_9593" style="width: 896px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2022/04/datagateway-networksettings-specific-ip.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-9593" class="wp-image-9593 size-full" src="https://zappysys.com/blog/wp-content/uploads/2022/04/datagateway-networksettings-specific-ip.png" alt="Specific IP Filter Network Settings for Data Gateway." width="886" height="665" srcset="https://zappysys.com/blog/wp-content/uploads/2022/04/datagateway-networksettings-specific-ip.png 886w, https://zappysys.com/blog/wp-content/uploads/2022/04/datagateway-networksettings-specific-ip-300x225.png 300w, https://zappysys.com/blog/wp-content/uploads/2022/04/datagateway-networksettings-specific-ip-768x576.png 768w" sizes="(max-width: 886px) 100vw, 886px" /></a><p id="caption-attachment-9593" class="wp-caption-text">Specific IP Filter Network Settings for Data Gateway.</p></div>
<p><strong>Note:</strong> once any filter rule is enabled, all other addresses are automatically blocked.</p>
<hr />
<h2><span style="font-size: 14pt;">User‑Based Permissions</span></h2>
<p>You can further limit access by granting specific users permission to individual data sources. This is useful when you want to allow non‑admin users to consume only certain datasets.</p>
<ol>
<li>Make sure the user(s) exist on the <strong>Users</strong> tab and that they are not assigned administrator rights.</li>
<li>Switch to the <strong>Datasets</strong> tab.</li>
<li>Find the row for the data source you wish to secure and click <strong>Edit</strong> in the <em>Users</em> column.</li>
<li>In the dialog that appears, select one or more users on the left pane and click the <strong>[ &gt;&gt; ]</strong> button to move them to the right pane.</li>
<li>Choose the desired permission type (for example, <strong>Full permission</strong>).
<div id="attachment_11841" style="width: 708px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2022/04/zappysys-data-gateway-set-dataset-user-permissions.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-11841" class="size-full wp-image-11841" src="https://zappysys.com/blog/wp-content/uploads/2022/04/zappysys-data-gateway-set-dataset-user-permissions.png" alt="Set Dataset User Permissions - ZappySys Data Gateway" width="698" height="680" srcset="https://zappysys.com/blog/wp-content/uploads/2022/04/zappysys-data-gateway-set-dataset-user-permissions.png 698w, https://zappysys.com/blog/wp-content/uploads/2022/04/zappysys-data-gateway-set-dataset-user-permissions-300x292.png 300w" sizes="(max-width: 698px) 100vw, 698px" /></a><p id="caption-attachment-11841" class="wp-caption-text">Set Dataset User Permissions &#8211; ZappySys Data Gateway</p></div></li>
<li>Click <strong>OK</strong> to save the changes.</li>
<li>Restart the Data Gateway service to ensure the new permissions take effect.</li>
</ol>
<hr />
<h2><span id="Conclusion">Conclusion</span></h2>
<p>In this article we reviewed several ways to harden the ZappySys Data Gateway. The network filters let you restrict connections to either a specific IP address or a range of addresses. The new user‑based permissions allow you to grant dataset access to individual users. Together these features make your gateway more secure and easier to manage.</p>
<p>If you haven’t yet installed the gateway, <a href="https://zappysys.com/products/odbc-powerpack/download/">download it here</a> to get started.</p>
<p>The post <a href="https://zappysys.com/blog/secure-zappysys-data-gateway-network-settings/">How to Secure ZappySys Data Gateway (Network Settings)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Get data from Google Search Console API in SSIS and ODBC Apps</title>
		<link>https://zappysys.com/blog/get-data-google-search-console-api-ssis-odbc-drivers/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Wed, 09 Oct 2019 20:22:28 +0000</pubDate>
				<category><![CDATA[JSON File / REST API Driver]]></category>
		<category><![CDATA[ODBC Gateway]]></category>
		<category><![CDATA[ODBC PowerPack]]></category>
		<category><![CDATA[SSIS JSON Source (File/REST)]]></category>
		<category><![CDATA[SSIS REST API Task]]></category>
		<category><![CDATA[google api]]></category>
		<category><![CDATA[oauth]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=8128</guid>

					<description><![CDATA[<p>Introduction In our previous few posts we saw how to call various google apis in SSIS.  In this post lets learn how to call Google Search Console API in SSIS or other ODBC Compatible Apps such as Power BI, Informatica, SSRS using API Drivers for ODBC About Google Search Console API (Google Webmaster API) If [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/get-data-google-search-console-api-ssis-odbc-drivers/">Get data from Google Search Console API in SSIS and ODBC Apps</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>Introduction</h2>
<p>In our previous few posts we saw how to call various <a href="https://zappysys.com/blog/category/google-api/" target="_blank" rel="noopener">google apis</a> in SSIS.  In this post lets learn how to call Google Search Console API in SSIS or other ODBC Compatible Apps such as Power BI, Informatica, SSRS using <a href="https://zappysys.com/products/odbc-powerpack/">API Drivers for ODBC</a></p>
<div class="content_block" id="custom_post_widget-2523"><h2><span id="Prerequisites">Prerequisites</span></h2>
Before we perform the steps listed in this article, you will need to make sure the following prerequisites are met:
<ol style="margin-left: 1.5em;">
 	<li><abbr title="SQL Server Integration Services">SSIS</abbr> designer installed. Sometimes it is referred to as <abbr title="Business Intelligence Development Studio">BIDS</abbr> or <abbr title="SQL Server Data Tools">SSDT</abbr> (<a href="https://docs.microsoft.com/en-us/sql/ssdt/download-sql-server-data-tools-ssdt" target="_blank" rel="noopener">download it from the Microsoft site</a>).</li>
 	<li>Basic knowledge of SSIS package development using <em>Microsoft SQL Server Integration Services</em>.</li>
 	<li>Make sure <span style="text-decoration: underline;"><a href="https://zappysys.com/products/ssis-powerpack/" target="_blank" rel="noopener">ZappySys SSIS PowerPack</a></span> is installed (<a href="https://zappysys.com/products/ssis-powerpack/download/" target="_blank" rel="noopener">download it</a>, if you haven't already).</li>
 	<li>(<em>Optional step</em>)<em>.</em> <a href="https://zappysys.zendesk.com/hc/en-us/articles/360035974593" target="_blank" rel="noopener">Read this article</a>, if you are planning to deploy packages to a server and schedule their execution later.</li>
</ol></div>
<h2>About Google Search Console API (Google Webmaster API)</h2>
<p>If you are new to Google Search Console API (i.e. Webmaster API) then start <a href="https://developers.google.com/webmaster-tools/search-console-api-original/v3/prereqs" target="_blank" rel="noopener">from this link</a>. You can also <a href="https://developers.google.com/apis-explorer/#p/webmasters/v3/" target="_blank" rel="noopener">check API Explorer</a> here to test API requests.</p>
<p>Search API can be called by supplying either <a href="https://developers.google.com/webmaster-tools/search-console-api-original/v3/how-tos/authorizing#APIKey" target="_blank" rel="noopener">API key</a> in URL  or <a href="https://zappysys.com/blog/register-google-oauth-application-get-clientid-clientsecret/">use OAuth</a></p>
<p>Search Console V3 Covers following APIs (May add more in future)</p>
<div class="su-table su-table-alternate">
<table class="NYYWNC-h-b">
<tbody>
<tr>
<td><strong><span class="gwt-InlineLabel">API Name</span></strong></td>
<td><strong><span class="gwt-InlineLabel">Description</span></strong></td>
</tr>
<tr>
<td class="NYYWNC-h-c"><span class="gwt-InlineLabel">webmasters.searchanalytics.query</span></td>
<td class="NYYWNC-h-a"><span class="gwt-InlineLabel">Query your data with filters and parameters that you define. Returns zero or more rows grouped by the row keys that you define. You must define a date range of one or more days. When date is one of the group by values, any days without data are omitted from the result list. If you need to know which days have data, issue a broad date range query grouped by date for any metric, and see which day rows are returned.</span></td>
</tr>
<tr>
<td class="NYYWNC-h-c"><span class="gwt-InlineLabel">webmasters.sitemaps.delete</span></td>
<td class="NYYWNC-h-a"><span class="gwt-InlineLabel">Deletes a sitemap from this site.</span></td>
</tr>
<tr>
<td class="NYYWNC-h-c"><span class="gwt-InlineLabel">webmasters.sitemaps.get</span></td>
<td class="NYYWNC-h-a"><span class="gwt-InlineLabel">Retrieves information about a specific sitemap.</span></td>
</tr>
<tr>
<td class="NYYWNC-h-c"><span class="gwt-InlineLabel">webmasters.sitemaps.list</span></td>
<td class="NYYWNC-h-a"><span class="gwt-InlineLabel">Lists the sitemaps-entries submitted for this site, or included in the sitemap index file (if sitemapIndex is specified in the request).</span></td>
</tr>
<tr>
<td class="NYYWNC-h-c"><span class="gwt-InlineLabel">webmasters.sitemaps.submit</span></td>
<td class="NYYWNC-h-a"><span class="gwt-InlineLabel">Submits a sitemap for a site.</span></td>
</tr>
<tr>
<td class="NYYWNC-h-c"><span class="gwt-InlineLabel">webmasters.sites.add</span></td>
<td class="NYYWNC-h-a"><span class="gwt-InlineLabel">Adds a site to the set of the user&#8217;s sites in Search Console.</span></td>
</tr>
<tr>
<td class="NYYWNC-h-c"><span class="gwt-InlineLabel">webmasters.sites.delete</span></td>
<td class="NYYWNC-h-a"><span class="gwt-InlineLabel">Removes a site from the set of the user&#8217;s Search Console sites.</span></td>
</tr>
<tr>
<td class="NYYWNC-h-c"><span class="gwt-InlineLabel">webmasters.sites.get</span></td>
<td class="NYYWNC-h-a"><span class="gwt-InlineLabel">Retrieves information about specific site.</span></td>
</tr>
<tr>
<td class="NYYWNC-h-c"><span class="gwt-InlineLabel">webmasters.sites.list</span></td>
<td class="NYYWNC-h-a"><span class="gwt-InlineLabel">Lists the user&#8217;s Search Console sites.</span></td>
</tr>
</tbody>
</table>
</div>
<p><strong>Search Console API Call Example</strong></p>
<p>Here is simple example of Search Console API call. Below example returns all sites you added under your search console account.</p>
<p><strong>Request</strong></p><pre class="crayon-plain-tag">GET https://www.googleapis.com/webmasters/v3/sites?key={YOUR_API_KEY}</pre><p>
<strong>Response</strong></p><pre class="crayon-plain-tag">{
 "siteEntry": [
  {
   "siteUrl": "https://my-google-search-api-1.com/",
   "permissionLevel": "siteOwner"
  },
  {
   "siteUrl": "https://www.my-google-search-api-1.com/",
   "permissionLevel": "siteOwner"
  },
  {
   "siteUrl": "https://my-google-search-api-2.com/",
   "permissionLevel": "siteOwner"
  },
  {
   "siteUrl": "https://www.my-google-search-api-2.com/",
   "permissionLevel": "siteOwner"
  }
 ]
}</pre><p>
&nbsp;</p>
<h2>Step-By-Step &#8211; Call Search Console API in SSIS</h2>
<p>Now lets look at very simple API call to <a href="https://developers.google.com/webmaster-tools/search-console-api-original/v3/sites/list" target="_blank" rel="noopener">list search console sites</a></p>
<ol>
<li>Open SSIS Package</li>
<li>Drag and drop ZS REST API Task from SSIS tool box
<div style="width: 565px" class="wp-caption alignnone"><img loading="lazy" decoding="async" class="size-full" src="https://zappysys.com/onlinehelp/ssis-powerpack/scr/images/rest-api-task/ssis-rest-api-web-service-task-drag.png" alt="Drag and Drop ZS REST API Task from SSIS Toolbox" width="555" height="199" /><p class="wp-caption-text">Drag and Drop ZS REST API Task from SSIS Toolbox</p></div></li>
<li>Now double click REST API Task and configure (Skip <strong>Step 5</strong> if you use <a href="https://developers.google.com/webmaster-tools/search-console-api-original/v3/how-tos/authorizing#APIKey" target="_blank" rel="noopener">API Key</a> instead of OAuth).</li>
<li>Enter API URL you like to call. For This example we will use simple URL as below<br />
<strong>OAuth based Authentication</strong><br />
<pre class="crayon-plain-tag">https://www.googleapis.com/webmasters/v3/sites/</pre>
<strong>API Key based Authentication</strong><br />
<pre class="crayon-plain-tag">https://www.googleapis.com/webmasters/v3/sites/?key={YOUR_API_KEY}</pre>
</li>
<li>If you want to use OAuth based credentials then perform the following steps
<ol>
<li>Select <strong>URL from Connection </strong></li>
<li>Click <strong>New ZS-OAUTH</strong> connection from Dropdown</li>
<li>On the OAuth UI select <strong>Google as Provider</strong></li>
<li>Enter Scopes as below<br />
<pre class="crayon-plain-tag">https://www.googleapis.com/auth/webmasters
https://www.googleapis.com/auth/webmasters.readonly</pre>
</li>
<li>Click Generate Token. When you get Login Prompt enter your Google Account information and <strong>click Accept</strong></li>
<li>Click OK to Save OAuth UI</li>
</ol>
</li>
<li>This is how it will look like if you use OAuth Connection
<div id="attachment_8131" style="width: 1037px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/10/call-google-search-api-using-oauth-ssis-rest-api-task.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-8131" class="size-full wp-image-8131" src="https://zappysys.com/blog/wp-content/uploads/2019/10/call-google-search-api-using-oauth-ssis-rest-api-task.png" alt="Call Google Search Console API using SSIS REST API Task (OAuth Authentication)" width="1027" height="869" srcset="https://zappysys.com/blog/wp-content/uploads/2019/10/call-google-search-api-using-oauth-ssis-rest-api-task.png 1027w, https://zappysys.com/blog/wp-content/uploads/2019/10/call-google-search-api-using-oauth-ssis-rest-api-task-300x254.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/10/call-google-search-api-using-oauth-ssis-rest-api-task-768x650.png 768w, https://zappysys.com/blog/wp-content/uploads/2019/10/call-google-search-api-using-oauth-ssis-rest-api-task-1024x866.png 1024w" sizes="(max-width: 1027px) 100vw, 1027px" /></a><p id="caption-attachment-8131" class="wp-caption-text">Call Google Search Console API using SSIS REST API Task (OAuth Authentication)</p></div></li>
<li>Now click Test Request / Response to check if its working. You should get response like below</li>
</ol>
<p>&nbsp;</p>
<h2>Read from Search Console Analytics API (query)</h2>
<p>Now let&#8217;s look at how to <a href="https://developers.google.com/webmaster-tools/search-console-api-original/v3/searchanalytics/query" target="_blank" rel="noopener">call Search Console Analytics API (i.e. query)</a> for Specified Site and extract data in tabular format using <a href="https://zappysys.com/products/ssis-powerpack/ssis-json-file-source/" target="_blank" rel="noopener">ZS JSON Source</a>. In below example we will obtain search Impression, clicks, position etc for specified site. We will aggregate this over date and country (dimensions).</p>
<p>In this section you will learn how to use JSON Source Adapter to extract data from JSON file (In this case its Web URL).</p>
<ol>
<li>Firstly, You need to <b>Download and Install</b> SSIS <a href="https://zappysys.com/products/ssis-powerpack/download/" target="_blank" rel="noopener">ZappySys PowerPack.</a></li>
<li>Once you finished first step, Open Visual Studio and Create New SSIS Package Project.</li>
<li>Now, Drag and Drop SSIS <b>Data Flow Task</b> from SSIS Toolbox.<br />
<img decoding="async" class="figureimage" title="SSIS Data Flow Task - Drag and Drop" src="https://zappysys.com/onlinehelp/ssis-powerpack/scr/images/drag-and-drop-data-flow-task.png" alt="SSIS Data Flow Task - Drag and Drop" /></li>
<li>Double click on the Data Flow task to see Data Flow designer surface.</li>
<li>From the SSIS toolbox drag and drop JSON Source on the Data Flow designer surface.<br />
<img decoding="async" class="figureimage" title="SSIS JSON Source - Drag and Drop" src="https://zappysys.com/onlinehelp/ssis-powerpack/scr/images/json-source/ssis-json-source-adapter-drag.png" alt="SSIS JSON Source - Drag and Drop" /></li>
<li>Double click JSON Source and configure like below
<ol>
<li>Enter URL as below. Notice two things, first we used <strong>&lt;&lt;somedata,FUN_URLENC&gt;&gt;</strong> <a href="https://zappysys.com/onlinehelp/ssis-powerpack/scr/ssis-format-specifiers.htm" target="_blank" rel="noopener">placeholder function</a> to encode <strong>:</strong> and <strong>//</strong> in the URL so it <a href="https://zappysys.zendesk.com/hc/en-us/articles/360012261713">become %2F %3A</a>. We use <pre class="crayon-plain-tag">--dont-escape--</pre>  suffix at the end.<br />
<strong>For OAuth based Credentials</strong><br />
<pre class="crayon-plain-tag">https://www.googleapis.com/webmasters/v3/sites/&lt;&lt;https://mysite.com,FUN_URLENC&gt;&gt;/searchAnalytics/query--dont-escape--</pre>
<strong>For API Key based Credentials</strong><br />
<pre class="crayon-plain-tag">https://www.googleapis.com/webmasters/v3/sites/&lt;&lt;https://mysite.com,FUN_URLENC&gt;&gt;/searchAnalytics/query/?key={YOUR_API_KEY}--dont-escape--</pre>
</li>
<li>Check Use Credentials and select OAuth connection (created earlier) (if you are using API key in URL then skip this step).</li>
<li>Select <strong>POST</strong> as HTTP Method</li>
<li>Enter Body for Query. Here are <a href="https://developers.google.com/webmaster-tools/search-console-api-original/v3/how-tos/search_analytics" target="_blank" rel="noopener">some examples</a> for various queries you can use. For our case we want to group by date and country so use below<br />
<pre class="crayon-plain-tag">{
"startDate": "2019-01-01",
"endDate": "2019-01-10",
"dimensions" : ["date","country"]
}</pre>
</li>
<li>Select <strong>Content Type</strong> as <pre class="crayon-plain-tag">application/json</pre>  from Content Type drop down.</li>
<li>Select Filter or enter as  <pre class="crayon-plain-tag">$.rows[*]</pre></li>
<li>Now go to Extract Multiple Arrays Tab and <strong>Check Array Flattening Option</strong> (on older version it was on the different Tab)</li>
</ol>
</li>
<li>Click Preview and you will see your Google Search Console API data as below.
<div id="attachment_8138" style="width: 914px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/10/read-google-search-console-api-example.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-8138" class="size-full wp-image-8138" src="https://zappysys.com/blog/wp-content/uploads/2019/10/read-google-search-console-api-example.png" alt="Read from Google Search API Console (Analytics Query Endpoint) - JSON Source" width="904" height="827" srcset="https://zappysys.com/blog/wp-content/uploads/2019/10/read-google-search-console-api-example.png 904w, https://zappysys.com/blog/wp-content/uploads/2019/10/read-google-search-console-api-example-300x274.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/10/read-google-search-console-api-example-768x703.png 768w" sizes="(max-width: 904px) 100vw, 904px" /></a><p id="caption-attachment-8138" class="wp-caption-text">Read from Google Search API Console (Analytics Query Endpoint) &#8211; JSON Source</p></div></li>
</ol>
<h2>Loading Google Search Console API data into SQL Server / Other Target</h2>
<div class="content_block" id="custom_post_widget-5617"><p>ZappySys SSIS PowerPack makes it easy to load data from various sources such as REST, SOAP, JSON, XML, CSV or from other source into SQL Server, or PostgreSQL, or Amazon Redshift, or other  targets. The <strong>Upsert Destination</strong> component allows you to automatically insert new records and update existing ones based on key columns. Below are the detailed steps to configure it.</p>
<h3>Step 1: Add Upsert Destination to Data Flow</h3>
<ol>
<li>Drag and drop the <strong>Upsert Destination</strong> component from the SSIS Toolbox.</li>
<li>Connect your source component (e.g., JSON / REST / Other Source) to the Upsert Destination.</li>
</ol>
<div class="wp-caption aligncenter">
<a href="https://zappysys.com/blog/wp-content/uploads/2017/08/ssis-data-flow-drag-drop-upsert-destination.png">
<img loading="lazy" decoding="async" class="size-full" alt="" src="https://zappysys.com/blog/wp-content/uploads/2017/08/ssis-data-flow-drag-drop-upsert-destination.png" /></a>
<p class="wp-caption-text">SSIS - Data Flow - Drang and Drop Upsert Destination Component</p>
</div>
<h3>Step 2: Configure Target Connection</h3>
<ol>
<li>Double-click the <strong>Upsert Destination</strong> component to open the configuration window.</li>
<li>Under <strong>Connection</strong>, select an existing target connection or click <strong>NEW</strong> to create a new connection.
<ul>
<li>Example: SQL Server, or PostgreSQL, or Amazon Redshift.</li>
</ul>
</li>
</ol>
<h3>Step 3: Select or Create Target Table</h3>
<ol>
<li>In the <strong>Target Table</strong> dropdown, select the table where you want to load data.</li>
<li>Optionally, click <strong>NEW</strong> to create a new table based on the source columns.</li>
</ol>
<div class="wp-caption aligncenter">
<a href="https://zappysys.com/blog/wp-content/uploads/2020/09/upsert-destination-configuration.png">
<img loading="lazy" decoding="async" class="size-full" alt="" src="https://zappysys.com/blog/wp-content/uploads/2020/09/upsert-destination-configuration.png" /></a>
<p class="wp-caption-text">Configure SSIS Upsert Destination Connection - Loading data (REST / SOAP / JSON / XML /CSV) into SQL Server or other target using SSIS</p>
</div>
<h3>Step 4: Map Columns</h3>
<ol>
<li>Go to the <strong>Mappings</strong> tab.</li>
<li>Click <strong>Auto Map</strong> to map source columns to target columns by name.</li>
<li>Ensure you <strong>check the Primary key column(s)</strong> that will determine whether a record is inserted or updated.</li>
<li>You can manually adjust the mappings if necessary.</li>
</ol>
 <div class="wp-caption aligncenter">
<a href="https://zappysys.com/blog/wp-content/uploads/2020/09/upsert-destination-key.png">
<img loading="lazy" decoding="async" class="size-full" alt="" src="https://zappysys.com/blog/wp-content/uploads/2020/09/upsert-destination-key.png" /></a>
<p class="wp-caption-text">SSIS Upsert Destination - Columns Mappings</p>
</div>
<h3>Step 5: Save Settings</h3>
<ul>
<li>Click <strong>OK</strong> to save the Upsert Destination configuration.</li>
</ul>
<h3>Step 6: Optional: Add Logging or Analysis</h3>
<ul>
<li>You may add extra destination components to log the number of inserted vs. updated records for monitoring or auditing purposes.</li>
</ul>
<h3>Step 7: Execute the Package</h3>
<ul>
<li>Run your SSIS package and verify that the data is correctly inserted and updated in the target table.</li>
</ul>
<div class="wp-caption aligncenter">
<a href="https://zappysys.com/blog/wp-content/uploads/2018/12/ssis-upsert-destination-execute.png">
<img loading="lazy" decoding="async" class="size-full" alt="" src="https://zappysys.com/blog/wp-content/uploads/2018/12/ssis-upsert-destination-execute.png" /></a>
<p class="wp-caption-text">SSIS Upsert Destination Execution</p>
</div></div>
<p>&nbsp;</p>
<h2>Import Google Search Console API data in Reporting / other ETL tools (ODBC Usecase)</h2>
<p>There will be a time when you dont want to use SSIS connector like mentioned in previous sections but extract Google Search API data in Reporting Tools / Other ETL Platform.  Good news is you can use <a href="https://zappysys.com/products/odbc-powerpack/odbc-json-rest-api-driver/" target="_blank" rel="noopener">ZappySys ODBC Driver for JSON / REST API</a> in ODBC Apps. See few popular ODBC Apps below.</p>
<ul>
<li>Power BI connection for Google Search Console API</li>
<li>Excel connection for Google Search Console API</li>
<li>Informatica connection for Google Search Console API</li>
<li>MS Access connection for Google Search Console API</li>
<li>C# , PowerShell, VB.net connection for Google Search Console API</li>
</ul>
<div id="attachment_6416" style="width: 766px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-generate-quickbooks-query.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-6416" class="size-full wp-image-6416" src="https://zappysys.com/blog/wp-content/uploads/2019/01/odbc-json-driver-generate-quickbooks-query.png" alt="Preview / Generate Query in JSON Driver / XML Driver" 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">Preview / Generate Query in JSON Driver / XML Driver</p></div>
<h2></h2>
<h2>Load Google Search Console API in SQL Server without any ETL</h2>
<p>Now let&#8217;s look at even more interesting integration scenario. If you have SQL Server and like to load Google Search Console API without any ETL then you can use <a href="https://zappysys.com/products/odbc-powerpack/data-gateway/" target="_blank" rel="noopener">Data Gateway</a></p>
<p>Read this article to learn how to <a href="https://zappysys.com/blog/import-rest-api-json-sql-server/" target="_blank" rel="noopener">load REST API in SQL Server</a> without any coding (Use just T-SQL) .</p>
<p>You can write query like below to load data inside SQL Table.</p><pre class="crayon-plain-tag">SELECT * FROM OPENQUERY([MY_LINKED_SERVER]
, 'SELECT * FROM $
WITH(
	 Src=''https://www.googleapis.com/webmasters/v3/sites/&lt;&lt;https://mysite.com,FUN_URLENC&gt;&gt;/searchAnalytics/query/?key={YOUR_API_KEY}--dont-escape--''
	,Filter=''$.rows[*]''
	,RequestData=''{
"startDate": "2019-01-01",
"endDate": "2019-01-10",
"dimensions" : ["date","country"]
}''
	,RequestContentTypeCode=''ApplicationJson''
	,Header=''cache-control: no-cache || Accept: */*''
	,RequestMethod=''POST''
	,EnableArrayFlattening=''True''
)')</pre><p>
<div id="attachment_5293" style="width: 899px" 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 loading="lazy" decoding="async" aria-describedby="caption-attachment-5293" class="size-full wp-image-5293" 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)" width="889" height="481" srcset="https://zappysys.com/blog/wp-content/uploads/2018/11/query-rest-api-sql-server-linked-server-openquery-zappysys-data-gateway.png 889w, https://zappysys.com/blog/wp-content/uploads/2018/11/query-rest-api-sql-server-linked-server-openquery-zappysys-data-gateway-300x162.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/11/query-rest-api-sql-server-linked-server-openquery-zappysys-data-gateway-768x416.png 768w" sizes="(max-width: 889px) 100vw, 889px" /></a><p id="caption-attachment-5293" class="wp-caption-text">SSMS Output &#8211; Query REST API via Linked Server OPENQUERY statement (Connect to ZappySys Data Gateway)</p></div>
<h2>Conclusion</h2>
<p>So in this post we saw how easy it is to achieve total REST API integration in SSIS using JSON Connector. We also saw how to use ODBC Drivers to query REST API data inside Apps like Excel, MS Access, Informatica and other ODBC Apps using ODBC JSON / REST API driver. If you are SSIS User download <a href="https://zappysys.com/products/ssis-powerpack/">SSIS PowerPack and try for FREE</a> and if you don&#8217;t have SSIS in house and want to try more generic approach then <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">Download ODBC PowerPack Drivers for FREE Trial</a>.</p>
<p>The post <a href="https://zappysys.com/blog/get-data-google-search-console-api-ssis-odbc-drivers/">Get data from Google Search Console API in SSIS and ODBC Apps</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Import Amazon S3 files into SQL Server (CSV/JSON/XML Driver)</title>
		<link>https://zappysys.com/blog/import-amazon-s3-files-sql-server-csv-json-xml-driver/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Mon, 12 Aug 2019 16:32:00 +0000</pubDate>
				<category><![CDATA[Amazon S3 CSV Driver]]></category>
		<category><![CDATA[Amazon S3 JSON Driver]]></category>
		<category><![CDATA[Amazon S3 XML Driver]]></category>
		<category><![CDATA[ODBC Drivers]]></category>
		<category><![CDATA[ODBC Gateway]]></category>
		<category><![CDATA[ODBC PowerPack]]></category>
		<category><![CDATA[S3 (Simple Storage Service)]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[xml]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=7206</guid>

					<description><![CDATA[<p>Introduction There might be a case when you have many CSV, JSON or XML files in Amazon S3 bucket and you want them to be imported straight into a SQL Server table. Here come ZappySys ODBC PowerPack and ZappySys Data Gateway (part of ODBC PowerPack) which will enable you to accomplish that. ZappySys ODBC PowerPack includes powerful [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/import-amazon-s3-files-sql-server-csv-json-xml-driver/">Import Amazon S3 files into SQL Server (CSV/JSON/XML Driver)</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="alignnone wp-image-7581 size-thumbnail alignleft" src="https://zappysys.com/blog/wp-content/uploads/2019/06/s3-to-sql-150x150.png" alt="" width="150" height="150" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/s3-to-sql-150x150.png 150w, https://zappysys.com/blog/wp-content/uploads/2019/06/s3-to-sql-300x300.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/06/s3-to-sql.png 400w" sizes="(max-width: 150px) 100vw, 150px" />There might be a case when you have many CSV, JSON or XML files in <a href="https://aws.amazon.com/s3/" target="_blank" rel="noopener">Amazon S3</a> bucket and you want them to be imported straight into a SQL Server table. Here come <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> and <a href="https://zappysys.com/products/odbc-powerpack/data-gateway/" target="_blank" rel="noopener">ZappySys Data Gateway</a> (part of ODBC PowerPack) which will enable you to accomplish that. ZappySys ODBC PowerPack includes powerful Amazon S3 CSV, Amazon S3 JSON and Amazon S3 XML drivers that let you connect to an S3 bucket and read the contents from the files in the bucket. Bringing in ZappySys Data Gateway allows doing that right from a SQL Server. Let&#8217;s begin and see how to import Amazon S3 files into SQL Server.</p>
<p>&nbsp;</p>
<p>These drivers are related to this article:</p>
<div class="content_block" id="custom_post_widget-7227"><div style="display: table-row; background: #f7f7f7;">
<div style="display: table-cell; padding: 1em; border: 1px solid #ccc;"><img loading="lazy" decoding="async" style="vertical-align: middle; width: 50px; height: 50px; max-width: 50px;" src="//i1.wp.com/zappysys.com/images/odbc-powerpack/odbc-amazon-s3-xml-driver.png?w=100&amp;ssl=1" alt="Web API Destination" width="50" height="50" /></div>
<div style="display: table-cell; padding: 1em; border: 1px solid #ccc; border-left: none; width: 100%;"><a href="//zappysys.com/products/odbc-powerpack/amazon-s3-odbc-driver-xml-files/" target="_blank" rel="noopener">Amazon S3 Driver (for XML Files)</a></div>
</div></div>
<div class="content_block" id="custom_post_widget-7229"><div style="display: table-row; background: #f7f7f7;">
<div style="display: table-cell; padding: 1em; border: 1px solid #ccc;"><img loading="lazy" decoding="async" style="vertical-align: middle; width: 50px; height: 50px; max-width: 50px;" src="//i0.wp.com/zappysys.com/images/odbc-powerpack/odbc-amazon-s3-json-driver.png?w=100&amp;ssl=1" alt="Web API Destination" width="50" height="50" /></div>
<div style="display: table-cell; padding: 1em; border: 1px solid #ccc; border-left: none; width: 100%;"><a href="//zappysys.com/products/odbc-powerpack/amazon-s3-odbc-driver-json-files/" target="_blank" rel="noopener">Amazon S3 Driver (for JSON Files)</a></div>
</div></div>
<div class="content_block" id="custom_post_widget-7233"><div style="display: table-row; background: #f7f7f7;">
<div style="display: table-cell; padding: 1em; border: 1px solid #ccc;"><img loading="lazy" decoding="async" style="vertical-align: middle; width: 50px; height: 50px; max-width: 50px;" src="https://i2.wp.com/zappysys.com/images/odbc-powerpack/odbc-amazon-s3-csv-driver.png?w=100&amp;ssl=1" alt="Web API Destination" width="50" height="50" /></div>
<div style="display: table-cell; padding: 1em; border: 1px solid #ccc; border-left: none; width: 100%;"><a href="//zappysys.com/products/odbc-powerpack/amazon-s3-odbc-driver-csv-files/" target="_blank" rel="noopener">Amazon S3 Driver (for CSV Files)</a></div>
</div></div>
<h2>Prerequisites</h2>
<ol>
<li>Have an <a href="https://aws.amazon.com/" target="_blank" rel="noopener">AWS</a> account.</li>
<li>Existing <a href="https://aws.amazon.com/s3/" target="_blank" rel="noopener">Amazon S3</a> bucket.</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>Getting started</h2>
<p style="text-align: justify;">We will start from a simple example of how to load contacts from a JSON that are located in Amazon S3 bucket, then we will proceed by loading contacts from many XML files that are compressed in ZIP, and finally, we will traverse many folders and subfolders to gather CSVs and load contacts from them.</p>
<h2>Step-by-Step &#8211; Import JSON file located at Amazon S3 into SQL Server</h2>
<h3><span style="font-size: 14pt;">Open and configure ZappySys Data Gateway</span></h3>
<div class="content_block" id="custom_post_widget-7369">Now let's look at steps to configure Data Gateway after installation:
<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/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">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 decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-user.png" alt="Add Data Gateway User" /></a>
<p class="wp-caption-text">Add Data Gateway User</p>

</div></li>
</ol>
&nbsp;</div>
<h3><a id="create-json-data-source"></a>Create an Amazon S3 JSON data source in ZappySys Data Gateway</h3>
<ol>
<li>The first thing you will have to do is to create a data source in ZappySys Data Gateway. Just click <strong>Add</strong> button, give the data source a name, e.g. &#8220;<strong>MyContactsJSON</strong>&#8220;, and then select <strong>Native &#8211; ZappySys Amazon S3 JSON Driver</strong>:
<div id="attachment_7373" style="width: 637px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7373" class="wp-image-7373 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/06/100-create-new-data-source-in-data-gateway-to-load-json-files-into-sql-server.png" alt="Adding a JSON data source in ZappySys Data Gateway to load it from Amazon S3 bucket into SQL Server" width="627" height="552" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/100-create-new-data-source-in-data-gateway-to-load-json-files-into-sql-server.png 627w, https://zappysys.com/blog/wp-content/uploads/2019/06/100-create-new-data-source-in-data-gateway-to-load-json-files-into-sql-server-300x264.png 300w" sizes="(max-width: 627px) 100vw, 627px" /><p id="caption-attachment-7373" class="wp-caption-text">Adding a JSON data source in ZappySys Data Gateway to load it from Amazon S3 bucket into SQL Server</p></div></li>
<li>Then click <strong>Edit</strong> and add the Data Gateway user you created in <strong>Users</strong> tab. We will use this user later when adding a Linked Server to the Data Gateway to authenticate:
<div id="attachment_7557" style="width: 688px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7557" class="wp-image-7557 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/06/125-add-data-gateway-user-to-json-data-source-to-get-json-data-into-sql-server.png" alt="Adding a user to the newly created JSON data source" width="678" height="627" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/125-add-data-gateway-user-to-json-data-source-to-get-json-data-into-sql-server.png 678w, https://zappysys.com/blog/wp-content/uploads/2019/06/125-add-data-gateway-user-to-json-data-source-to-get-json-data-into-sql-server-300x277.png 300w" sizes="(max-width: 678px) 100vw, 678px" /><p id="caption-attachment-7557" class="wp-caption-text">Adding a user to the newly created Amazon S3 JSON data source</p></div></li>
<li>Once you do that, then click <strong>Edit</strong> to configure the data source:
<div id="attachment_7374" style="width: 637px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7374" class="wp-image-7374 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/06/200-modify-data-source-in-data-gateway-to-load-json-files-into-sql-server.png" alt="Preparing to configure the JSON data source to load a JSON from Amazon S3 bucket to SQL Server" width="627" height="445" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/200-modify-data-source-in-data-gateway-to-load-json-files-into-sql-server.png 627w, https://zappysys.com/blog/wp-content/uploads/2019/06/200-modify-data-source-in-data-gateway-to-load-json-files-into-sql-server-300x213.png 300w" sizes="(max-width: 627px) 100vw, 627px" /><p id="caption-attachment-7374" class="wp-caption-text">Preparing to configure the Amazon S3 JSON data source to load a JSON from Amazon S3 bucket to SQL Server</p></div></li>
<li>When a window opens, click <strong>Click here to Configure the Connection</strong> and enter your <em>Access Key</em> and <em>Secret Key</em>:
<div id="attachment_7376" style="width: 655px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7376" class="wp-image-7376 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/06/300-create-connection-to-amazon-s3-to-load-json-into-sql-server-1.png" alt="Configuring the authentication to Amazon S3 bucket in ZappySys Data Gateway" width="645" height="702" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/300-create-connection-to-amazon-s3-to-load-json-into-sql-server-1.png 645w, https://zappysys.com/blog/wp-content/uploads/2019/06/300-create-connection-to-amazon-s3-to-load-json-into-sql-server-1-276x300.png 276w" sizes="(max-width: 645px) 100vw, 645px" /><p id="caption-attachment-7376" class="wp-caption-text">Configuring the authentication to Amazon S3 bucket in ZappySys Data Gateway</p></div></li>
<li>After that, select a JSON file you want to load, and then click <strong>Select Filter</strong> button to choose data you want to be displayed in SQL Server:
<div id="attachment_7377" style="width: 668px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7377" class="wp-image-7377 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/06/400-configure-amazon-s3-json-data-source-to-load-data-into-sql-server.png" alt="Configuring the JSON data source to load a JSON from Amazon S3 bucket into SQL Server" width="658" height="702" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/400-configure-amazon-s3-json-data-source-to-load-data-into-sql-server.png 658w, https://zappysys.com/blog/wp-content/uploads/2019/06/400-configure-amazon-s3-json-data-source-to-load-data-into-sql-server-281x300.png 281w" sizes="(max-width: 658px) 100vw, 658px" /><p id="caption-attachment-7377" class="wp-caption-text">Configuring the JSON data source to load a JSON from Amazon S3 bucket into SQL Server</p></div></li>
<li>Go to the <strong>Preview</strong> tab and click the <strong>Preview Data</strong> button to make sure everything is configured correctly and preview the results:
<div id="attachment_7378" style="width: 668px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7378" class="wp-image-7378 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/06/500-preview-the-results-of-amazon-s3-json-data-source-to-load-data-into-sql-server.png" alt="Previewing JSON data in the data source based on Amazon S3 JSON Driver" width="658" height="653" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/500-preview-the-results-of-amazon-s3-json-data-source-to-load-data-into-sql-server.png 658w, https://zappysys.com/blog/wp-content/uploads/2019/06/500-preview-the-results-of-amazon-s3-json-data-source-to-load-data-into-sql-server-150x150.png 150w, https://zappysys.com/blog/wp-content/uploads/2019/06/500-preview-the-results-of-amazon-s3-json-data-source-to-load-data-into-sql-server-300x298.png 300w" sizes="(max-width: 658px) 100vw, 658px" /><p id="caption-attachment-7378" class="wp-caption-text">Previewing JSON data in the data source based on Amazon S3 JSON Driver</p></div></li>
</ol>
<p style="text-align: justify;">Now you are ready to create a Linked Server and connect to the data source you just created. If you used &#8220;<strong>MyContactsJSON</strong>&#8221; as the data source name, make sure to use the same name when creating a Linked Server.</p>
<h3><a id="set-up-a-sql-server-linked-server"></a>Set up a SQL Server Linked Server</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>Execute the SQL query</h3>
<p style="text-align: justify;">Once you created the Linked Server to ZappySys Data Gateway, you are ready to execute the SQL query and load data into SQL Server. Supposedly, you created the Linked Server with the name &#8220;GATEWAY&#8221;, then open SSMS and execute this query:</p>
<p><code>SELECT * INTO MyContacts FROM openquery([GATEWAY], 'SELECT * FROM $')<br />
SELECT * FROM MyContacts</code></p>
<h3>The results</h3>
<p>You should see similar results after you execute the query:</p>
<div id="attachment_7536" style="width: 609px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7536" class="wp-image-7536 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/06/600-the-results-of-importing-amazon-s3-data-into-sql-server-using-json-driver.png" alt="" width="599" height="257" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/600-the-results-of-importing-amazon-s3-data-into-sql-server-using-json-driver.png 599w, https://zappysys.com/blog/wp-content/uploads/2019/06/600-the-results-of-importing-amazon-s3-data-into-sql-server-using-json-driver-300x129.png 300w" sizes="(max-width: 599px) 100vw, 599px" /><p id="caption-attachment-7536" class="wp-caption-text">The results of getting JSON data straight from Amazon S3 bucket using ZappySys Amazon S3 JSON driver</p></div>
<p>Now we are ready to proceed to the next section and import many XML files at once.</p>
<h2>Step-by-Step &#8211; Import many XML files located at Amazon S3 into SQL Server</h2>
<h3>Overview</h3>
<p>Supposedly, you have many XMLs where each one is zipped and you want to load them all into a SQL Server table:</p>
<div id="attachment_7548" style="width: 668px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7548" class="wp-image-7548 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/06/650-load-many-compressed-xml-files-from-amazon-s3-bucket-into-sql-server-1.png" alt="Zipped XML files located in Amazon S3 bucket to be loaded into SQL Server" width="658" height="311" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/650-load-many-compressed-xml-files-from-amazon-s3-bucket-into-sql-server-1.png 658w, https://zappysys.com/blog/wp-content/uploads/2019/06/650-load-many-compressed-xml-files-from-amazon-s3-bucket-into-sql-server-1-300x142.png 300w" sizes="(max-width: 658px) 100vw, 658px" /><p id="caption-attachment-7548" class="wp-caption-text">Zipped XML files located in Amazon S3 bucket to be loaded into SQL Server</p></div>
<p>The first thing you will have to do is to create a data source, based on ZappySys Amazon S3 XML Driver. Let&#8217;s proceed and just do that.</p>
<h3>Create an Amazon S3 XML data source in ZappySys Data Gateway</h3>
<p>Follow the same steps as in <a href="#create-json-data-source">Create an Amazon S3 JSON data source in ZappySys Data Gateway</a> section when adding a new data source, except for these two steps:</p>
<ol>
<li>When adding a data source select <strong>Native &#8211; ZappySys Amazon S3 XML Driver</strong> as <em>Connector Type</em>:
<div id="attachment_7573" style="width: 430px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7573" class="wp-image-7573 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/06/685-create-new-xml-data-source-in-data-gateway-to-load-xml-files-into-sql-selver.png" alt="Choosing &quot;ZappySys Amazon S3 XML Driver&quot; to load XMLs to SQL Server" width="420" height="296" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/685-create-new-xml-data-source-in-data-gateway-to-load-xml-files-into-sql-selver.png 420w, https://zappysys.com/blog/wp-content/uploads/2019/06/685-create-new-xml-data-source-in-data-gateway-to-load-xml-files-into-sql-selver-300x211.png 300w" sizes="(max-width: 420px) 100vw, 420px" /><p id="caption-attachment-7573" class="wp-caption-text">Choosing &#8220;ZappySys Amazon S3 XML Driver&#8221; to load XMLs to SQL Server</p></div></li>
<li>Then click <strong>Edit</strong> and edit the data source similarly like in this window:
<div id="attachment_7547" style="width: 668px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7547" class="wp-image-7547 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/06/700-configure-amazon-s3-xml-data-source-to-load-into-sql-server-1.png" alt="Configuring data source based on ZappySys XML Driver to load XMLs into SQL Server" width="658" height="516" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/700-configure-amazon-s3-xml-data-source-to-load-into-sql-server-1.png 658w, https://zappysys.com/blog/wp-content/uploads/2019/06/700-configure-amazon-s3-xml-data-source-to-load-into-sql-server-1-300x235.png 300w" sizes="(max-width: 658px) 100vw, 658px" /><p id="caption-attachment-7547" class="wp-caption-text">Configuring data source based on ZappySys Amazon S3 XML Driver to load XMLs into SQL Server</p></div></li>
</ol>
<p>Now we are ready to set up a Linked Server to this newly created data source.</p>
<h3>Set up a SQL Server Linked Server</h3>
<p style="text-align: justify;">Follow the very same steps from the section above where we <a href="#set-up-a-sql-server-linked-server">added the Linked Server to a JSON data source</a>, except that change <em>Datasource</em> property of the Linked Server to match the name of the Amazon S3 XML data source you created. Once you do that, you are ready to load XMLs into your SQL Server.</p>
<h3>Execute the SQL query</h3>
<p>Again, if you created the Linked Server with name &#8220;GATEWAY&#8221;, execute this SQL query in SSMS:</p>
<p><code>SELECT * INTO MyContacts FROM openquery([GATEWAY], 'SELECT * FROM $')<br />
SELECT * FROM MyContacts</code></p>
<h3>The results</h3>
<p>You should see a similar view once you execute the query:</p>
<div id="attachment_7550" style="width: 614px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7550" class="wp-image-7550 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/06/750-the-result-of-importing-xml-data-from-amazon-s3-into-sql-server.png" alt="The data of many XMLs loaded from Amazon S3 bucket into SQL Server" width="604" height="360" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/750-the-result-of-importing-xml-data-from-amazon-s3-into-sql-server.png 604w, https://zappysys.com/blog/wp-content/uploads/2019/06/750-the-result-of-importing-xml-data-from-amazon-s3-into-sql-server-300x179.png 300w" sizes="(max-width: 604px) 100vw, 604px" /><p id="caption-attachment-7550" class="wp-caption-text">The data of many XMLs loaded from Amazon S3 bucket into SQL Server</p></div>
<p>Now we are ready to move to the next section and recursively scan CSVs and load them into SQL Server.</p>
<h2>Step-by-Step &#8211; Import CSV file located at Amazon S3 into SQL Server</h2>
<h3>Overview</h3>
<p>Let&#8217;s say you have many CSVs that are located in a folder tree, including subfolders and you want them all in your SQL Server:</p>
<div id="attachment_7552" style="width: 666px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7552" class="wp-image-7552 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/06/800-load-many-csv-files-from-subfolders-from-amazon-s3-bucket-into-sql-server.png" alt="Many CSV files located in Amazon S3 bucket folders and subfolders to be loaded into SQL Server" width="656" height="299" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/800-load-many-csv-files-from-subfolders-from-amazon-s3-bucket-into-sql-server.png 656w, https://zappysys.com/blog/wp-content/uploads/2019/06/800-load-many-csv-files-from-subfolders-from-amazon-s3-bucket-into-sql-server-300x137.png 300w" sizes="(max-width: 656px) 100vw, 656px" /><p id="caption-attachment-7552" class="wp-caption-text">Many CSV files located in Amazon S3 bucket folders and subfolders to be loaded into SQL Server</p></div>
<p>We will follow the same steps to accomplish that as we did for loading JSON and XMLs.</p>
<h3>Create an Amazon S3 CSV data source in ZappySys Data Gateway</h3>
<p>Follow the steps as in <a href="#create-json-data-source">Create an Amazon S3 JSON data source in ZappySys Data Gateway</a> section when adding a new data source, except for these two steps:</p>
<ol>
<li>When adding a CSV data source select <strong>Native &#8211; ZappySys Amazon S3 CSV Driver</strong> as <em>Connector Type</em>:
<div id="attachment_7574" style="width: 430px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7574" class="wp-image-7574 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/06/875-create-new-csv-data-source-in-data-gateway-to-load-csv-files-into-sql-selver.png" alt="Choosing &quot;ZappySys Amazon S3 CSV Driver&quot; to load CSVs to SQL Server" width="420" height="296" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/875-create-new-csv-data-source-in-data-gateway-to-load-csv-files-into-sql-selver.png 420w, https://zappysys.com/blog/wp-content/uploads/2019/06/875-create-new-csv-data-source-in-data-gateway-to-load-csv-files-into-sql-selver-300x211.png 300w" sizes="(max-width: 420px) 100vw, 420px" /><p id="caption-attachment-7574" class="wp-caption-text">Choosing &#8220;ZappySys Amazon S3 CSV Driver&#8221; to load CSVs to SQL Server</p></div></li>
<li>Then click <strong>Edit</strong> and edit the data source similarly:
<div id="attachment_7554" style="width: 752px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7554" class="wp-image-7554 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/06/900-configure-amazon-s3-csv-data-source-to-scan-csvs-recursively-and-load-into-sql-server.png" alt="Configuring data source based on ZappySys CSV Driver to load CSVs into SQL Server" width="742" height="582" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/900-configure-amazon-s3-csv-data-source-to-scan-csvs-recursively-and-load-into-sql-server.png 742w, https://zappysys.com/blog/wp-content/uploads/2019/06/900-configure-amazon-s3-csv-data-source-to-scan-csvs-recursively-and-load-into-sql-server-300x235.png 300w" sizes="(max-width: 742px) 100vw, 742px" /><p id="caption-attachment-7554" class="wp-caption-text">Configuring data source based on ZappySys Amazon S3 CSV Driver to load CSVs into SQL Server</p></div></li>
</ol>
<p>Now we are ready to proceed and add a Linked Server to this data source.</p>
<h3>Set up a SQL Server Linked Server</h3>
<p style="text-align: justify;">Again, follow the very same steps from the section above where we <a href="#set-up-a-sql-server-linked-server">added the Linked Server to a JSON data source</a>, except that change <em>Datasource</em> property of the Linked Server to match the name of the Amazon S3 CSV data source we created. Once you do that, you are ready to load CSVs into your SQL Server.</p>
<h3>Execute the SQL query</h3>
<p>Once again, if you created the Linked Server with name &#8220;GATEWAY&#8221;, execute this SQL query in SSMS:</p>
<p><code>SELECT * INTO MyContacts FROM openquery([GATEWAY], 'SELECT * FROM $')<br />
SELECT * FROM MyContacts</code></p>
<h3>The results</h3>
<p>You should see a similar view, once you execute the query:</p>
<div id="attachment_7559" style="width: 768px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7559" class="wp-image-7559 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/06/950-the-result-of-importing-multiple-csv-files-from-amazon-s3-into-sql-server-1.png" alt="The results of loading many CSVs from Amazon S3 bucket into SQL Server" width="758" height="365" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/950-the-result-of-importing-multiple-csv-files-from-amazon-s3-into-sql-server-1.png 758w, https://zappysys.com/blog/wp-content/uploads/2019/06/950-the-result-of-importing-multiple-csv-files-from-amazon-s3-into-sql-server-1-300x144.png 300w" sizes="(max-width: 758px) 100vw, 758px" /><p id="caption-attachment-7559" class="wp-caption-text">The results of loading many CSVs from Amazon S3 bucket into SQL Server</p></div>
<h2>Conclusion</h2>
<p style="text-align: justify;">We had a goal to import Amazon S3 files into SQL Server from SQL Server itself. We learned how to load JSON, XML and CSV files into SQL Server, which some of them were zipped and were located at different folders and subfolders. It was possible to accomplish that using <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ODBC PowerPack</a>, <a href="https://zappysys.com/products/odbc-powerpack/data-gateway/" target="_blank" rel="noopener">ZappySys Data Gateway</a> and ODBC PowerPack drivers &#8211; Amazon S3 JSON Driver, Amazon S3 XML Driver, and Amazon S3 CSV Driver. At first, we created data sources in the Data Gateway, then we created Linked Servers in SQL Server and connected to ZappySys Data Gateway, which finally made it possible to load data from Amazon S3 bucket straight from SQL queries in SSMS.</p>
<h2>Check Amazon S3 Integration with Other BI Tools (Power BI, Excel, SSRS, MS Access, etc.)</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>
<p>The post <a href="https://zappysys.com/blog/import-amazon-s3-files-sql-server-csv-json-xml-driver/">Import Amazon S3 files into SQL Server (CSV/JSON/XML Driver)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Import Azure Blob files into SQL Server (CSV/JSON/XML Driver)</title>
		<link>https://zappysys.com/blog/import-azure-blob-files-sql-server-csv-json-xml-driver/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Wed, 07 Aug 2019 15:52:30 +0000</pubDate>
				<category><![CDATA[Azure Blob CSV Driver]]></category>
		<category><![CDATA[Azure Blob JSON Driver]]></category>
		<category><![CDATA[Azure Blob XML Driver]]></category>
		<category><![CDATA[ODBC Drivers]]></category>
		<category><![CDATA[ODBC Gateway]]></category>
		<category><![CDATA[ODBC PowerPack]]></category>
		<category><![CDATA[azure]]></category>
		<category><![CDATA[blob]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[linked server]]></category>
		<category><![CDATA[sql server]]></category>
		<category><![CDATA[xml]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=7638</guid>

					<description><![CDATA[<p>Introduction There might be a case when you have many CSV, JSON or XML files in Azure Blob and you want them to be imported straight into a SQL Server table. Here come ZappySys ODBC PowerPack and ZappySys Data Gateway (part of ODBC PowerPack) which will enable you to accomplish that. ZappySys ODBC PowerPack includes powerful Azure [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/import-azure-blob-files-sql-server-csv-json-xml-driver/">Import Azure Blob files into SQL Server (CSV/JSON/XML Driver)</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="alignnone wp-image-7639 size-thumbnail alignleft" src="https://zappysys.com/blog/wp-content/uploads/2019/08/blob-to-sql-150x150.png" alt="" width="150" height="150" srcset="https://zappysys.com/blog/wp-content/uploads/2019/08/blob-to-sql-150x150.png 150w, https://zappysys.com/blog/wp-content/uploads/2019/08/blob-to-sql-300x300.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/08/blob-to-sql.png 400w" sizes="(max-width: 150px) 100vw, 150px" />There might be a case when you have many CSV, JSON or XML files in Azure Blob and you want them to be imported straight into a SQL Server table. Here come <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ZappySys ODBC PowerPack</a> and <a href="https://zappysys.com/products/odbc-powerpack/data-gateway/" target="_blank" rel="noopener">ZappySys Data Gateway</a> (part of ODBC PowerPack) which will enable you to accomplish that. ZappySys ODBC PowerPack includes powerful Azure Blob CSV, Azure Blob JSON and Azure Blob XML drivers that let you connect to an Azure Storage Explorer and read the contents from the files in the Container. Bringing in ZappySys Data Gateway allows doing that right from a SQL Server. Let&#8217;s begin and see how to Import Azure Blob files into SQL Server (CSV/JSON/XML Driver).</p>
<p>These drivers are related to this article:</p>
<div class="content_block" id="custom_post_widget-7641"><div style="display: table-row; background: #f7f7f7;">
<div style="display: table-cell; padding: 1em; border: 1px solid #ccc;"><img loading="lazy" decoding="async" style="vertical-align: middle; width: 50px; height: 50px; max-width: 50px;" src="//zappysys.com/images/odbc-powerpack/odbc-azure-blob-csv-driver.png" alt="Azure Blob CSV Driver" width="50" height="50" /></div>
<div style="display: table-cell; padding: 1em; border: 1px solid #ccc; border-left: none; width: 100%;"><a href="//zappysys.com/products/odbc-powerpack/azure-blob-odbc-driver-csv-files/" target="_blank" rel="noopener">Azure Blob Driver (for CSV Files)</a></div>
</div></div>
<div class="content_block" id="custom_post_widget-7643"><div style="display: table-row; background: #f7f7f7;">
<div style="display: table-cell; padding: 1em; border: 1px solid #ccc;"><img loading="lazy" decoding="async" style="vertical-align: middle; width: 50px; height: 50px; max-width: 50px;" src="https://zappysys.com/images/odbc-powerpack/odbc-azure-blob-json-driver.png" alt="Azure Blob JSON Driver" width="50" height="50" /></div>
<div style="display: table-cell; padding: 1em; border: 1px solid #ccc; border-left: none; width: 100%;"><a href="//zappysys.com/products/odbc-powerpack/azure-blob-odbc-driver-json-files/" target="_blank" rel="noopener">Azure Blob Driver (for JSON Files)</a></div>
</div></div>
<div class="content_block" id="custom_post_widget-7645"><div style="display: table-row; background: #f7f7f7;">
<div style="display: table-cell; padding: 1em; border: 1px solid #ccc;"><img loading="lazy" decoding="async" style="vertical-align: middle; width: 50px; height: 50px; max-width: 50px;" src="//zappysys.com/images/odbc-powerpack/odbc-azure-blob-xml-driver.png" alt="Azure Blob XML Driver" width="50" height="50" /></div>
<div style="display: table-cell; padding: 1em; border: 1px solid #ccc; border-left: none; width: 100%;"><a href="//zappysys.com/products/odbc-powerpack/azure-blob-odbc-driver-xml-files/" target="_blank" rel="noopener">Azure Blob Driver (for XML Files)</a></div>
</div></div>
<h2>Prerequisites</h2>
<ol>
<li>Firstly, Download and install <a href="https://go.microsoft.com/fwlink/?LinkId=717179&amp;clcid=0x4009" target="_blank" rel="noopener">Microsoft Azure Storage Emulator</a> and <a href="https://azure.microsoft.com/en-us/features/storage-explorer/" target="_blank" rel="noopener">Microsoft Azure Storage Explorer.</a></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>
<p><strong>NOTE:</strong> If you want to use Live account (Azure Storage) then you can skip Step #3</p>
<h2>Getting started</h2>
<p>In order to start, we will show several examples. ZappySys includes Data Gateway that will help you in reading data of Azure Blob files. Here we are showing you is, how to Import Azure Blob files into SQL Server (CSV/JSON/XML Driver).</p>
<p>You can connect to Azure Storage Service from SSIS, you will need Storage Account Name and Access Key. Ask your SysAdmin or responsible person to provide that information to you. <a href="https://zappysys.com/forums/topic/azure-blob-storage-how-to-create-new-storage-account-and-get-access-key/" target="_blank" rel="noopener">Click here</a> to read more about how to get your Storage Account Name and Access Key. Here are sample Credentials.</p><pre class="crayon-plain-tag">Account Name: mystorageaccount
Access Key: Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==</pre><p>
If you don&#8217;t have Azure Storage account then you can try offline mode on your local machine. You can just <a href="http://www.microsoft.com/en-us/download/details.aspx?id=42317" target="_blank" rel="noopener">download Azure Storage Emulator</a> and start testing.</p>
<h2><span id="Setup_Azure_Storage_client_tools_and_Create_Queue"><span id="Setup_Azure_Storage_client_tools">Setup Azure Storage Explorer</span></span></h2>
<p>Setup Azure Storage client tools we will start from a simple example of how to load Invoice Data from a CSV that is located in Azure Blob, then we will load JSON contacts data from them and finally, we will proceed by loading contacts from many XML files those are compressed in ZIP.</p>
<ol>
<li>Once you have <a href="https://go.microsoft.com/fwlink/?LinkId=717179&amp;clcid=0x4009" target="_blank" rel="noopener">downloaded and installed storage emulator</a> You can launch Microsoft Azure Storage Emulator from its Physical location or from the desktop or start menu shortcut.
<div id="attachment_3631" class="wp-caption aligncenter">
<p><a href="https://i1.wp.com/zappysys.com/blog/wp-content/uploads/2018/04/microsoft-azure-storage-emulator-location.png?ssl=1" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-3631 size-full" src="https://i1.wp.com/zappysys.com/blog/wp-content/uploads/2018/04/microsoft-azure-storage-emulator-location.png?resize=720%2C79&amp;ssl=1" alt="Azure Storage Emulator Physical Location" width="643" height="70" srcset="https://zappysys.com/blog/wp-content/uploads/2018/04/microsoft-azure-storage-emulator-location.png 859w, https://zappysys.com/blog/wp-content/uploads/2018/04/microsoft-azure-storage-emulator-location-300x33.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/04/microsoft-azure-storage-emulator-location-768x84.png 768w" sizes="(max-width: 643px) 100vw, 643px" /></a></p>
<p class="wp-caption-text">Azure Storage Emulator Physical Location</p>
</div>
</li>
<li>If you can see the below-attached Command Prompt screen after Emulator started. Then you can proceed to start Microsoft Azure Storage Explorer as the Azure Storage Emulator is started successfully.
<div id="attachment_3633" class="wp-caption aligncenter">
<p><a href="https://i2.wp.com/zappysys.com/blog/wp-content/uploads/2018/04/microsoft-azure-storage-emulator-screen-after-started-e1552723801433.png?ssl=1" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-3633 size-full" src="https://i2.wp.com/zappysys.com/blog/wp-content/uploads/2018/04/microsoft-azure-storage-emulator-screen-after-started-e1552723801433.png?resize=700%2C237&amp;ssl=1" alt="Command Prompt Screen after Microsoft Azure Storage Emulator Started" width="643" height="218" /></a></p>
<p class="wp-caption-text">Command Prompt Screen after Microsoft Azure Storage Emulator Started</p>
</div>
</li>
<li>Now, you have to <a href="https://azure.microsoft.com/en-us/features/storage-explorer/" target="_blank" rel="noopener">download and install Microsoft Azure Storage Explorer</a> and then you can launch Microsoft Azure Storage Explorer from its Physical location or from the desktop or start menu shortcut.
<div id="attachment_3635" class="wp-caption aligncenter">
<p><a href="https://i0.wp.com/zappysys.com/blog/wp-content/uploads/2018/04/microsoft-azure-storage-explorer-location.png?ssl=1" target="_blank" rel="noopener"><img loading="lazy" decoding="async" class="wp-image-3635 size-full" src="https://i0.wp.com/zappysys.com/blog/wp-content/uploads/2018/04/microsoft-azure-storage-explorer-location.png?resize=720%2C84&amp;ssl=1" alt="Microsoft Azure Storage Explorer Location" width="643" height="75" srcset="https://zappysys.com/blog/wp-content/uploads/2018/04/microsoft-azure-storage-explorer-location.png 827w, https://zappysys.com/blog/wp-content/uploads/2018/04/microsoft-azure-storage-explorer-location-300x35.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/04/microsoft-azure-storage-explorer-location-768x90.png 768w" sizes="(max-width: 643px) 100vw, 643px" /></a></p>
<p class="wp-caption-text">Microsoft Azure Storage Explorer Location.</p>
</div>
</li>
<li>For Creating a Blob Container, First of all, you need to go to Microsoft Storage Explorer Window. Then you can go through like this way (Storage Accounts –&gt; (Development) –&gt; Blob Containers).
<div id="attachment_3637" style="width: 556px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/04/microsoft-azure-storage-explorer-create-blob-container-e1552723740747.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-3637" class="size-full wp-image-3637" src="https://zappysys.com/blog/wp-content/uploads/2018/04/microsoft-azure-storage-explorer-create-blob-container-e1552723740747.png" alt="Microsoft Azure Storage Explorer : Create Blob Container" width="546" height="584" srcset="https://zappysys.com/blog/wp-content/uploads/2018/04/microsoft-azure-storage-explorer-create-blob-container-e1552723740747.png 546w, https://zappysys.com/blog/wp-content/uploads/2018/04/microsoft-azure-storage-explorer-create-blob-container-e1552723740747-280x300.png 280w" sizes="(max-width: 546px) 100vw, 546px" /></a><p id="caption-attachment-3637" class="wp-caption-text">Microsoft Azure Storage Explorer: Create a Blob Container</p></div></li>
</ol>
<h2><span style="font-size: 14pt;">Open and Configure ZappySys Data Gateway</span></h2>
<div class="content_block" id="custom_post_widget-7369">Now let's look at steps to configure Data Gateway after installation:
<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/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">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 decoding="async" src="https://zappysys.com/blog/wp-content/uploads/2018/11/zappysys-data-gateway-add-user.png" alt="Add Data Gateway User" /></a>
<p class="wp-caption-text">Add Data Gateway User</p>

</div></li>
</ol>
&nbsp;</div>
<h2>Import CSV file located at Azure Blob into SQL Server</h2>
<h3>Overview</h3>
<p>Let&#8217;s say you have CSV file that is located in Azure Blob Container, and you want them all data into your SQL Server. We will follow the same steps for that we will do for import JSON and XML file into SQL Server.</p>
<div id="attachment_7719" style="width: 612px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/08/azure-blob-csv-file-list.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7719" class="wp-image-7719 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/08/azure-blob-csv-file-list.png" alt="Azure Blob Container - CSV File Located" width="602" height="418" srcset="https://zappysys.com/blog/wp-content/uploads/2019/08/azure-blob-csv-file-list.png 602w, https://zappysys.com/blog/wp-content/uploads/2019/08/azure-blob-csv-file-list-300x208.png 300w" sizes="(max-width: 602px) 100vw, 602px" /></a><p id="caption-attachment-7719" class="wp-caption-text">Azure Blob Container &#8211; CSV File Located</p></div>
<h3>Create an Azure Blob CSV data source in ZappySys Data Gateway</h3>
<ol>
<li>The first thing you will have to do is to create a data source in ZappySys Data Gateway. In the Data Source tab, Just click on <strong>Add</strong> button, give the data source a name, e.g. &#8220;<strong>MyInvoiceCSV</strong>&#8220;, and then select <strong>Native &#8211; ZappySys Azure Blob CSV Driver</strong><strong>.</strong>
<div id="attachment_7746" style="width: 572px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/08/azure-blob-csv-data-source-e1565697707852.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7746" class="wp-image-7746 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/08/azure-blob-csv-data-source-e1565697707852.png" alt="Create Data Source - Azure Blob CSV Driver" width="562" height="539" srcset="https://zappysys.com/blog/wp-content/uploads/2019/08/azure-blob-csv-data-source-e1565697707852.png 562w, https://zappysys.com/blog/wp-content/uploads/2019/08/azure-blob-csv-data-source-e1565697707852-300x288.png 300w" sizes="(max-width: 562px) 100vw, 562px" /></a><p id="caption-attachment-7746" class="wp-caption-text">Create Data Source &#8211; Azure Blob CSV Driver</p></div></li>
<li>Then click on <strong>Edit</strong> and add the Data Gateway user you created in the <strong>Users</strong> tab. We will use this user later when adding a Linked Server to the Data Gateway to authenticate:<img loading="lazy" decoding="async" class="size-full wp-image-7864 aligncenter" src="https://zappysys.com/blog/wp-content/uploads/2019/08/import-csv-from-azure-blob-storage-to-sql-server-add-user.png" alt="" width="681" height="629" srcset="https://zappysys.com/blog/wp-content/uploads/2019/08/import-csv-from-azure-blob-storage-to-sql-server-add-user.png 681w, https://zappysys.com/blog/wp-content/uploads/2019/08/import-csv-from-azure-blob-storage-to-sql-server-add-user-300x277.png 300w" sizes="(max-width: 681px) 100vw, 681px" /></li>
<li>Now, click on the Edit button to configure &#8220;<strong>MyInvoiceCSV</strong>&#8221; Azure Blob CSV Data Source.
<div id="attachment_7722" style="width: 572px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/08/edit-azure-blob-csv-data-source.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7722" class="wp-image-7722 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/08/edit-azure-blob-csv-data-source.png" alt="Configure Data Gateway" width="562" height="539" srcset="https://zappysys.com/blog/wp-content/uploads/2019/08/edit-azure-blob-csv-data-source.png 562w, https://zappysys.com/blog/wp-content/uploads/2019/08/edit-azure-blob-csv-data-source-300x288.png 300w" sizes="(max-width: 562px) 100vw, 562px" /></a><p id="caption-attachment-7722" class="wp-caption-text">Configure Data Gateway</p></div></li>
<li>When a window open, click on <strong>Click here to Configure the Connection</strong> and select Use the Microsoft Azure Storage Emulator. If you have Online <em>Storage Account</em> and <em><em>Account Key </em></em>then Select Enter Storage Account Credentials and enter it.<em><em><br />
</em></em></p>
<div style="width: 503px" class="wp-caption aligncenter"><a href="https://zappysys.com/onlinehelp/odbc-powerpack/scr/images/azure-blob-json-driver/azure-blob-json-driver-create-connection.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" src="https://zappysys.com/onlinehelp/odbc-powerpack/scr/images/azure-blob-json-driver/azure-blob-json-driver-create-connection.png" alt="Create Azure Storage Connection" width="493" height="499" /></a><p class="wp-caption-text">Create Azure Storage Connection</p></div></li>
<li>Now, Select Azure Blob Container and file from it and In the Data Format / Compression (Zip / GZip) tab set suitable file Compression Format (Zip or GZip).
<div id="attachment_7721" style="width: 753px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/08/configure-azure-blob-csv-data-source.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7721" class="wp-image-7721 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/08/configure-azure-blob-csv-data-source.png" alt="ZappySys Azure Blob CSV - Configure Driver" width="743" height="623" srcset="https://zappysys.com/blog/wp-content/uploads/2019/08/configure-azure-blob-csv-data-source.png 743w, https://zappysys.com/blog/wp-content/uploads/2019/08/configure-azure-blob-csv-data-source-300x252.png 300w" sizes="(max-width: 743px) 100vw, 743px" /></a><p id="caption-attachment-7721" class="wp-caption-text">ZappySys Azure Blob CSV &#8211; Configure Driver</p></div></li>
<li>Go to the <strong>Preview</strong> tab and click on the <strong>Preview Data</strong> button to make sure everything is configured correctly and preview the results.
<div id="attachment_7726" style="width: 753px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/08/preview-azure-blob-csv-data-source.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7726" class="wp-image-7726 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/08/preview-azure-blob-csv-data-source.png" alt="ZappySys Azure Blob CSV - Preview Data" width="743" height="570" srcset="https://zappysys.com/blog/wp-content/uploads/2019/08/preview-azure-blob-csv-data-source.png 743w, https://zappysys.com/blog/wp-content/uploads/2019/08/preview-azure-blob-csv-data-source-300x230.png 300w" sizes="(max-width: 743px) 100vw, 743px" /></a><p id="caption-attachment-7726" class="wp-caption-text">ZappySys Azure Blob CSV &#8211; Preview Data</p></div></li>
<li>Now, Click on OK button also Save and Restart Service.
<div id="attachment_7724" style="width: 572px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/08/save-and-restart-service-data-source.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7724" class="wp-image-7724 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/08/save-and-restart-service-data-source.png" alt="ZappySys Data Gateway Service - Save and Restart" width="562" height="539" srcset="https://zappysys.com/blog/wp-content/uploads/2019/08/save-and-restart-service-data-source.png 562w, https://zappysys.com/blog/wp-content/uploads/2019/08/save-and-restart-service-data-source-300x288.png 300w" sizes="(max-width: 562px) 100vw, 562px" /></a><p id="caption-attachment-7724" class="wp-caption-text">ZappySys Data Gateway Service &#8211; Save and Restart</p></div></li>
<li>That&#8217;s all, now we are ready to proceed and add a Linked Server to this data source.</li>
</ol>
<h3 id="Set-up-a-SQL-Server-Linked-Server">Set up a SQL Server Linked Server</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>Execute the SQL query</h3>
<p>Once again, if you created the Linked Server with name &#8220;GATEWAY&#8221;, execute this SQL query in SSMS:</p>
<p><code>SELECT * INTO MyInvoices FROM OPENQUERY([GATEWAY], 'SELECT * FROM $')<br />
SELECT * FROM MyInvoices</code></p>
<h3>The results</h3>
<p>You should see a similar view, once you execute the query:</p>
<div id="attachment_7862" style="width: 713px" class="wp-caption alignnone"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7862" class="wp-image-7862 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/08/80-import-csv-from-azure-blob-storage-into-sql-server-the-results-data-is-loaded-into-sql-server.png" alt="The results of loading many CSVs from Azure Blob into SQL Server" width="703" height="441" srcset="https://zappysys.com/blog/wp-content/uploads/2019/08/80-import-csv-from-azure-blob-storage-into-sql-server-the-results-data-is-loaded-into-sql-server.png 703w, https://zappysys.com/blog/wp-content/uploads/2019/08/80-import-csv-from-azure-blob-storage-into-sql-server-the-results-data-is-loaded-into-sql-server-300x188.png 300w" sizes="(max-width: 703px) 100vw, 703px" /><p id="caption-attachment-7862" class="wp-caption-text">The results of loading many CSVs from Azure Blob into SQL Server</p></div>
<h2>Import JSON file located at Azure Blob into SQL Server</h2>
<h3>Overview</h3>
<p>Let&#8217;s say you have JSON file that is located in Azure Blob Container, and you want them all data into your SQL Server. We will follow the same steps of the import CSV file into SQL Server and we will do for XML file into SQL Server.</p>
<h3>Create an Azure Blob JSON data source in ZappySys Data Gateway</h3>
<p>Follow the steps as in Create an Azure Blob CSV data source in ZappySys Data Gateway section when adding a new data source, except for these two steps:</p>
<ol>
<li>The first thing you will have to do is to create a data source in ZappySys Data Gateway. Just click <strong>Add</strong> button, give the data source a name, e.g. &#8220;<strong>MyContactsJSON</strong>&#8220;, and then select <strong>Native &#8211; ZappySys Azure Blob JSON Driver.</strong>
<div id="attachment_7663" style="width: 637px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/08/10-create-new-data-source-in-data-gateway-to-load-json-files-from-azure-blob-into-sql-server-1.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7663" class="wp-image-7663 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/08/10-create-new-data-source-in-data-gateway-to-load-json-files-from-azure-blob-into-sql-server-1.png" alt="ZappySys Data Gateway - Create New Data Source" width="627" height="583" srcset="https://zappysys.com/blog/wp-content/uploads/2019/08/10-create-new-data-source-in-data-gateway-to-load-json-files-from-azure-blob-into-sql-server-1.png 627w, https://zappysys.com/blog/wp-content/uploads/2019/08/10-create-new-data-source-in-data-gateway-to-load-json-files-from-azure-blob-into-sql-server-1-300x279.png 300w" sizes="(max-width: 627px) 100vw, 627px" /></a><p id="caption-attachment-7663" class="wp-caption-text">ZappySys Data Gateway &#8211; Create New Data Source</p></div>
<div class="mceTemp"></div>
<div class="mceTemp"></div>
</li>
<li>After that, select a JSON file from container you want to load, and then click <strong>Select Filter</strong> button to choose data you want to be displayed in SQL Server.
<div id="attachment_7670" style="width: 667px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/08/40-configure-azure-blob-json-data-source-to-load-data-into-sql-server-1.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7670" class="wp-image-7670 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/08/40-configure-azure-blob-json-data-source-to-load-data-into-sql-server-1.png" alt="Configuring the JSON data source to load a JSON from Azure Blob container into SQL Server" width="657" height="702" srcset="https://zappysys.com/blog/wp-content/uploads/2019/08/40-configure-azure-blob-json-data-source-to-load-data-into-sql-server-1.png 657w, https://zappysys.com/blog/wp-content/uploads/2019/08/40-configure-azure-blob-json-data-source-to-load-data-into-sql-server-1-281x300.png 281w" sizes="(max-width: 657px) 100vw, 657px" /></a><p id="caption-attachment-7670" class="wp-caption-text">Configuring the JSON data source to load a JSON from Azure Blob container into SQL Server</p></div></li>
</ol>
<p>Now you are ready to create a Linked Server and connect to the data source you just created. If you used &#8220;<strong>MyContactsJSON</strong>&#8221; as the data source name, make sure to use the same name when creating a Linked Server.</p>
<h3>Set up a SQL Server Linked Server</h3>
<p>Again, follow the very same steps from the section above where we <a href="#Set-up-a-SQL-Server-Linked-Server">added the Linked Server to a CSV data source</a>, except that change <em>Catalog</em> property of the Linked Server to match the name of the Azure Blob JSON data source we created. Once you do that, you are ready to load JSON into your SQL Server.</p>
<h3>Execute the SQL query</h3>
<p style="text-align: justify;">Once you created the Linked Server to ZappySys Data Gateway, you are ready to execute the SQL query and load data into SQL Server. Supposedly, you created the Linked Server with the name &#8220;GATEWAY&#8221;, then open SSMS and execute the following query:</p>
<p><code>SELECT * INTO MyContacts FROM openquery([GATEWAY], 'SELECT * FROM $')<br />
SELECT * FROM MyContacts</code></p>
<h3>The results</h3>
<p>You should see similar results after you execute the query:</p>
<div id="attachment_7536" style="width: 609px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/06/600-the-results-of-importing-amazon-s3-data-into-sql-server-using-json-driver.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7536" class="wp-image-7536 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/06/600-the-results-of-importing-amazon-s3-data-into-sql-server-using-json-driver.png" alt="The results of getting JSON data straight from Azure Blob JSON" width="599" height="257" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/600-the-results-of-importing-amazon-s3-data-into-sql-server-using-json-driver.png 599w, https://zappysys.com/blog/wp-content/uploads/2019/06/600-the-results-of-importing-amazon-s3-data-into-sql-server-using-json-driver-300x129.png 300w" sizes="(max-width: 599px) 100vw, 599px" /></a><p id="caption-attachment-7536" class="wp-caption-text">The results of getting JSON data straight from Azure Blob JSON</p></div>
<p>Now we are ready to proceed to the next section and import many XML files at once.</p>
<h2>Import many XML files located at Azure Blob into SQL Server</h2>
<h3>Overview</h3>
<p>Supposedly, you have many XMLs where each one is zipped and you want to load them all into a SQL Server table.</p>
<div id="attachment_7675" style="width: 616px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/08/65-load-many-compressed-xml-files-from-azure-blob-container-into-sql-server.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7675" class="wp-image-7675 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/08/65-load-many-compressed-xml-files-from-azure-blob-container-into-sql-server.png" alt="Zipped XML files located in Azure Blob container to be loaded into SQL Server" width="606" height="415" srcset="https://zappysys.com/blog/wp-content/uploads/2019/08/65-load-many-compressed-xml-files-from-azure-blob-container-into-sql-server.png 606w, https://zappysys.com/blog/wp-content/uploads/2019/08/65-load-many-compressed-xml-files-from-azure-blob-container-into-sql-server-300x205.png 300w" sizes="(max-width: 606px) 100vw, 606px" /></a><p id="caption-attachment-7675" class="wp-caption-text">Zipped XML files located in Azure Blob container to be loaded into SQL Server</p></div>
<p>The first thing you will have to do is to create a data source, based on ZappySys Azure Blob XML Driver. Let&#8217;s proceed and just do that.</p>
<h3>Create an Azure Blob XML data source in ZappySys Data Gateway</h3>
<p>Follow the same steps as in Create an Azure Blob JSON data source in ZappySys Data Gateway section when adding a new data source, except for these two steps:</p>
<ol>
<li>When adding a data source select <strong>Native &#8211; ZappySys Azure Blob XML Driver</strong> as <em>Connector Type.</em>
<div id="attachment_7674" style="width: 430px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/08/67-create-new-azure-blob-xml-data-source-in-data-gateway-to-load-xml-files-into-sql-selver.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7674" class="wp-image-7674 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/08/67-create-new-azure-blob-xml-data-source-in-data-gateway-to-load-xml-files-into-sql-selver.png" alt="Choosing &quot;ZappySys Azure Blob XML Driver&quot; to load XMLs to SQL Server" width="420" height="296" srcset="https://zappysys.com/blog/wp-content/uploads/2019/08/67-create-new-azure-blob-xml-data-source-in-data-gateway-to-load-xml-files-into-sql-selver.png 420w, https://zappysys.com/blog/wp-content/uploads/2019/08/67-create-new-azure-blob-xml-data-source-in-data-gateway-to-load-xml-files-into-sql-selver-300x211.png 300w" sizes="(max-width: 420px) 100vw, 420px" /></a><p id="caption-attachment-7674" class="wp-caption-text">Choosing &#8220;ZappySys Azure Blob XML Driver&#8221; to load XMLs to SQL Server</p></div>
<div class="mceTemp"></div>
</li>
<li>Then click on <strong>Edit</strong> and select Azure Blob Container and file from it and In the Data Format / Compression (Zip / GZip) tab set suitable file Compression Format (Zip or GZip).
<div id="attachment_7673" style="width: 667px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/08/70-configure-azure-blob-xml-data-source-to-load-into-sql-server.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7673" class="wp-image-7673 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/08/70-configure-azure-blob-xml-data-source-to-load-into-sql-server.png" alt="Configuring data source based on ZappySys Azure Blob XML Driver to load XMLs into SQL Server" width="657" height="515" srcset="https://zappysys.com/blog/wp-content/uploads/2019/08/70-configure-azure-blob-xml-data-source-to-load-into-sql-server.png 657w, https://zappysys.com/blog/wp-content/uploads/2019/08/70-configure-azure-blob-xml-data-source-to-load-into-sql-server-300x235.png 300w" sizes="(max-width: 657px) 100vw, 657px" /></a><p id="caption-attachment-7673" class="wp-caption-text">Configuring data source based on ZappySys Azure Blob XML Driver to load XMLs into SQL Server</p></div></li>
<li>Now we are ready to set up a Linked Server to this newly created data source.</li>
</ol>
<h3>Set up a SQL Server Linked Server</h3>
<p style="text-align: justify;">Follow the very same steps from the section above where we <a href="#Set-up-a-SQL-Server-Linked-Server">added the Linked Server to a CSV data source</a>, except that change <em>Catalog</em> property of the Linked Server to match the name of the Azure Blob XML data source you created. Once you do that, you are ready to load XMLs into your SQL Server.</p>
<h3>Execute the SQL query</h3>
<p>Again, if you created the Linked Server with name &#8220;GATEWAY&#8221;, execute the following SQL query in SSMS:</p>
<p><code>SELECT * INTO MyContacts FROM openquery([GATEWAY], 'SELECT * FROM $')<br />
SELECT * FROM MyContacts</code></p>
<h3>The results</h3>
<p>You should see a similar view once you execute the query:</p>
<div id="attachment_7550" style="width: 614px" class="wp-caption aligncenter"><a href="https://zappysys.com/blog/wp-content/uploads/2019/06/750-the-result-of-importing-xml-data-from-amazon-s3-into-sql-server.png" target="_blank" rel="noopener"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-7550" class="wp-image-7550 size-full" src="https://zappysys.com/blog/wp-content/uploads/2019/06/750-the-result-of-importing-xml-data-from-amazon-s3-into-sql-server.png" alt="The data of many XMLs loaded from Azure Blob Container into SQL Server" width="604" height="360" srcset="https://zappysys.com/blog/wp-content/uploads/2019/06/750-the-result-of-importing-xml-data-from-amazon-s3-into-sql-server.png 604w, https://zappysys.com/blog/wp-content/uploads/2019/06/750-the-result-of-importing-xml-data-from-amazon-s3-into-sql-server-300x179.png 300w" sizes="(max-width: 604px) 100vw, 604px" /></a><p id="caption-attachment-7550" class="wp-caption-text">The data of many XMLs loaded from Azure Blob Container into SQL Server</p></div>
<p>Now we are ready to move to the next section and recursively scan CSVs and load them into SQL Server.</p>
<h2>Conclusion</h2>
<p style="text-align: justify;">We had a goal to import Azure Blob files into SQL Server from SQL Server itself. We learned how to Import Azure Blob files into SQL Server (CSV/JSON/XML Driver), which some of them were zipped and were located at different folders and subfolders. It was possible to accomplish that using <a href="https://zappysys.com/products/odbc-powerpack/" target="_blank" rel="noopener">ODBC PowerPack</a>, <a href="https://zappysys.com/products/odbc-powerpack/data-gateway/" target="_blank" rel="noopener">ZappySys Data Gateway</a>, and ODBC PowerPack drivers &#8211; Azure Blob JSON Driver, Azure Blob XML Driver, and Azure Blob CSV Driver. At first, we created data sources in the Data Gateway, then we created Linked Servers in SQL Server and connected to ZappySys Data Gateway, which finally made it possible to load data from Azure Blob straight from SQL queries in SSMS.</p>
<h2>References</h2>
<p>Finally, you can use the following links for more information:</p>
<ul>
<li><a href="https://zappysys.com/onlinehelp/odbc-powerpack/scr/azure-blob-csv-odbc-driver-intro.htm" target="_blank" rel="noopener">Azure Blob CSV Driver</a></li>
<li><a href="https://zappysys.com/onlinehelp/odbc-powerpack/scr/azure-blob-json-odbc-driver-intro.htm" target="_blank" rel="noopener">Azure Blob JSON Driver</a></li>
<li><a href="https://zappysys.com/onlinehelp/odbc-powerpack/scr/azure-blob-xml-odbc-driver-intro.htm" target="_blank" rel="noopener">Azure Blob XML Driver</a></li>
</ul>
<p>The post <a href="https://zappysys.com/blog/import-azure-blob-files-sql-server-csv-json-xml-driver/">Import Azure Blob files into SQL Server (CSV/JSON/XML Driver)</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>ODBC PowerPack v1.1.3 Released</title>
		<link>https://zappysys.com/blog/odbc-powerpack-v1-1-3/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Tue, 25 Jun 2019 13:35:30 +0000</pubDate>
				<category><![CDATA[Announcements]]></category>
		<category><![CDATA[ETL - Informatica]]></category>
		<category><![CDATA[ODBC Gateway]]></category>
		<category><![CDATA[Reporting - Microsoft Access]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=7296</guid>

					<description><![CDATA[<p>What&#8217;s New In this release we focused on adding URL JOIN Features which may allow many multi steps scenarios in one query. Bing Ads, Amazon MWS, Google BigQuery, Amazon Athena all these supports Job style queries which needs 3 step process (Create job, keep checking status, once done read report data). We also improved compatibility [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/odbc-powerpack-v1-1-3/">ODBC PowerPack v1.1.3 Released</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h2>What&#8217;s New</h2>
<p>In this release we focused on adding URL JOIN Features which may allow many multi steps scenarios in one query. Bing Ads, Amazon MWS, Google BigQuery, Amazon Athena all these supports Job style queries which needs 3 step process (Create job, keep checking status, once done read report data). We also improved compatibility with Informatica and MS Access.</p>
<h2 class="vertitle">Version 1.1.3.10621 [Jun 24, 2019]</h2>
<h3 class="versubtitle">New Features/Improvements</h3>
<ul>
<li><span class="verAdded">NEW: </span>Add option to replace placeholders in File content if you use IsMultiPart = True</li>
<li><span class="verAdded">NEW: </span>All API Drivers &#8211; Add option EnableBodyPlaceholderForMultiPart to support replacing placeholders in file content in IsMultiPart mode (E.g. replace &lt;%access_token%&gt; or [$token$] or [$alias.MyJoinColumn$] )</li>
<li><span class="verAdded">NEW: </span>All API Drivers &#8211; Add option OutputAsRawDocumentSingleRow (Returns __DOCUMENT__ field with entire File / Response string in one field)</li>
<li><span class="verAdded">NEW: </span>All API Drivers &#8211; Add Options to parse from any unstructured data &#8211; RawOutputExtractMode, RawOutputDataRowTemplate, RawOutputFilterExpr</li>
<li><span class="verAdded">NEW: </span>All API Drivers &#8211; Add Status Check feature for all API drivers (Keep sending request until desired value found) &#8211; Options added EnableStatusCheck, StatucCheckMaxWaitSeconds, StatucCheckIterationWaitSeconds, StatusSuccessValue, StatusFailureValue</li>
<li><span class="verAdded">NEW: </span>All API Drivers &#8211; Add support for ConnectionType in URL Join</li>
<li><span class="verAdded">NEW: </span>All API Drivers &#8211; Add Support for HMAC Authentication</li>
<li><span class="verAdded">NEW: </span>All ODBC Drivers &#8211; Add support for Parameters</li>
<li><span class="verAdded">NEW: </span>Data Gateway &#8211; Add Code Generator UI for SQL / Java</li>
<li><span class="verAdded">NEW: </span>Data Gateway &#8211; Allow to add firewall rule via UI</li>
<li><span class="verAdded">NEW: </span>Data Gateway &#8211; Better logging about connected devices</li>
<li><span class="verAdded">NEW: </span>Salesforce Driver &#8211; Add support for Select * FROM</li>
</ul>
<h3 class="versubtitle">Bug fixes</h3>
<ul>
<li><span class="verFixed">FIX: </span>All API Drivers &#8211; joinXX_DataConnectionType Option not supported in JOIN URL</li>
<li><span class="verFixed">FIX: </span>All API Drivers- Show meaningful error when same option used twice in WITH clause (Right now you see odd error &#8211; An item with the same key has already been added)</li>
<li><span class="verFixed">FIX: </span>Apps &#8211; Informatica &#8211; Driver may output many extra empty rows in some cases</li>
<li><span class="verFixed">FIX: </span>Apps &#8211; MS Access &#8211; Linked table throwing call fail error (due to missing support for parameters in current driver)</li>
<li><span class="verFixed">FIX: </span>Data Gateway &#8211; Certain errors not reported correctly back to caller</li>
<li><span class="verFixed">FIX: </span>Data Gateway &#8211; Enabling caching options may hang query in some case</li>
<li><span class="verFixed">FIX: </span>Data Gateway &#8211; Generic ODBC Connection Type fails with error Connection is Busy</li>
<li><span class="verFixed">FIX: </span>Data Gateway &#8211; When you use Meta option in WITH clause you may see empty rowset rather error in some cases</li>
<li><span class="verFixed">FIX: </span>Salesforce Driver &#8211; Can not load table list in Excel / Power BI</li>
<li><span class="verFixed">FIX: </span>Salesforce Driver &#8211; Failed to preview data in Power BI</li>
<li><span class="verFixed">FIX: </span>Salesforce Driver &#8211; Load ConnectionString doesnt set Username</li>
<li><span class="verFixed">FIX: </span>Salesforce Driver &#8211; Nested queries not supported &#8211; You may get syntax error</li>
<li><span class="verFixed">FIX: </span>Salesforce Driver &#8211; SSIS ODBC destination showing bad Table names in list</li>
</ul>
<p>The post <a href="https://zappysys.com/blog/odbc-powerpack-v1-1-3/">ODBC PowerPack v1.1.3 Released</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>
	</channel>
</rss>
