Edits history of script submission #9044 for ' Delete Field (datocms)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Datocms = {
    	apiKey: string
    }
    
    export async function main(resource: Datocms, fieldId: string) {
    	const endpoint = `https://site-api.datocms.com/fields/${fieldId}`
    
    	const response = await fetch(endpoint, {
    		method: 'DELETE',
    		headers: {
    			Authorization: `Bearer ${resource.apiKey}`,
    			Accept: 'application/json',
    			'X-Api-Version': '3'
    		}
    	})
    
    	if (!response.ok) {
    		throw new Error(`HTTP error! status: ${response.status}`)
    	}
    
    	const data = await response.json()
    
    	return data
    }
    

    Submitted by hugo697 621 days ago