Coded Geekery

BlogWritingAboutContact
BlogWritingAboutContact

Gumroad

Get all sales of a product in dollars.

import fetch from 'isomorphic-unfetch'; export default async (_, res) => { const apiKey = process.env.GUMROAD_API_KEY; const productId = 'sDpG'; const response = await fetch( `https://api.gumroad.com/v2/products/${productId}`, { headers: { Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json' }, method: 'GET' } ); const { product } = await response.json(); const sales = product.sales_usd_cents / 100; return res.status(200).json({ sales }); };

Usage#

  • Create Gumroad Account

  • First, create a Gumroad account. Then, navigate to the Applications tab and create a new app.

  • Save Application Secret

  • Make note of your "Application Secret". Since we're communicating server to server, we only need the secret.

  • Add Environment Variable

  • To securely access the API, we need to include the secret with each request.

    Remember: never commit secrets to git. Thus, we should use an environment variable.

    Not Playing

    Spotify

    Coded Geekery

    TwitterGitHubInstagramgumroadbuymeacoffee

    Stuff

    HomeAbout MeContact Me

    © 2022 Roger Stringer. All rights reserved.