This is a minimal starter kit that integrates with Product Hunt's API V2 via OAuth flow.
node
>=8.15
npm
oryarn
openssl
-
Create an OAuth application via API Dashboard
-
git clone [email protected]:producthunt/producthunt-api.git
-
yarn
ornpm install
-
cp .env.sample .env
. -
Update
PH_APP_API_KEY
&PH_APP_API_SECRET
,PH_APP_REDIRECT_URI
&PH_APP_REQUESTED_SCOPES
values in.env
file. -
Only needed for local development: Generate self-signed certificate to run app on https locally.
openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.cert
-
yarn build
- creates a production ready build of the React app. -
yarn start
- starts the application server on port 3000. -
open
https://localhost:3000
.
-
All requests made by React app to
/graphql
are proxied to the PH API. The user access token is encrypted and stored in the session cookie. -
If your app only requires
public
scope token, you can fetch one using the command below and put it in the.env
file underPH_APP_CLIENT_CREDENTIALS_TOKEN
curl --header "Content-Type: application/json" \
--request POST \
--data '{"client_id":"YOUR_API_KEY_HERE","client_secret":"YOUR_API_SECRET_HERE", "grant_type": "client_credentials"}' \
https://api.producthunt.com/v2/oauth/token
-
Use
ENABLE_HTTPS=true
in.env
file while developing locally. -
Change made to the React app need to be rebuilt every time using
yarn build
. This is not ideal and needs to be migrated to HMR to ease development, PRs for same are appreciated :)
The API supports 3 scopes as of now:
public
- Allows to access public information on Product Hunt.
private
- Allows to access Product Hunt on behalf of the authenticated user. e.g Read goals of the user.
write
- Allows to write data to Product Hunt on behalf of the authenticated user. e.g Mark goals of user as complete/incomplete.
Useful Links:
-
Documentation: https://api.producthunt.com/v2/docs
-
GraphQL Reference: http://api-v2-docs.producthunt.com.s3-website-us-east-1.amazonaws.com/operation/query/.
-
API Explorer: https://ph-graph-api-explorer.herokuapp.com/(uses GraphiQL).
For feedback, requests and bugs please visit: https://github.com/producthunt/producthunt-api/issues
Happy Hacking!