//native
/**
* List Blog Posts
* List blog posts, optionally filtered by creation/update date (ISO 8601). Requires the content scope.
*/
export async function main(
auth: RT.Hubspot,
limit: number | undefined,
after: string | undefined,
created_after: string | undefined,
created_before: string | undefined,
updated_after: string | undefined,
updated_before: string | undefined,
archived: boolean | undefined,
sort: string | undefined
) {
const url = new URL(`https://api.hubapi.com/cms/v3/blogs/posts`)
if (limit != null) url.searchParams.append("limit", String(limit))
if (after != null && after !== "") url.searchParams.append("after", after)
if (created_after != null && created_after !== "")
url.searchParams.append("createdAfter", created_after)
if (created_before != null && created_before !== "")
url.searchParams.append("createdBefore", created_before)
if (updated_after != null && updated_after !== "")
url.searchParams.append("updatedAfter", updated_after)
if (updated_before != null && updated_before !== "")
url.searchParams.append("updatedBefore", updated_before)
if (archived) url.searchParams.append("archived", String(archived))
if (sort != null && sort !== "") url.searchParams.append("sort", sort)
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${auth.token}`,
Accept: "application/json",
},
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 5 hours ago