Get PayPal Access Token in Google Sheets

Get PayPal Access Token in Google Sheets

Last Updated On August 26, 2019

Paypal is probably the best-known online payments system, and, founded in the late ’90s, certainly the longest-running. However their APIs are clunky and convoluted, especially in comparison to newer competitors like Stripe. This guide will help navigate the first step of getting started: retrieving the Paypal Access Token, which is required for making requests from their REST API. We’ll pull it into Google Sheets, using the free API Connector add-on.

PART 1: GET YOUR PAYPAL CREDENTIALS

  1. Navigate to Paypal’s Apps & Credentials page (https://developer.paypal.com/developer/applications). Click ‘Log into Dashboard’ if you aren’t already logged into your account. You will need to sign up if you don’t already have a developer account. paypal-img1

  2. Once you’re logged in, you’ll see a page containing a default application, with the option to create a new one. Click Create App to set up a new application. This will allow us to receive the credentials we need for querying the Paypal API.
    paypal-img2

  3. Give your app a name. It can be anything, but we’ll call it ‘Google Sheets’. Click Create App.
    paypal-img3

  4. You’ll now see values for the Sandbox account email, the Client ID, and the Secret. Keep these handy as we’ll need them in a minute.
    paypal-img4
  5. Note that we’re using the Sandbox values for this demo. To access your actual account transactions, you can toggle the button at top from Sandbox to Live (some features available only for Business accounts).

PART 2: GET YOUR PAYPAL ACCESS TOKEN

  1. Paypal requires that we encode the above credentials to base 64, and then exchange them for an access token. To encode these credentials, open up Developer Tools in your browser (F12 on Windows/Linux or option + ⌘ + J on OSX). In the console, type in the following and click enter:

  2. You’ll need to substitute in your own user credentials, like this (don’t forget the colon in the middle):
    paypal-img5
    (If you have any problems with the above, you can also try a tool like Basic Authentication Header Generator to generate your header.) Copy the entire encoded string to your clipboard as we’ll need it in a moment.

  3. Open up Google Sheets and click Add-ons > API Connector > Create New API Request.
  4. In the Create Request interface, choose POST and enter the following values:
    • API URL path:https://api.sandbox.paypal.com/v1/oauth2/token
    • Headers: (Note that ‘Basic {encoded value}’ refers to the value retrieved just above in step 1)
      Authorization Basic {encoded value}
    • Post Body:

    All together, it will look like this:
    paypal-img6

  5. Create a new sheet. You can call it anything but we’ll call it PaypalToken. Click Set to set this sheet to receive the output from your request.
  6. Name and save your request. Click Run and you’ll see your Paypal access token printed onto your sheet.
    paypal-img7

    Congrats, you now have your Access Token!

    PART 3: NOTES AND EXPANSIONS

    1. You can use your Paypal access token to make requests, but note that the ‘expires_in’ field contains the number of seconds until the token expires. In this case, it will last 9 hours, after which you will need to generate a new token. Unfortunately this prevents API Connector from accessing real-time refreshed Paypal data in Sheets.
    2. With that said, if you just want to pull Paypal data into Sheets at some infrequent interval, you can use the Access Token to do so, refreshing as needed. Enter your API URL into the API URL field, and enter the following headers, replacing {access token} with your Access Token:
      Authorization Bearer {access token}
      Content-Type application/json

      This will produce a result as follows:
      paypal-img8

    3. Paypal doesn’t provide any straightforward method to retrieve a list of all transactions. However, based on the documentation, the API URL to retrieve a list of completed payments made through the REST API is https://api.paypal.com/v1/payments/payment?count=10&start_index=0&sort_by=update_time&sort_order=desc. Please try it out and leave a comment if it works for you!

Comments:0

Leave a Reply

Your email address will not be published.