How to Make PayPal API Call in ODBC / SQL Server (T-SQL)


PayPalIn our previous article we saw how to call PayPal API in SSIS. Now in this article, we will see How to Make PayPal API Call in ODBC from the SQL Server. This blog mainly focuses on ODBC approach but steps mentioned to call PayPal APIs can be useful for any developer regardless of which 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 Create PayPal Order from MS SQL Server.

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



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

  1. A first requirement, make sure that Microsoft Access installed
  2. Make sure to have ZappySys ODBC PowerPack installed.
  3. 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.

Call PayPal Create Order API in SQL Server (T-SQL) using Data Gateway

Let’s start with an example. We use JSON Driver to make the call to PayPal API, we will Create the PayPal Order from SQL Server.

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

  • Sandbox:
  • Live:
  1. To do this, first of all, we will open the ZappySys Data Gateway Configuration:
    Open ZappySys Data Gateway

    Open ZappySys Data Gateway

  2. Add the Native – ZappySys JSON Driver Data source.
    Add Gateway Data Source (Native JSON Driver)

    Add Gateway Data Source (Native JSON Driver)

  3. Now it’s time to connect with PayPal. Let’s use JSON Driver Data source with the following URL:
    PayPal : Create Order

    PayPal : Create Order

  4. Create Basic OAuth Client Credentials Grant (Configure ZS-OAuth Connection).
    In the SSIS ZS OAuth Connection Manager, Select Provider as Custom, select version as OAuth2 and select Grant Type as  Client Credentials Grant. Enter the credentials and access token url and click OK.
    ZS OAuth Connection – Client Credentials Grant

    ZS OAuth Connection – Client Credentials Grant

  5. Furthermore, Now click on Test Connection button to test PayPal Connection.
    PayPal : Test Connection

    PayPal : Test Connection

  6. Write your Query and Preview Data.
  7. (Optional Step) If your Query use POST method (e.g. Create Invoice) to submit data then you have Save Metadata (Read More). We will use this meta file in later step when we call POST request.
    Generate Metadata File for REST API POST Operation using ZappySys API Driver (JSON / XML)

    Generate Metadata File for REST API POST Operation using ZappySys API Driver (JSON / XML)

  8. Now using Code Generator we will generate the query.

    Generate Query

Setup Linked Server in MS SQL Server for PayPal

Once you configured the data source in Gateway, we can now setup Linked Server in SQL Server to query API Calls.

  1. Assuming you have installed SQL Server and SSMS. If not then get both for FREE from here: Get SQL Server Express and  Get SSMS
  2. Open SSMS and connect to SQL Server.
  3. Go to Root > Server Objects > Linked Servers node. Right click and click New Linked Server…

    Add Linked Server in SQL Server

    Add Linked Server in SQL Server

  4.  Now enter the linked server name, select Provider as SQL Native Client
  5. Enter data source as  GatewayServerName, PORT_NUMBER 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 > General tab in case its different.
  6. Enter Catalog Name. This must match name from Data gateway Data sources grid > Name column

    Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection

    Configure Linked Server Provider, Catalog, Server, Port for ZappySys Data Gateway Connection

  7. Click on Security Tab and select last option “Be made using this security context“. Enter your gateway user account here.
  8. Click OK to save Linked Server

Create Order in PayPal from SQL Server (Call POST API Method)

  1. To Create Order in PayPal we need to execute the query like this. Please refer to this link for more information: Create Order example.
    Important Note*: Below query uses META property (fully explained here). This is needed if you creating anew record using POST, PUT. If you don’t pass META='{xxxx}’ in query driver calls REST API two times (first time to parse metadata and second time to get actual data). So that you find some odd thing in PayPal if you execute the query without Meta then you will find two same Orders created in your PayPal as the driver makes two calls as mentioned above.
  2. Here is the preview after you run REST API query in SQL Server. It will return created Order Id, Links and status. Notice that you can override default configuration by supplying many parameters in WITH clause.
    Create Order In PayPal Using SQL Query

    Create Order In PayPal Using SQL Query

  3. You can also find this created Order by opening that URL in the browser.
    Created Order In PayPal

    Created Order In PayPal

PayPal API integration in ODBC apps (e.g. Power BI, Excel, Informatica, Access, C#…)

So far we have looked at SQL Server integration only, but what if you like to use same powerful ZappySys API drivers part of ODBC PowerPack in other Apps like Power BI, Excel, MS Access, Informatica and many more… ?? Well not to worry if you know that App supports ODBC you can use ZappySys ODBC Driver same way described earlier… only difference is you dont need Linked Server and you dont have to use OPENQUERY statement when you use ODBC Drivers.

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.   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#,, PHP. PowerShell

BI / Reporting Tools Integration

ETL Tools Integration Programming Languages Integration


So in this blog, we learned how to generate a PayPal API Token, Load PayPal data in MS SQL Server table using ODBC JSON / REST API Driver in a very simple way. You can achieve many more functionalities with this tool. Check our blogs/articles on JSON / REST API Driver to find out what this tool is capable of more.


Finally, you can use the following links for more information about the use of PayPal API with our tools:

Posted in JSON File / REST API Driver, T-SQL (SQL Server) and tagged , , , .