<?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>SSIS Script Component Archives | ZappySys Blog</title>
	<atom:link href="https://zappysys.com/blog/category/ssis/components/ssis-script-component/feed/" rel="self" type="application/rss+xml" />
	<link>https://zappysys.com/blog/category/ssis/components/ssis-script-component/</link>
	<description>SSIS / ODBC Drivers / API Connectors for JSON, XML, Azure, Amazon AWS, Salesforce, MongoDB and more</description>
	<lastBuildDate>Mon, 11 Feb 2019 16:01:17 +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>SSIS Script Component Archives | ZappySys Blog</title>
	<link>https://zappysys.com/blog/category/ssis/components/ssis-script-component/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to batch REST API requests in SSIS (Bulk Operation)</title>
		<link>https://zappysys.com/blog/batch-rest-api-requests-ssis-bulk-operation/</link>
		
		<dc:creator><![CDATA[ZappySys]]></dc:creator>
		<pubDate>Wed, 06 Feb 2019 21:32:43 +0000</pubDate>
				<category><![CDATA[SSIS CSV Generator Transform]]></category>
		<category><![CDATA[SSIS JSON Generator Transform]]></category>
		<category><![CDATA[SSIS Script Component]]></category>
		<category><![CDATA[SSIS WEB API Destination]]></category>
		<category><![CDATA[SSIS XML Generator Transform]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[rest api]]></category>
		<category><![CDATA[xml]]></category>
		<guid isPermaLink="false">https://zappysys.com/blog/?p=6305</guid>

					<description><![CDATA[<p>Introduction In our previous article we saw how to POST data to REST API using few different ways. Now let&#8217;s go one step further and discuss another common scenario to batch REST API requests in SSIS. For efficient data transfer many API provides you to submit multiple records in a single request. In this article [&#8230;]</p>
<p>The post <a href="https://zappysys.com/blog/batch-rest-api-requests-ssis-bulk-operation/">How to batch REST API requests in SSIS (Bulk Operation)</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 article we saw <a href="https://zappysys.com/blog/http-post-in-ssis-send-data-to-web-api-url-json-xml/" target="_blank" rel="noopener">how to POST data to REST API</a> using few different ways. Now let&#8217;s go one step further and discuss another common scenario to batch REST API requests in SSIS. For efficient data transfer many API provides you to submit multiple records in a single request. In this article we will look at few ways to batch our requests using <a href="https://zappysys.com/products/ssis-powerpack/ssis-json-generator-transform/" target="_blank" rel="noopener">SSIS JSON Generator Transform</a> and  <a href="https://zappysys.com/products/ssis-powerpack/ssis-web-api-destination-connector/" target="_blank" rel="noopener">SSIS Web API destination</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>Method 1 &#8211; Batch records using SSIS JSON / XML Generator Transform</h2>
<p>First let&#8217;s look at common way to group multiple records and generate single JSON or XML document for desired batch size. We will also see another technique where you can assign Unique BatchID to each document.</p>
<p>For example below screenshot shows how to product one JSON document for every 10 input rows. We have also use BatchID column on the root level. This will use use BatchID from first row of that batch. You can use <a href="https://zappysys.com/products/ssis-powerpack/ssis-xml-generator-transform/" target="_blank" rel="noopener">XML Generator Transform</a> if you like to produce XML Document rather than JSON.</p>
<p>To generate Unique BatchID you can use function like newid() in SQL Server.</p><pre class="crayon-plain-tag">SELECT newid() as BatchID,CustomerID,CompanyName FROM Customers</pre><p>
<div id="attachment_6306" style="width: 1115px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-generate-json-with-batch-setting.png"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-6306" class="size-full wp-image-6306" src="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-generate-json-with-batch-setting.png" alt="Using SSIS JSON Generator Transform with Batch Option (Multiple Records in a single document)" width="1105" height="865" srcset="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-generate-json-with-batch-setting.png 1105w, https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-generate-json-with-batch-setting-300x235.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-generate-json-with-batch-setting-768x601.png 768w, https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-generate-json-with-batch-setting-1024x802.png 1024w" sizes="(max-width: 1105px) 100vw, 1105px" /></a><p id="caption-attachment-6306" class="wp-caption-text">Using SSIS JSON Generator Transform with Batch Option (Multiple Records in a single document)</p></div>
<p>&nbsp;</p>
<p>Here if full flow to batch your JSON Requests and Submit to REST API.</p>
<div id="attachment_6307" style="width: 671px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-post-data-rest-api-in-batch.png"><img decoding="async" aria-describedby="caption-attachment-6307" class="size-full wp-image-6307" src="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-post-data-rest-api-in-batch.png" alt="POST data to REST API in Bulk Mode (Batch multiple rows)" width="661" height="785" srcset="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-post-data-rest-api-in-batch.png 661w, https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-post-data-rest-api-in-batch-253x300.png 253w" sizes="(max-width: 661px) 100vw, 661px" /></a><p id="caption-attachment-6307" class="wp-caption-text">POST data to REST API in Bulk Mode (Batch multiple rows)</p></div>
<p>&nbsp;</p>
<h2>Method 2 &#8211; Using SSIS Web API destination Batch Mode with Header / Footer</h2>
<p>Another method of batching is use Web API destination and turn on Batch mode.  You can <a href="https://zappysys.com/blog/how-to-use-fiddler-to-analyze-http-web-requests/" target="_blank" rel="noopener">use Fiddler</a> to debug your web requests incase you are not sure how its generating and sending POST requests after this setting.</p>
<div id="attachment_2616" style="width: 919px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2018/02/ssis-call-smartsheet-rest-api-post-bulk-mode-web-api-destination.png"><img decoding="async" aria-describedby="caption-attachment-2616" class="size-full wp-image-2616" src="https://zappysys.com/blog/wp-content/uploads/2018/02/ssis-call-smartsheet-rest-api-post-bulk-mode-web-api-destination.png" alt="Configure SSIS Web API Destination for Bulk API call (Smartsheet REST API - Insert multiple rows)" width="909" height="445" srcset="https://zappysys.com/blog/wp-content/uploads/2018/02/ssis-call-smartsheet-rest-api-post-bulk-mode-web-api-destination.png 909w, https://zappysys.com/blog/wp-content/uploads/2018/02/ssis-call-smartsheet-rest-api-post-bulk-mode-web-api-destination-300x147.png 300w, https://zappysys.com/blog/wp-content/uploads/2018/02/ssis-call-smartsheet-rest-api-post-bulk-mode-web-api-destination-768x376.png 768w" sizes="(max-width: 909px) 100vw, 909px" /></a><p id="caption-attachment-2616" class="wp-caption-text">Configure SSIS Web API Destination for Bulk API call (Insert multiple rows)</p></div>
<h2>Method 3 &#8211; Batch CSV records using CSV Generator Transform</h2>
<p>So far we looked at how to batch JSON and XML format. Now let&#8217;s look at scenario where you have to POST CSV formatted data to REST API endpoint.</p>
<p>Assume that you have an API endpoint where you can submit data in multiple batches. Also you have few additional requirements</p>
<ol>
<li>First row of First batch must have column names (any other batch must not contains CSV Header)</li>
<li>In each Batch we want to submit maximum 5 rows as per API call</li>
<li>Each batch must contain Unique Batch Number in URL</li>
</ol>
<p>Here is high level flow.</p>
<div id="attachment_6333" style="width: 1148px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-generate-csv-using-output-in-batch-setting.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-6333" class="size-full wp-image-6333" src="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-generate-csv-using-output-in-batch-setting.png" alt="Generate CSV using Batch Setting , Send data to REST API in multiple batches, Debug REST API in Fiddler" width="1138" height="508" srcset="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-generate-csv-using-output-in-batch-setting.png 1138w, https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-generate-csv-using-output-in-batch-setting-300x134.png 300w, https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-generate-csv-using-output-in-batch-setting-768x343.png 768w, https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-generate-csv-using-output-in-batch-setting-1024x457.png 1024w" sizes="(max-width: 1138px) 100vw, 1138px" /></a><p id="caption-attachment-6333" class="wp-caption-text">Generate CSV using Batch Setting , Send data to REST API in multiple batches, Debug REST API in Fiddler</p></div>
<h3>Include CSV Header in First Batch Only</h3>
<p>Now let&#8217;s break down the problem and find out how to do. First problem is we need to include CSV Header only in First batch. To achieve this we use old school trick where we output column names as data row&#8230; and when we generate CSV in the next section we will turn off Column Headers option.</p>
<p>If you are consuming records from SQL Server or any other RDBMS you can write following style source query. If you don&#8217;t use relational source then use native UNION Transform in SSIS.</p><pre class="crayon-plain-tag">select 'CustomerID' as Column1, 'OrderID' as Column2
UNION ALL
select top 12 cast(CustomerID as varchar(1000)), cast(OrderID as varchar(1000)) from Invoices</pre><p>
<h3>Batch records and output CSV data</h3>
<p>Now next step would be to generate CSV data but in batches&#8230; so in our example we have to output size of 5 rows per batch. For this perform the following steps</p>
<ol>
<li>Drag ZS CSV Generator Transform (Included in <strong>v2.8</strong> and Higher)</li>
<li>Connect source to CSV Generator Transform</li>
<li>Now before we edit in UI mode, <strong>right click</strong> and select <strong>Properties</strong>. Change following 3 properties  (You can also change QuoteAroundValue and Dimiliter if needed). In future version batch setting will be visible in UI mode too.
<ol>
<li>ArrayBatchSize  = yourbatchsize (in our case it was just 5 rows per batch)</li>
<li>OutputMode = SingleFileFormat</li>
<li>FirstRowsHasColumnNames  =False</li>
</ol>
</li>
<li>Now double click to configure ZS Generator Output</li>
<li>Right click on Mappings folder node and Add Elements &gt; Select Multiple Columns  &gt; Check columns you like to output</li>
<li>Click OK to Save UI</li>
</ol>
<div id="attachment_6336" style="width: 611px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-csv-generator-output-data-in-batch.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-6336" class="size-full wp-image-6336" src="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-csv-generator-output-data-in-batch.png" alt="Generate CSV data in SSIS (Batch Output Setting)" width="601" height="603" srcset="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-csv-generator-output-data-in-batch.png 601w, https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-csv-generator-output-data-in-batch-150x150.png 150w, https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-csv-generator-output-data-in-batch-300x300.png 300w" sizes="(max-width: 601px) 100vw, 601px" /></a><p id="caption-attachment-6336" class="wp-caption-text">Generate CSV data in SSIS (Batch Output Setting)</p></div>
<h3>Generate unique URL with Batch using Script Component</h3>
<p>Now next task we have to achieve is generate Unique Batch Number. Put that Batch ID in URL like below&#8230;</p><pre class="crayon-plain-tag">http://httpbin.org/post?batch=0
http://httpbin.org/post?batch=1
http://httpbin.org/post?batch=2
.....</pre><p>
<ol>
<li>For this drag SSIS Script Component and select Transformation Mode</li>
<li>Now go to <strong>Inputs and Outputs</strong> tab &gt; Select <strong>Output Columns</strong> &gt; Click <strong>Add Column</strong> &gt; Name it as <strong>URL</strong> &gt; Configure <strong>DataType</strong> as <strong>DT_WSTR</strong> , <strong>Length</strong> = 500</li>
<li>Now got Script Tab and Click Edit. Remove old code and enter following code (Assuming You selected C#). This code will generate new URL with Unique batch ID each time. You can use this same technique to generate Unique row number too (in that case rather than DT_WSTR type you can use DT_I4 type)</p><pre class="crayon-plain-tag">[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
    private static int _batch;
    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
        Row.Url = string.Format("http://httpbin.org/post?batch={0}",_batch);
        //If you have to send GUID rather than Integer for Batch ID then use below code
        //Row.Url = string.Format("http://httpbin.org/post?batch={0}",System.Guid.NewGuid());

        _batch = _batch+1;
    }
}</pre><p>
</li>
<li>Click OK to Save script.</li>
</ol>
<div id="attachment_6334" style="width: 681px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-script-component-unique-row-number-output-new-column.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-6334" class="size-full wp-image-6334" src="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-script-component-unique-row-number-output-new-column.png" alt="Output Unique URL or Number using SSIS Script Transform" width="671" height="768" srcset="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-script-component-unique-row-number-output-new-column.png 671w, https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-script-component-unique-row-number-output-new-column-262x300.png 262w" sizes="(max-width: 671px) 100vw, 671px" /></a><p id="caption-attachment-6334" class="wp-caption-text">Output Unique URL or Number using SSIS Script Transform</p></div>
<h3>Configure Web API Destination to POST CSV Data</h3>
<p>Now final step is to configure SSIS Web API Destination to POST CSV data to API.</p>
<ol>
<li>Drag ZS Web API Destination and connect Source Transform to Web API destination.</li>
<li>Double click to configure</li>
<li>Select Connection Manager</li>
<li>Once connection setup, select Input Column for URL ( This will be same column from Script Transform)</li>
<li>Select column for Body (e.g. ZS_CSV_OUT)</li>
<li>Click OK to save</li>
</ol>
<div id="attachment_6335" style="width: 739px" class="wp-caption alignnone"><a href="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-configure-web-api-destination-post-csv-data-in-batch.png"><img loading="lazy" decoding="async" aria-describedby="caption-attachment-6335" class="size-full wp-image-6335" src="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-configure-web-api-destination-post-csv-data-in-batch.png" alt="POST data to REST API in multiple batches using SSIS Web API destination" width="729" height="764" srcset="https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-configure-web-api-destination-post-csv-data-in-batch.png 729w, https://zappysys.com/blog/wp-content/uploads/2019/02/ssis-configure-web-api-destination-post-csv-data-in-batch-286x300.png 286w" sizes="(max-width: 729px) 100vw, 729px" /></a><p id="caption-attachment-6335" class="wp-caption-text">POST data to REST API in multiple batches using SSIS Web API destination</p></div>
<h2>Debug Web API Requests using Fiddler</h2>
<p>Now we ready to run entire flow. Once you execute data flow, observe Input rows before CSV Generator Transform and after. CSV Generator transform must produce less rows before we now grouping multiple rows in a single batch.</p>
<p>Another important aspect to play with API request is to debug it, We recommend you to to look at <a href="https://zappysys.com/blog/how-to-use-fiddler-to-analyze-http-web-requests/" target="_blank" rel="noopener">this article about using Fiddler to debug web requests</a>.</p>
<h2>Download Sample Package</h2>
<p>Here is the <a href="https://zappysys.com/blog/wp-content/uploads/2019/02/RestAPI_Batch.zip">Sample SSIS Package (2012 format) &#8211; Rest API_Batching</a></p>
<h2>Conclusion</h2>
<p>In this post, we saw how easy it is to handle complex REST API  / CSV /JSON / XML operations in SSIS. We configured REST API POST Operation using Batching Method. Hope this post helps you to achieve your API integration without coding.  Feel free to <a href="https://zappysys.com/products/ssis-powerpack/" target="_blank" rel="noopener">download SSIS PowerPack</a> and try many other components not discussed in this article.</p>
<p>The post <a href="https://zappysys.com/blog/batch-rest-api-requests-ssis-bulk-operation/">How to batch REST API requests in SSIS (Bulk Operation)</a> appeared first on <a href="https://zappysys.com/blog">ZappySys Blog</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
