Created
November 18, 2022 18:24
-
-
Save joelhooks/94b3b25b062868a79b07bb42a0fd8e33 to your computer and use it in GitHub Desktop.
Load subscriber stats from Convertkit via API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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