Edits history of script submission #10571 for ' Get write subtenants count (adhook)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Adhook = {
    	token: string
    }
    
    export async function main(
    	auth: Adhook,
    	mode:
    		| 'CAMPAIGN'
    		| 'POST'
    		| 'CAMPAIGN_GENERATION'
    		| 'POST_GENERATION'
    		| 'POST_TEMPLATE'
    		| 'AD_TEMPLATE'
    		| 'MANAGE'
    		| 'REVIEW'
    		| 'MODERATION'
    		| 'DEFAULT'
    		| undefined,
    	statusFilter: 'ALL' | 'ACTIVE' | 'INACTIVE' | undefined,
    	languageFilter:
    		| 'ALL'
    		| 'DE'
    		| 'FR'
    		| 'EN'
    		| 'IT'
    		| 'ES'
    		| 'PT'
    		| 'NL'
    		| 'SV'
    		| 'RO'
    		| 'CS'
    		| 'EL'
    		| 'TR'
    		| 'PL'
    		| 'DA'
    		| 'EU'
    		| 'CY'
    		| 'CA'
    		| 'HU'
    		| 'SK'
    		| 'SL'
    		| 'SQ'
    		| 'HY'
    		| 'BS'
    		| 'BG'
    		| 'HR'
    		| 'UK'
    		| 'NO'
    		| 'FI'
    		| undefined,
    	q: string | undefined,
    	adhookToken: string
    ) {
    	const url = new URL(`https://app.adhook.io/v1/subtenants/write/count`)
    
    	for (const [k, v] of [
    		['mode', mode],
    		['statusFilter', statusFilter],
    		['languageFilter', languageFilter],
    		['q', q]
    	]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			adhookToken: adhookToken,
    			Authorization: `Bearer ${auth.token}`
    		},
    		body: undefined
    	})
    
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    
    	return await response.json()
    }
    

    Submitted by hugo697 519 days ago