API Connector Documentation
Import Product Hunt Data to Google Sheets
In this guide, we’ll walk through how to pull data from the Product Hunt API directly into Google Sheets, using the API Connector add-on for Sheets.
We'll first get an API key from Product Hunt, and then set up a request to pull in the most popular products from Product Hunt to your spreadsheet.
This article will focus on the original v1 REST API since it enables us to automatically loop through paginated results. However we'll also provide an example for the newer v2 GraphQL API.
Contents
- Before You Begin
- Part 1: Get your Product Hunt API Key
- Part 2: Pull Product Hunt API Data into Sheets
- Part 3: Handle Pagination
- Part 4: Variation - Use GraphQL
- Part 5: API Documentation
Before You Begin
Click here to install the API Connector add-on from the Google Marketplace.
Part 1: Get Your Product Hunt API Key
- Log in to Product Hunt and hover over your profile pic to open the Account drop-down menu. Click API Dashboard (or click here to go there directly).
- This page will prompt you to create a new application. Enter a name and a URL, and click Create Application (for our purposes, the exact values don't matter)
- You'll now see a page listing some API tokens. Scroll to the bottom and click Create token to create a token that never expires.
- Once you click Create Token, you'll see a Token. Copy this as we'll need it shortly. Congrats, you're now ready to get started pulling data out of Product Hunt's API.
Part 2: Pull Product Hunt API Data into Sheets
For this example, we'll fetch the most upvoted posts in a month. Where it says YOUR_DEV_TOKEN
, substitute in your own developer token.
- Open up Google Sheets and click Extensions > API Connector > Open > Create request.
- In the request form enter the following:
- Application:
Custom
- Method:
GET
- Request URL:
https://api.producthunt.com/v1/posts/all?sort_by=votes_count&order=desc&search[featured_month]=5&search[featured_year]=2022
- Headers:
Authorization
:Bearer YOUR_DEV_TOKEN
- Report style:
grid
. This is optional, but will reduce the number of distinct columns.
- Application:
- Create a new tab and click Set current to use that tab as your data destination.
- Name your request and click Run. A moment later you’ll see the most upvoted Product Hunt posts populate your Google Sheet:
Part 3: Handle Pagination
By default, Product Hunt's API will only show 50 records at a time.
To get more, use the page/per_page parameters as described here.
You can append these manually or use API Connector's automated paginated handling to cycle through and fetch pages automatically, like this:
- URL: same as above, including the per_page=50 parameter
- Pagination:
page parameter
- Page parameter:
page
- Run until: choose when to stop fetching data
Part 4: Variation - Use GraphQL
Product Hunt's v2 API uses the GraphQL query language to pull API data. Unlike the v1 Rest API, this means you can pull all your API data in a single request. You can check the documentation for information on what fields are available, but the below steps provide a full example of a working query.
- To use GraphQL with the Product Hunt API, create your GraphQL query. It should look something like this:
{ posts { edges { node { id name description votesCount website thumbnail { url } media { videoUrl type url } } } } }
- Enter that entire query into a single cell, like this:
- Encode the entire cell by entering
=encodeURL(A1)
into cell A3. - When you work with GraphQL APIs, you add your encoded GraphQL request to a “query” query string (documentation). So, assuming your sheet is called GraphQL, your entire request URL will look like this:
https://api.producthunt.com/v2/api/graphql?query=+++GraphQL!A3+++
- Choose POST method and enter this URL into API Connector:
- We can't have an empty POST body, so just enter
{}
into the POST body section. - Create a new tab called PH GraphQL and click 'Set current' to use that tab as your data destination.
- Name your request and click Run. A moment later you’ll see the results of your GraphQL query populate your sheet.
Part 5: API Documentation
Official V1 documentation: https://api.producthunt.com/v1/docs
Official V2 documentation: http://api-v2-docs.producthunt.com.s3-website-us-east-1.amazonaws.com/operation/query/