Created
December 24, 2022 17:09
-
-
Save magalhini/dd15e889b8c0f09c84227dcff68348b2 to your computer and use it in GitHub Desktop.
Fetch your Revue newsletter issues
This file contains hidden or 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
// Usage: node index.mjs YOUR_API_KEY | |
import fetch from "node-fetch"; | |
import fs from "fs"; | |
async function fetchRevueData(key) { | |
const response = await fetch("https://www.getrevue.co/api/v2/issues", { | |
headers: { | |
Authorization: `Token ${key}`, | |
}, | |
}); | |
console.log("Fetching your newsletter issues..."); | |
const issues = await response.json(); | |
return issues; | |
} | |
const main = async (key) => { | |
if (!key) { | |
console.log( | |
"We need an API key for this: Go to https://www.getrevue.co/app/integrations to request/view your API key." | |
); | |
return; | |
} | |
let data; | |
try { | |
data = await fetchRevueData(key); | |
} catch (e) { | |
throw new Error(`Something went wrong with this import: ${e.message}`); | |
} | |
fs.writeFileSync("revue.json", JSON.stringify(data, null, 2)); | |
console.log("Issues exported successfully in revue.json."); | |
}; | |
main(process.argv[2]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment