How to import Reddit Ads data into Google Sheets using the Reddit Ads API

In my last post, I showed you how to integrate the Reddit API with Google Sheets.

In this tutorial, I’ll show you how to connect the Reddit Ads API to Google Sheets in 6 steps:

  1. Install the Apipheny Add-on
  2. Create a Reddit API App
  3. Obtain Reddit API Access & Refresh Tokens
  4. Choose your Reddit API Endpoint
  5. Enter Reddit Ads API request into Apipheny
  6. Run the Reddit Ads API request

Note: the Reddit Ads API is available only for whitelisted accounts. To be whitelisted to access the Reddit Ads API, contact your Reddit sales representative. If you don’t have a Reddit sales rep but want to request one, contact their sales team by clicking the “Advertising at Scale” button on this page.

Step 1.) Install and open the Apipheny Add-on in Google Sheets

To pull data from the Reddit Ads API to Google Sheets without any coding, you’ll first have to install and open the Apipheny Google Sheets add-on.

Apipheny is a Google Sheets API add-on that you can use to make unlimited API requests, connect to unlimited APIs, save your API requests, schedule API requests, and more. Click here for more information about Apipheny. There’s a 30-day free trial included, then there’s annual and monthly plans available starting at $19/month.

1. To install Apipheny, go to the following link on desktop and click the Install button on the page: https://gsuite.google.com/marketplace/app/apipheny/966163326746

Install the Apipheny add-on in the G Suite Marketplace
Install the Apipheny add-on in the G Suite Marketplace

2. After you’ve installed Apipheny, open a Google Sheet and then click on Add-Ons option in the menu at the top. In the add-ons dropdown menu, you should see Apipheny. Click Apipheny > Import API to open the Apipheny add-on in your Google Sheet.

Open the Apipheny add-on in your Google Sheets
Open the Apipheny add-on in your Google Sheets

Step 2.) Create a Reddit API App

To create an “app” that’s able to access the Reddit Ads API, first go to https://www.reddit.com/prefs/apps/ and click the “are you a developer? create an app” button:

Create an app for the Reddit Ads API
Create an app for the Reddit Ads API

On the next page:

  • fill in the application name
  • choose the script type for your app
  • add a short optional description
  • add a redirect URL

Then after filling in those fields, click the create app button:

Fill in the app details and then click "create app"
Fill in the app details and then click “create app”

You can use any valid link as the redirect URL, including https://apipheny.io/

Your app will then be created:

Reddit API apps dashboard
Reddit API apps dashboard

On the dashboard for your new app, you will see the app ID and secret. Copy these values to a safe location because you will need them in the upcoming steps.

Step 3.) Obtain Reddit API Access and Refresh Tokens

Next, give your developer application access to your account by visiting this URL in your browser: https://www.reddit.com/api/v1/authorize?client_id=CLIENT_ID&response_type=code&state=RANDOM_STRING&redirect_uri=REDIRECT_URL&duration=DURATION&scope=SCOPE_STRING

On that page, replace the various identifiers with the following values:

  • CLIENT_ID – This should be the client ID that you obtained earlier, while creating your developer application
  • RANDOM_STRING – This can be any random string, it will end up being passed to your redirect URL in the following steps
  • REDIRECT_URL – This must be the redirect URL that you entered while creating your developer application
  • DURATION – You should set this to “permanent”. It’s also valid to set it to “temporary”, but in this case, your access token will only be valid for one hour and you will not be able to refresh it
  • SCOPE_STRING – This is a comma separated list of scopes that you want your access token to have. These scopes dictate which actions may be performed with the access token. Each endpoint’s documentation lists the scopes required by that endpoint. You may set this “adsread,history” if you would like your token to access everything in the ads API.

After filling in those details, click the “Allow” button:

Connecting a Reddit Developer App with a Reddit Account
Connecting a Reddit Developer App with a Reddit Account

You will now then be redirected to the redirect URL that you provided earlier. Two query parameters (state and code) will be added in your browser’s address bar, as parameters of this redirect URL. The code parameter is a single use login code that we will now use to acquire a refreshable access token:

Redirect URL with added parameters
Redirect URL with added parameters

Next, open up a terminal and compose the following curl command:

 curl -X POST https://www.reddit.com/api/v1/access_token \\
   -H 'content-type: application/x-www-form-urlencoded' \\
   -A 'CLIENT_NAME' \\
   -u CLIENT_ID:APP_SECRET \\
   -d 'grant_type=authorization_code&code=CODE&redirect_uri=REDIRECT_URL'

You’ll need to fill in a few parts:

  • CLIENT_NAME – This should be the name of the application using the access token
  • CLIENT_ID – This should be the client ID that you obtained earlier, while creating your developer application
  • APP_SECRET – This should be the application secret, that you obtained earlier while creating your developer application
  • CODE – This should be the value of the code query parameter from the previous step
  • REDIRECT_URL – This must be the redirect URL that you entered while creating your developer application
