Paypal API data in Google Sheets

How to connect PayPal REST API to Google Sheets

PayPal is a well-known online payments processor that enables money transfers for companies and regular users alike.

Paypal’s API enables users to create apps that interact with their accounts, automating operations that pertain to billing, invoicing, orders, payments and many other elements.

In this tutorial, you will learn how to connect the PayPal REST API to Google Sheets in 5 steps:

  1. Install the Apipheny Add-on
  2. Create a Paypal Live App
  3. Get a Paypal Access Token
  4. Enter Paypal API into Apipheny
  5. Run the Paypal API request

Step 1: Install the Apipheny Add-on for Google Sheets

To pull data from the PayPal REST API to Google Sheets, you’ll first have to install and open the Apipheny Google Sheets add-on.

Apipheny is a no-code API integrator that can make GET and POST requests using almost any JSON or CSV API, and comes with a suite of other spreadsheet-centric features. There’s a 30 day free trial then it’s $29/month or $19/month if you purchase the annual plan. Learn more about Apipheny on the homepage.

Some advantages to using Apipheny over another platform are the ability to use any endpoint an API has instead of relying on pre-built integrations, as well as other API and spreadsheet specific features, and the ability to connect to almost any other data source and create custom blends of data.

You can install Apipheny in the G Suite Marketplace and get a 30 day trial by opening the following link and then clicking the Install button on the next page:

https://gsuite.google.com/marketplace/app/apipheny/966163326746
Install Apipheny
Install Apipheny

After you’ve installed Apipheny, open a Google Sheet and then click “Add-Ons” in the menu.

In the menu, click Apipheny and then after accepting the permissions, click Import API. The Apipheny sidebar will then open on the right side of the Google Sheet:

Open Apipheny
Open Apipheny

Step 2: Create a PayPal Live App

To use the PayPal REST API, you have to create a dedicated app in your Paypal account. You can create either a sandbox app, used for testing, or a live app that uses the actual information in your account.

In this tutorial we will use a live app, to show you how you can import actual live information from Paypal into your Google Sheets. Here’s the steps:

1.) Log in to your PayPal Developer Dashboard, using the same log in information as your Paypal account. If you don’t yet have a Paypal account, you can create one by clicking on the Sign Up button:

Log in to Paypal Developer Account
Log in to Paypal Developer Account

2.) Once logged in, click on My Apps & Credentials and toggle the switch to the Live option, to start creating a live app (Paypal may prompt you to upgrade your account to a business account):

Toggle the switch to "Live"
Toggle the switch to “Live”

3.) After clicking “Live”, scroll down, and in the REST API apps section, click Create App. Then type a name for your app and then click Create App again:

Create New App - Paypal API
Create New App – Paypal API

4.) Your new app’s details page will open and display the app’s identifying information. Copy and save the Client ID and Secret for your app somewhere safe and get ready to use them in the next step.

Client ID and Secret Code you will need in the next step

5.) Review your app’s information and for the purposes of this example, make sure that the Transaction Search option is checked, before saving your app:

Enable Transaction Search
Enable Transaction Search

Step 3: Get your Paypal API Access Token

In order to access most PayPal REST API endpoints, you will need an access token. To obtain an access token, you’ll either need to do a cURL command or use the Postman app.

Click here for instructions on using the Postman app.

Here’s the instruction for cURL:

To make a cURL command, pass your OAuth 2.0 credentials through a dedicated PayPal REST API command, using the cURL command line tool:

add your client ID and secret from the previous step

Use the same values for Client ID and for Secret that you copied in the previous step, into the <client_id> and <secret> placeholders you see above.

You can also use other command-line tools besides cURL, but for those, you’ll have to set the Accept header to application/x-www-form-urlencoded instead of application/json.

In response to this command, the PayPal authorization server will return your access token in the access_token field of the JSON result:

access token you will need in the next step

Copy the access token somewhere safe because you will need it in the next step.

Note: This JSON result also contains an expires_in field, containing the number of seconds after which your newly-retrieved access token expires. For instance, access tokens with a value of 3600 in the expires_ field will expire in one hour from the time the response was generated, meaning you will need to get a new access token if it’s been longer than an hour.

Step 4: Enter your PayPal API URL into the Apipheny Add-on

Back in the Google Sheet, at the top of Apipheny add-on, select your HTTP method (GET or POST) as required by your API endpoint. For this example we are using GET.

Next, enter your URL for a PayPal REST API endpoint into the Apipheny add-on, where it says API URL Path, followed by any GET parameters required for your query.

Here’s a list of available Paypal API parameters you can use.

For this example, we will use the Transaction Search API to get your PayPal account’s transaction history. This example URL uses the GET HTTP method and includes a number of parameters: start_date, end_date, fields, page_size and page.

https://api.paypal.com/v1/reporting/transactions?start_date=2020-03-10T00:00:00-0700&end_date=2020-03-24T23:59:59-0700&fields=all&page_size=100&page=1

See the screenshot below to see the URL in Apipheny.

After you enter the API URL into Apipheny, we’re going to enter some keys and values into the Headers section.

In the headers section in Apipheny, you should have two rows with the following keys and values:

Key 1:
Content-Type
Value 1:
application/json
Key 2:
Authorization
Value 2:
Bearer your-access-token

It doesn’t matter what order the headers are entered. “your-access-token” is the value from the access_token field in the JSON response you obtained in Step 3. Enter the access token after “Bearer”, with a space between “Bearer” and the token (see screenshot below).

The Content-Type and Authorization headers are also required, so you should add them as their own header:

Paypal API URL and 2 headers with access token entered in Apipheny app

Step 5: Click “Run” to query the Paypal API in Google Sheets

Click the Run button at the bottom of the Apipheny sidebar and then wait for the Paypal API data to be retrieved and added in to your Google spreadsheet, like this:

Paypal API data in Google Sheets
Paypal API data in Google Sheets

In this example, we got our Paypal transaction history data in Google Sheets by using the Apipheny add-on.

Take it a step further

Now that you know how to query the Paypal API, try using different parameters in your Paypal API URL. Click here to see a list of available parameters.

Keep in mind that the access token you obtained expires after an hour, so you’ll need to get a new access token if it’s been more than an hour.

You could also try using one of the more advance features in the Apipheny add-on, such as:

  • Save your API request
  • Make a POST request to the Paypal API
  • Use the custom =APIPHENY() function to call the API request in your sheet
  • Create an API request by referencing the value of a cell in the API URL, headers, or POST body (with three curly braces eg. {{{Sheet1!A1}}})

Related articles:

Related Posts

Leave a Comment