ghostguild-org/server/api/helcim/subscriptions.get.js

41 lines
No EOL
1.1 KiB
JavaScript

// Get existing Helcim subscriptions to understand the format
const HELCIM_API_BASE = 'https://api.helcim.com/v2'
export default defineEventHandler(async (event) => {
try {
await requireAdmin(event)
const config = useRuntimeConfig(event)
const helcimToken = config.helcimApiToken
const response = await fetch(`${HELCIM_API_BASE}/subscriptions`, {
method: 'GET',
headers: {
'accept': 'application/json',
'api-token': helcimToken
}
})
if (!response.ok) {
console.error('Failed to fetch subscriptions:', response.status, response.statusText)
throw createError({
statusCode: response.status,
statusMessage: 'Failed to fetch subscriptions'
})
}
const subscriptionsData = await response.json()
return {
success: true,
subscriptions: subscriptionsData
}
} catch (error) {
if (error.statusCode) throw error
console.error('Error fetching Helcim subscriptions:', error)
throw createError({
statusCode: 500,
statusMessage: 'An unexpected error occurred'
})
}
})