Edits history of script submission #8941 for ' Create a Group (mailerlite)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Mailerlite = {
    	apiToken: string
    }
    
    export async function main(resource: Mailerlite, name: string) {
    	const endpoint = `https://connect.mailerlite.com/api/groups`
    
    	const body = { name }
    
    	const response = await fetch(endpoint, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Accept: 'application/json',
    			Authorization: `Bearer ${resource.apiToken}`
    		},
    		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