jsjoeio / speak-argentinian-spanish

speak argentinian spanish website
https://speakargentinianspanish.com/
1 stars 0 forks source link

Figure out Beehiiv API #11

Closed jsjoeio closed 1 year ago

jsjoeio commented 1 year ago

Link: https://developers.beehiiv.com/docs/v2/1f82a0eaf9b68-create

Worried that if I integrate this while I'm on the free trial, it won't work after that's up 🤔 Not sure though so may need to reach out to support and ask.

jsjoeio commented 1 year ago

For the font stuff, maybe this will work: https://stackoverflow.com/a/25963902/3015595

More:

jsjoeio commented 1 year ago

There are two tasks to be completed here. I will write them both out and how to achieve them:

Get total count of subscribers

Using the Beehiiv API, get the total count of subscribers

  1. add new environment variable called BEEHIIV_API_KEY (add to Vercel too). This can be found here
  2. Update src/pages/getWaitlistTotal.json.ts to use Beehiiv's API. Example:
const url = 'https://api.beehiiv.com/v2/publications/pub_6fcf5bfc-5793-49e6-b6b2-abcf322a6fd7/subscriptions?status=active&tier=all&limit=1';
const options = {
  method: 'GET',
  headers: {
    Accept: 'application/json',
    Authorization: `Bearer ${BEEHIIV_API_KEY}`
  }
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}

The response will look something like this:

{
  "data": [
    {}
  ],
  "page": 1,
  "limit": 1,
  "total_results": 2,
  "total_pages": 2
}

All we need is total_results.

Add subscriber to list

It will be similar to the above but for src/pages/updateWaitlistTotal.json.ts and we'll do this in src/components/CTA.tsx. We'll need to update the frontend to not submit the form but instead:

jsjoeio commented 1 year ago

Spoke to Beehiiv Team and they said they're down to extend my API access even after my free trial expires so this approach will work :D