Skip to content

Instantly share code, notes, and snippets.

@magalhini
Created December 24, 2022 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magalhini/dd15e889b8c0f09c84227dcff68348b2 to your computer and use it in GitHub Desktop.
Save magalhini/dd15e889b8c0f09c84227dcff68348b2 to your computer and use it in GitHub Desktop.
Fetch your Revue newsletter issues
// 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