//native
/**
* List R2 Buckets
* List the R2 buckets in the account. Use the S3 integration with an R2 endpoint to read and write objects.
*/
export async function main(
auth: RT.Cloudflare,
name_contains: string | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/accounts/${auth.account_id}/r2/buckets`
)
if (name_contains != null && name_contains !== "") {
url.searchParams.append("name_contains", name_contains)
}
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 4 hours ago