Edits history of script submission #8998 for ' Create Contact (campayn)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Campayn = {
    	apiKey: string
    }
    
    export async function main(
    	resource: Campayn,
    	listId: string,
    	body: {
    		email: string
    		first_name?: string
    		last_name?: string
    		title?: string
    		address?: string
    		city?: string
    		state?: string
    		zip?: string
    		company?: string
    		country?: string
    	}
    ) {
    	const endpoint = `https://campayn.com/api/v1/lists/${listId}/contacts.json`
    
    	const response = await fetch(endpoint, {
    		method: 'POST',
    		headers: {
    			Authorization: `TRUEREST apikey=${resource.apiKey}`
    		},
    		body: JSON.stringify(body)
    	})
    
    	if (!response.ok) {
    		throw new Error(`HTTP error! status: ${response.status}`)
    	}
    
    	const data = await response.json()
    
    	return data
    }
    

    Submitted by hugo697 652 days ago