How to read PayPal API data in SSIS

Introduction

PayPalIn this article, we will see how to read PayPal API data in SSIS and load into SQL Server. This blog mainly focuses on SSIS approach but steps mentioned to call PayPal APIs can be useful for any developer regardless of which programming language or tool set you use. We will also see How to send basic Authorization header along with body in OAuth2.

We will go through the steps to read data from PayPal Transactions and Load into MS SQL Server.

In nutshell, this post will focus on how to make PayPal API Call using SSIS.

 

Prerequisites

Before we perform the steps listed in this article, you will need to make sure the following prerequisites are met:

  1. SSIS designer installed. Sometimes it is referred to as BIDS or SSDT (download it from Microsoft site).
  2. Basic knowledge of SSIS package development using Microsoft SQL Server Integration Services.
  3. Make sure ZappySys SSIS PowerPack is installed (download it).
  4. Credentials of PayPal API. Click here to create API.

What is PayPal?

PayPal is an American company operating a worldwide online payments system that supports online money transfers and serves as an electronic alternative to traditional paper methods like checks and money orders. The company operates as a payment processor for online vendors, auction sites, and many other commercial users, for which it charges a fee in exchange for benefits such as one-click transactions and password memory. PayPal’s payment system, also called PayPal, is considered a type of payment rail.

Get Started with PayPal API

If you have need to automate PayPal operations (e.g. read / write / update / delete ) then you can use PayPal REST API. Before you can integrate a PayPal product or solution, you must set up your development environment to get OAuth 2.0 client ID and secret credentials for the sandbox and live environments. You exchange these credentials for an access token that authorizes your REST API calls. To test your web and mobile apps, you create sandbox accounts.

Get PayPal credentials

To generate OAuth 2.0 credentials for the sandbox and live environments:

  1. Log into Dashboard and type your PayPal personal or business account email and password.
  2. In the REST API apps section, click Create App. The purpose of this app is to generate your credentials.
  3. Type a name for your app and click Create App. The page shows your sandbox app information, which includes your credentials.

    Note: To show your live app information, toggle to Live.

  4. Copy and save the client ID and secret for your sandbox app.
    PayPal Client ID and Secret

    PayPal Client ID and Secret

  5. Review your app details and save your app.

Read PayPal API Data using SSIS JSON Source

Let’s start with an example. We use SSIS JSON Source component to make the call to PayPal API, we will read PayPal data and load into SQL Server. First of All, Open Visual Studio and Create New SSIS Package Project.

In REST API calls, include the URL to the API service for the environment:

  • Sandbox: https://api.sandbox.paypal.com
  • Live: https://api.paypal.com

Create Basic OAuth Client Credentials Grant (Configure ZS-OAuth Connection)

To get API response data using SOAP / REST API call, you need to get an API Token from your token request URL. Follow the steps mentioned below to get API Token:

  1. Now, Right Click on Connection Managers Window, and one Context menu appears for creating a new connection manager.
    Connection Manager Window: Create New Connection

    Connection Manager Window: Create New Connection

  2. Select ZS-OAuth Connection Manager from the list of Connection Managers and, double-click on it or click on Add button to add a new Connection Manager. By Default, The created connection manager is of Package-Level. You can set Project Level Connection manager too If you want.
    SSIS Connection Maangers List: Select O-AUTH Connection Manager

    SSIS Connection Mangers List: Select O-AUTH Connection Manager

  3. In the SSIS ZS OAuth Connection Manager, Select Provider as Custom, select version as OAuth2 and select Grant Type as  Client Credentials Grant. Enter the credentials and access token url and test the connection.
     
    ZS OAuth Connection – Client Credentials Grant

    ZS OAuth Connection – Client Credentials Grant

  4. Click on OK button to save OAuth Connection configure settings.

That’s it we have successfully configured Connection for PayPal API in SSIS. In the next section, we will see how to use this connection and read various data from PayPal API.

Read PayPal API Data in SSIS

Once we have done creating HTTP Connection Manager we can move forward to read PayPal API data inside Data Flow. So lets Configure SSIS JSON / REST API Source.

  1. First of All, Drag and drop Data Flow Task from SSIS Toolbox and double click it to edit.
    Drag and Drop SSIS Data Flow Task from SSIS Toolbox

    Drag and Drop : SSIS Data Flow Task from SSIS Toolbox

  2. From the SSIS toolbox drag and drop JSON Source on the dataflow designer surface.
    Drag and Drop JSON Source Component

    Drag and Drop JSON Source Component

  3. Double click JSON Source and enter the following URL as below to get invoices and select that created OAuth Connection.
    SSIS JSON Source

    SSIS JSON Source

  4. Now Go to Pagination tab select mode as Url Parameter and add indicator as page  and Add the increment value same as page_size  value we set in url, there for in our case we set 100. For pagination call please click here for reference to this link.
    PayPal Pagination

    PayPal Pagination

  5. Select the desire Array Filter and click on preview.
    PayPal Preview

    PayPal Preview

  6. That’s it, you are ready to load PayPal API Data into SQL Server.

Load PayPal API data into SQL Server

Now let's look at how to load data into target like SQL Server, Oracle or Flat File. In below example we will see loading data into SQL Server database but steps may remain same for other targets which can be accessed using OLEDB Drivers (e.g. Oracle).
  1. Inside Data Flow, Drag and drop Upsert Destination Component from SSIS Toolbox
  2. Connect our Source component to Upsert Destination
  3. Double click Upsert Destination to configure it
  4. Select Target Connection or click NEW to create new connectionConfigure SSIS Upsert Destination Connection - Loading data (REST / SOAP / JSON / XML /CSV) into SQL Server or other target using SSIS Configure SSIS Upsert Destination Connection - Loading data (REST / SOAP / JSON / XML /CSV) into SQL Server or other target using SSIS
  5. Select Target Table or click NEW to create new table based on source columns
  6. Click on Mappings Tab to Auto map columns by name. You can change mappings as you need SSIS Upsert Destination - Columns Mappings SSIS Upsert Destination - Columns Mappings
  7. Click OK to Save Upsert Destination Settings
  8. That's it, You are now ready to run data flow. NOTE: If you wish to debug data flow and see records when you run, add data viewer by right click on blue arrow > Click Enable Data Viewer
  9. To execute data flow, Right click anywhere inside Data Flow Surface and click Execute Task
 

Conclusion

After all, we saw you how to extract information from REST API such as PayPal REST API using HTTP Connection and load into SQL Server. We also learned techniques like How to get Dynamic Token using HTTP Connection. To explore many other scenarios not discussed in this article download SSIS PowerPack from here (includes 70+ Components).

References

Finally, you can use the following links for more information:

Posted in REST API, REST API Integration, SSIS JSON Source (File/REST), SSIS Logging Task and tagged , , , , .