type Baremetrics = {
apiKey: string
}
export async function main(
resource: Baremetrics,
sourceId: string,
params?: {
customer_oid?: string
order?: 'asc' | 'desc'
page?: number
per_page?: number
}
) {
const queryParams = new URLSearchParams()
if (params?.customer_oid) {
queryParams.append('customer_oid', params.customer_oid)
}
if (params?.order) {
queryParams.append('order', params.order)
}
if (params?.page) {
queryParams.append('page', params.page.toString())
}
if (params?.per_page) {
queryParams.append('per_page', params.per_page.toString())
}
const endpoint = `https://api.baremetrics.com/v1/${sourceId}/subscriptions?${queryParams.toString()}`
const response = await fetch(endpoint, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: `Bearer ${resource.apiKey}`
}
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
return data
}
Submitted by hugo697 123 days ago