Skip to content

Instantly share code, notes, and snippets.

@joelhooks
Created November 18, 2022 18:24
Show Gist options
  • Save joelhooks/94b3b25b062868a79b07bb42a0fd8e33 to your computer and use it in GitHub Desktop.
Save joelhooks/94b3b25b062868a79b07bb42a0fd8e33 to your computer and use it in GitHub Desktop.
Load subscriber stats from Convertkit via API
// Name: ck stats for site
// Snippet: ;ck
import "@johnlindquist/kit"
const sites = [
{
name: "Some Account",
ck_secret: await env("SOME_ACCOUNT_CK_SECRET"),
}
]
// load subscriber count from convertkit api
async function loadSubscriberCount(apiSecret: string): Promise<number> {
const url = `https://api.convertkit.com/v3/subscribers?api_secret=${apiSecret}`;
const response = await fetch(url).then(response => {
return response.json();
})
return response.total_subscribers;
}
let report = `* [[active partner products]]\n\n`
for (let index = 0; index < sites.length; index++) {
const site = sites[index];
const siteSubscriberCount = await loadSubscriberCount(site.ck_secret);
report += ` * [[${site.name}]]\n
* convertkit subscribers:: ${siteSubscriberCount}\n\n`;
}
copy(report);
// let html = await highlight(report)
// await div(html)
await setSelectedText(report)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment