Introduction
In this article, we will guide you through the steps to download and save a file from a REST API JSON response containing binary content using SQL Server Integration Services (SSIS). This process involves using the REST API Task to retrieve the binary content from the JSON response and the Logging Task to save the content to a file.
Prerequisites
Ensure you have the following installed:
- SQL Server Data Tools (SSDT): Install SQL Server Data Tools, the development tool for SSIS.
- ZappySys SSIS PowerPack: Download and install the ZappySys SSIS PowerPack.
- Access to the REST API that returns the binary content in a JSON response.
Steps to Download and Save the File
-
Set Up SSIS Package
- Create a new SSIS package in SQL Server Data Tools (SSDT).
-
Add REST API Task
- Drag and drop a REST API Task onto the Control Flow design surface.
-
Configure REST API Task
- Double-click the REST API Task to configure it.
- In the Request tab, set up your API request URL, method, and any necessary headers or parameters.
- In the Response tab, configure the settings to store the binary content in an SSIS variable.
Example JSON Path for Binary Content:
- Assume the JSON response looks like this:
{ "d": { "GetPDF": { "BillingDocumentBinary": "<binary-content>" } } }
- Use the JSON path
$.d.GetPDF.BillingDocumentBinary
to extract the binary content.
-
Create SSIS Variable for Binary Content
- Create an SSIS variable (e.g.,
User::BinaryContent
) to store the binary content retrieved by the REST API Task. - In the Response Settings tab of the REST API Task, map the JSON path to the SSIS variable
User::BinaryContent
.
- Create an SSIS variable (e.g.,
-
Add ZS Logging Task
- Drag and drop a ZS Logging Task onto the Control Flow design surface.
-
Configure ZS Logging Task
- Double-click the ZS Logging Task to configure it.
- In the Expression tab, use the
FUN_FILE_WRITE_BINARY
placeholder function to save the binary content to a file.
Example Expression:
<<D:\demo.png|~||~|True,FUN_FILE_WRITE_BINARY>>
- Replace
<your-local-folder-path>
with the path where you want to save the file (e.g.,C:\\Files
).
-
Connect the Tasks
- Connect the REST API Task to the ZS Logging Task using a precedence constraint.
-
Test and Execute the Package
- Save and execute the SSIS package.
- Verify that the file is downloaded and saved to the specified local folder.
Sample Screenshots
Below are the sample screenshots of the REST API Task and Logging Task configurations to provide visual guidance.
Conclusion
By following these steps, you can successfully download and save a file from a REST API JSON response with binary content using SSIS. This setup allows you to automate the process of retrieving and saving binary files from API responses, enhancing your data integration workflows.