Skip to content

Instantly share code, notes, and snippets.

@joeworkman
Created April 20, 2022 16:18
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 joeworkman/fa3ef1ff5f76ddb71726a330a6e4d030 to your computer and use it in GitHub Desktop.
Save joeworkman/fa3ef1ff5f76ddb71726a330a6e4d030 to your computer and use it in GitHub Desktop.
This will parse through the posts in a Total CMS blog and randomly return one. This was made to help with automations in Zapier.
const url = 'https://sandbox.joeworkman.net/cms-data/blog/store/_blog.json';
const res = await fetch(url);
const json = await res.text();
const posts = Object.values(JSON.parse(json).post).filter(post => !post.draft);
const winner = posts[Math.floor(Math.random()*posts.length)];
return winner;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment