Skip to content

Instantly share code, notes, and snippets.

@cfjedimaster
Last active July 16, 2025 21:19
Show Gist options
  • Save cfjedimaster/058ef68b34cba357494567ceb98c3a80 to your computer and use it in GitHub Desktop.
Save cfjedimaster/058ef68b34cba357494567ceb98c3a80 to your computer and use it in GitHub Desktop.
if(!server.system.environment.keyExists('AGENTQL_API_KEY')) {
println('Set the AGENTQL_API_KEY value in your environment please.');
abort;
}
AGENTQL_API_KEY = server.system.environment.AGENTQL_API_KEY;
function agentQL(key, url, query) {
body = {
query: query,
url:blog
}
bx:http url="https://api.agentql.com/v1/query-data" method="post" result="result" {
bx:httpparam type="header" name="X-API-Key" value="#key#";
bx:httpparam type="header" name="Content-Type" value="application/json";
bx:httpparam type="body" value="#body.toJSON()#";
}
return result.fileContent.fromJSON();
}
blog = 'https://www.raymondcamden.com';
// The AgentQL query of the data to be extracted
query = "
{
blogposts[] {
url
title
date
}
}
";
// First, get our blog posts
data = agentQL(AGENTQL_API_KEY, blog, query).data.blogposts;
println("Fetched #data.len()# posts, now converting to Markdown");
bx:saveContent variable="md" {
```
# Blog Posts from <bx:output>#blog#</bx:output>
<bx:loop index="b" array="#data#">
* <bx:output>[#b.title#](#b.url#) (Posted #b.date#)</bx:output>
</bx:loop>
```
};
html = markdown(md);
// Email this - or just save it...
fileWrite('blog.html', html);
println('Done and saved to blog.html');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment