type Freshdesk = {
apiKey: string
baseUrl: string
}
export async function main(resource: Freshdesk, contactId: string) {
// Remove trailing slash from base URL
const baseUrl = resource.baseUrl.replace(/\/$/, '')
// Construct the URL for the API request
const url = `${baseUrl}/api/v2/contacts/${contactId}`
// Base64 encode the API key with a colon and 'X'
const encodedKey = btoa(`${resource.apiKey}:X`)
// Make the API request
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: `Basic ${encodedKey}`,
'Content-Type': 'application/json'
}
})
// Handle the response
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
// Parse and return the response data
const data = await response.json()
return data
}
Submitted by hugo697 652 days ago