curl command

The response access_token may be used in order to access the ads API for up to one hour. The refresh_token may be used to get a new access token when that hour is up. Refreshing the access token can be done with the following command:

 curl -X POST https://www.reddit.com/api/v1/access_token \\
   -A 'CLIENT_NAME' \\
   -u CLIENT_ID:APP_SECRET \\
   -d 'grant_type=refresh_token&refresh_token=REFRESH_TOKEN'
command to refresh the access token
command to refresh the access token

CLIENT_NAME, CLIENT_ID and APP_SECRET are the same as described before. REFRESH_TOKEN should be replaced with the value of the refresh_token field from the previous command’s response.

Step 4.) Choose a Reddit API Endpoint URL

In this section, I’ll show you how to browse the Reddit Ads API documentation to find an API endpoint URL that retrieves the specific information you need from your Reddit Ads account. If you already know your API URL, or you want to use the same example URL as us, just skip to Step 5.

First, open the Reddit Ads API documentation page: https://ads-api.reddit.com/docs/

The menu on the left contains general information about Reddit Ads and a list of grouped API endpoints:

Reddit Ads API Endpoints
Reddit Ads API Endpoints

An example endpoint group is Ad Groups. This endpoint group contains two endpoints: Get all groups belonging to an advertiser and Get an ad group by ID.

In this case, we will describe the Get an ad group by ID endpoint, that retrieves an ad group by its ID:

https://ads-api.reddit.com/api/v2.0/accounts/{account_id}/ad_groups/{ad_group_id}

The documentation for this endpoint contains a short description of the endpoint’s purpose, the authorizations used by the endpoint, the accepted path parameters, and the responses it can return:

Get an ad group by ID endpoint
Get an ad group by ID endpoint documentation

All API calls to the Reddit Ads API should be made using the https://ads-api.reddit.com/api/v2.0 base domain. All endpoints and parameters would be appended to this base domain.

Reddit Ads API base domain/root URL:
https://ads-api.reddit.com/api/v2.0

Step 5.) Enter the Reddit Ads API Request into the Apipheny add-on

Okay, we’re in the home stretch. Now go back to your Google Sheet and make sure that the Apipheny add-on is open on the “Import” tab. With the Import Tab open, enter these details into the add-on:

Method: At the top of the Apipheny sidebar, select the HTTP method (GET or POST) as required by your Reddit Ads API endpoint. For this example, we are using the GET method.

API URL: In Step 4, I explained how you can find the Reddit Ads API endpoint that you need. Now copy the complete API URL into the Apipheny add-on, where it says API URL Path (JSON / CSV), followed by any GET parameters required for your query.

For this example, we are using the Get an account by ID endpoint, that gets information about an account by its ID. The corresponding URL for this endpoint is:

https://ads-api.reddit.com/api/v2.0/accounts/{account_id}

The {account_id} parameter in this API URL is the account ID that is obtained by accessing the following link in your browser: https://www.reddit.com/user/{your_username}/about.json

Replace {your_username} with your Reddit username. Do not include the brackets “{}” around any of the values.

In the Headers of the Apipheny add-on section, add two rows, with the following keys and values:

Header 1
Key:
Content-Type
Value:
application/json
Header 2
Key:
Authorization
Value:
Bearer <your_token>

You can copy the first header exactly. In the second header, <your_token> is the value of the token you obtained previously, in Step 3. There should be a literal space between Bearer and <your_token>. Do not include the carrots “<>” around your token.

Reddit Ads API Request Entered into the Apipheny Google Sheets add-on
Reddit Ads API Request Entered into the Apipheny Google Sheets add-on

Step 6.) Run the Reddit Ads API Request in your Google Sheets

The last step is to click the Run button at the bottom of the Apipheny add-on and then your Reddit Ads data will be imported into your Google Sheet.

Reddit Ads data imported into my Google Sheet using the Apipheny add-on
Reddit Ads data imported into my Google Sheet using the Apipheny add-on

After making a successful request to the Reddit Ads API, try querying a different Reddit Ads API endpoint, or try using one of the more advanced features in the Apipheny add-on, such as:

  • Save and schedule your Reddit Ads API request
  • Make a POST request to the Reddit Ads API (if available)
  • Use the custom =APIPHENY() function to call the Reddit Ads API request inside your spreadsheet
  • Create an API request by referencing the value of a cell in the API URL with three curly braces eg. {{{Sheet1!A1}}}

If you want to integrate your Reddit Ads data with Google Data Studio, just follow the same steps above and then connect your Google Sheet to your Google Data Studio report.

Apipheny Google Sheets add-on Demo

Related Articles:

Related Posts

Leave a Comment