Edits history of script submission #9531 for ' Link Tariff to Location (enode)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Enode = {
    	token: string
    }
    
    export async function main(
    	auth: Enode,
    	locationId: string,
    	body: {
    		tariffId: string
    		tariffIntervals: {
    			name: string
    			weekdays?: 0 | 1 | 2 | 3 | 4 | 5 | 6[]
    			from: string
    			to: string
    		}[]
    	}
    ) {
    	const url = new URL(`https://enode-api.production.enode.io/locations/${locationId}/tariff`)
    
    	const response = await fetch(url, {
    		method: 'PUT',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.token
    		},
    		body: JSON.stringify(body)
    	})
    
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    
    	return await response.text()
    }
    

    Submitted by hugo697 581 days ago