Edits history of script submission #8996 for ' Get Tickets (freshdesk)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Freshdesk = {
    	apiKey: string
    	baseUrl: string
    }
    
    export async function main(resource: Freshdesk) {
    	// Remove the trailing slash from base URL.
    	const baseUrl = resource.baseUrl.replace(/\/$/, '')
    	const endpoint = `${baseUrl}/api/v2/tickets/`
    
    	// Base64 encode the API key with a colon and 'X'
    	const encodedKey = btoa(`${resource.apiKey}:X`)
    
    	const response = await fetch(endpoint, {
    		method: 'GET',
    		headers: {
    			Authorization: `Basic ${encodedKey}`,
    			'Content-Type': 'application/json'
    		}
    	})
    
    	if (!response.ok) {
    		throw new Error(`HTTP error! status: ${response.status}`)
    	}
    
    	const data = await response.json()
    
    	return data
    }
    

    Submitted by hugo697 652 days ago