Edits history of script submission #8960 for ' Update Plan (baremetrics)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Baremetrics = {
    	apiKey: string
    }
    
    export async function main(
    	resource: Baremetrics,
    	sourceId: string,
    	oid: string,
    	body: {
    		name: string
    	}
    ) {
    	const endpoint = `https://api.baremetrics.com/v1/${sourceId}/plans/${oid}`
    
    	const response = await fetch(endpoint, {
    		method: 'PUT',
    		headers: {
    			'Content-Type': 'application/json',
    			Accept: 'application/json',
    			Authorization: `Bearer ${resource.apiKey}`
    		},
    		body: JSON.stringify(body)
    	})
    
    	if (!response.ok) {
    		throw new Error(`HTTP error! status: ${response.status}`)
    	}
    
    	const data = await response.json()
    
    	return data.plan
    }
    

    Submitted by hugo697 629 days ago