Created
April 20, 2022 16:18
-
-
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.
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
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