//native
export type DynSelect_blog_id = string
export async function blog_id(auth: RT.Shopify) {
const response = await fetch(
`https://${auth.store_name}.myshopify.com/admin/api/2026-10/graphql.json`,
{
method: "POST",
headers: {
"X-Shopify-Access-Token": auth.token,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
query: `query { blogs(first: 250, sortKey: TITLE) { nodes { id title } } }`,
}),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { data, errors } = await response.json()
if (errors) {
throw new Error(JSON.stringify(errors))
}
return data.blogs.nodes.map((b: { id: string; title: string }) => ({
value: b.id,
label: b.title,
}))
}
/**
* List Articles
* List blog articles, from one blog or all of them, optionally filtered with Shopify's search syntax (e.g. `tag:news author:Jane published_status:published`). Returns one page; pass pageInfo.endCursor as after for the next. Needs the read_content scope.
*/
export async function main(
auth: RT.Shopify,
blog_id: DynSelect_blog_id | undefined,
query: string | undefined,
sort_key:
| "UPDATED_AT"
| "PUBLISHED_AT"
| "TITLE"
| "AUTHOR"
| "BLOG_TITLE"
| "ID"
| undefined,
reverse: boolean | undefined,
first: number | undefined,
after: string | undefined
) {
const filter = [
blog_id ? `blog_id:${blog_id.split("/").pop()}` : "",
query || "",
]
.filter(Boolean)
.join(" ")
const response = await fetch(
`https://${auth.store_name}.myshopify.com/admin/api/2026-10/graphql.json`,
{
method: "POST",
headers: {
"X-Shopify-Access-Token": auth.token,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
query: `query ($first: Int!, $after: String, $query: String, $sortKey: ArticleSortKeys, $reverse: Boolean) { articles(first: $first, after: $after, query: $query, sortKey: $sortKey, reverse: $reverse) { nodes { id title handle isPublished publishedAt author { name } blog { id title } tags summary image { url altText } createdAt updatedAt } pageInfo { hasNextPage endCursor } } }`,
variables: {
first: first || 50,
after: after || undefined,
query: filter || undefined,
sortKey: sort_key || undefined,
reverse: reverse || undefined,
},
}),
}
)
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
const { data, errors } = await response.json()
if (errors) {
throw new Error(JSON.stringify(errors))
}
return data.articles
}
Submitted by hugo989 3 hours ago