type Convertkit = {
apiSecret: string
}
export async function main(
resource: Convertkit,
formId: string,
filter?: {
page?: number
sortOrder?: 'asc' | 'desc'
subscriberState?: 'active' | 'cancelled'
}
) {
// Construct the query parameters.
const queryParams = new URLSearchParams({
api_secret: resource.apiSecret
})
// Add optional filters to the query parameters.
if (filter?.page) queryParams.append('page', filter.page.toString())
if (filter?.sortOrder) queryParams.append('sort_order', filter.sortOrder)
const endpoint = `https://api.convertkit.com/v3/forms/${formId}/subscriptions?${queryParams.toString()}`
const response = await fetch(endpoint, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
return data
}
Submitted by hugo697 81 days ago