How to extract data from Discord and import it into Google Sheets using the Discord API

Discord is a popular chat app, much like Slack. In this tutorial, I’ll show you how to connect the Discord API to Google Sheets in 7 steps:

  1. Install the Apipheny Add-on
  2. Create a Discord App
  3. Obtain your Discord Code
  4. Obtain a Bearer Access Token
  5. Choose your Endpoint URL
  6. Enter Discord API into Apipheny
  7. Run the Discord API request

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

To pull data from the Discord API to Google Sheets easily and without writing any code, first install and open the Apipheny Google Sheets add-on.

Apipheny is a no-code API integrator for Google Sheets that you can use to make unlimited API requests, connect to unlimited APIs (including the Discord API), save API requests, schedule API requests, and more. Click here if you want to learn more about Apipheny.

1. Install Apipheny by clicking the Install button on this page.

Install the Apipheny add-on
Install the Apipheny add-on

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

Open Apipheny add-on
Open Apipheny add-on

Step 2.) Create a Discord App

Go to https://discord.com/developers/applications and click the New Application button:

New Discord Application
New Discord Application

In the Create an application popup, complete the Name field and then click the Create button:

Create an application
Create an application

Your app will then be created and the client id and secret will be displayed on the screen:

Discord app client ID and secret
Discord app client ID and secret

Click the Copy button and then paste these values to a safe location, because you will need the ID and client secret in the following steps.

In the OAuth2 section, add a redirect URI by clicking the Add Redirect button:

Add redirect
Add redirect

Complete the Redirects field with any valid URL and then save the changes by clicking the Save Changes button:

Create redirect
Create redirect

Step 3.) Obtain a Discord code

Go to the following link into your browser: https://discordapp.com/api/oauth2/authorize?response_type=code&client_id=&scope=identify%20guilds.join&state=15773059ghq9183habn&redirect_uri=&prompt=consent

Don’t forget to replace your_client_id and your_redirect_uri values with the ones you obtained in Step 2 above.

Then you’ll be asked to authorize the action. Click the Authorize button:

Authorize the app
Authorize the app

You’ll then be redirected to your redirect URL. At the end of the URL, you’ll find the required code:

Copy the value after the “code“ parameter to a safe location, because you’ll need it later.

Step 4.) Obtain a Bearer Access Token

In your console window, enter the following command:

curl -X POST "https://discordapp.com/api/oauth2/token" --data "client_id=<your_client_id>" --data "client_secret=<your_client_secret> " --data "grant_type=authorization_code" --data "code=<your_code>" --data "redirect_uri=<redirect_URI> " --data "scope=identify"

Don’t forget to replace these values:

 <your_code> is the code you previously obtained in Step 3.

<your_client_id> is your client id from Step 2.

<your_client_secret> is your client secret from Step 2.

<redirect_URI> is your redirect URI from Step 2.

For the scope parameter, you should add any scopes that your requests need, separated by commas.

Your Bearer access token will then be displayed in the response:

Copy and paste your Bearer access token to a safe location because you’ll need it later.

Step 5.) Choose your endpoint URL

In this section, we’ll show you how to browse the Discord API documentation to find an API endpoint URL that retrieves the information you need. If you already know your endpoint URL, or you want to use the same example URL as us, just skip to Step 6.

First, open the Discord API documentation page: https://discord.com/developers/docs/reference

The menu on the left contains a list of categorized endpoints for the Discord API:

Discord API endpoints
Discord API endpoints

In this case, we’ll use the Invite category, which contains two endpoints: Get invite and Delete invite.

Invite API documentation
Invite API documentation

An example endpoint is the Get invite endpoint, which returns an invite object for the given code:

https://discordapp.com/api/v6/invites/{invite.code}

The documentation for this endpoint contains the HTTP method used (GET) and the request path, a short description of the endpoint’s purpose and a table describing the accepted parameters:

Get Invite and Delete Invite documentation
Get Invite and Delete Invite documentation

All API calls to Discord should be made to the https://discordapp.com/api/v6/ base domain.

Discord API base/root URL:

https://discordapp.com/api/v6/

Step 6.) Enter the Discord API URL Into Apipheny

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) required by your API endpoint. For this example, we are using the GET method.

API URL: In Step 5, we explained how you can find the Discord API endpoint that you need. Now copy the complete 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 current user endpoint that returns the current user. The corresponding URL is:

https://discordapp.com/api/v6/users/@me

Headers: In the Headers section, add one row with the following key and value:

Key:
Authorization
Value:
Bearer <your_token>

Where <your_token> value is the token you generated previously, in Step 4. There should be a space between Bearer and <your_token>. Do not include the carrots “<>”.

Discord API request entered into Apipheny
Discord API request entered into Apipheny

Step 7.) Run the Discord API Request

Lastly, click the Run button at the bottom of the Apipheny add-on and then wait for the Discord API data to be pulled in to your Google Sheet:

Discord API data in Google Sheets
Discord API data in Google Sheets

After making a successful request to the Discord API, try querying a different endpoint, or try using one of the more advanced features in the Apipheny add-on.

If you want to integrate your Discord API 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 API add-on demo

Related articles:

Related Posts

Leave a Comment