type Jotform = {
apiKey: string
baseUrl: string
}
export async function main(
resource: Jotform,
formId: string,
reportData: {
title: string
list_type: 'excel' | 'csv' | 'grid' | 'table' | 'calendar' | 'rss' | 'visual'
}
) {
const queryParams = new URLSearchParams({ apiKey: resource.apiKey })
const endpoint = `${resource.baseUrl}/form/${formId}/reports?${queryParams.toString()}`
// Construct the URLSearchParams body
const bodyParams = new URLSearchParams({
title: reportData.title,
list_type: reportData.list_type
})
const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: bodyParams.toString()
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
return data
}
Submitted by hugo697 621 days ago