type Baremetrics = {
apiKey: string
}
export async function main(
resource: Baremetrics,
sourceId: string,
oid: string,
body: {
plan_oid: string
occurred_at?: number
quantity?: number
discount?: number
addons?: {
oid: string
amount: number
quantity: number
}[]
}
) {
const endpoint = `https://api.baremetrics.com/v1/${sourceId}/subscriptions/${oid}`
const response = await fetch(endpoint, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: `Bearer ${resource.apiKey}`
},
body: JSON.stringify(body)
})
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const data = await response.json()
return data.event
}
Submitted by hugo697 118 days ago