Edits history of script submission #9290 for ' Fetch Badges (motimate)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Motimate = {
    	token: string
    }
    
    export async function main(auth: Motimate, filter_id_: string | undefined) {
    	const url = new URL(`https://motimateapp.com/public_api/badges`)
    
    	for (const [k, v] of [['filter[id]', filter_id_]]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Bearer ' + auth.token
    		}
    	})
    
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    
    	return await response.json()
    }
    

    Submitted by hugo697 581 days ago