type Baremetrics = {
apiKey: string
}
export async function main(
resource: Baremetrics,
sourceId: string,
oid: string,
body: {
name?: string
email?: string
notes?: string
}
) {
if (!body.name && !body.email && !body.notes) {
throw new Error('At least one property (name, email, or notes) is required in the body.')
}
const endpoint = `https://api.baremetrics.com/v1/${sourceId}/customers/${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.customer
}
Submitted by hugo697 87 days ago