Edits history of script submission #10579 for ' Search promotions (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,
    	filter: string | undefined,
    	skip: string | undefined,
    	limit: string | undefined,
    	start: string | undefined,
    	end: string | undefined,
    	subtenantId: string | undefined,
    	groupId: string | undefined,
    	tagIds: string | undefined,
    	topicIds: string | undefined,
    	channels: string | undefined,
    	promotionStatus:
    		| 'ALL'
    		| 'DRAFT'
    		| 'PLANNED'
    		| 'IN_PROGRESS'
    		| 'STOPPED'
    		| 'IN_REVIEW'
    		| 'COMPLETED'
    		| undefined,
    	promotionType:
    		| 'ALL'
    		| 'TRAFFIC'
    		| 'CONVERSIONS'
    		| 'RETARGETING'
    		| 'SHOPPING'
    		| 'APP'
    		| 'ENGAGEMENT'
    		| 'VIDEO_VIEWS'
    		| 'CALLS'
    		| 'REACH'
    		| 'FOLLOWERS'
    		| 'PROFILE_VIEWS'
    		| 'LEADS'
    		| 'PERFORMANCE_MAX'
    		| undefined,
    	orderKey: string | undefined,
    	reverseOrder: string | undefined,
    	adhookToken: string
    ) {
    	const url = new URL(`https://app.adhook.io/v1/promotions`)
    
    	for (const [k, v] of [
    		['filter', filter],
    		['skip', skip],
    		['limit', limit],
    		['start', start],
    		['end', end],
    		['subtenantId', subtenantId],
    		['groupId', groupId],
    		['tagIds', tagIds],
    		['topicIds', topicIds],
    		['channels', channels],
    		['promotionStatus', promotionStatus],
    		['promotionType', promotionType],
    		['orderKey', orderKey],
    		['reverseOrder', reverseOrder]
    	]) {
    		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