//native
type Telnyx = {
apiKey: string
}
/**
* Create a number reservation
* Creates a Phone Number Reservation for multiple numbers.
*/
export async function main(
auth: Telnyx,
body: {
id?: string
record_type?: string
phone_numbers?: {
id?: string
record_type?: string
phone_number?: string
status?: 'pending' | 'success' | 'failure'
created_at?: string
updated_at?: string
expired_at?: string
}[]
status?: 'pending' | 'success' | 'failure'
customer_reference?: string
created_at?: string
updated_at?: string
}
) {
const url = new URL(`https://api.telnyx.com/v2/number_reservations`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.apiKey
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 428 days ago