Edits history of script submission #9103 for ' Retrieve Collection Records (zixflow)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    type Zixflow = {
    	apiKey: string
    }
    
    export async function main(
    	resource: Zixflow,
    	collectionId: string,
    	options?: {
    		filter?: Array<Record<string, any>>
    		sort?: Array<Record<string, any>>
    		limit?: number
    		offset?: number
    	}
    ) {
    	const endpoint = `https://api.zixflow.com/api/v1/collection-records/${collectionId}/query`
    
    	const body: Record<string, any> = {}
    
    	if (options?.filter) {
    		body.filter = options.filter
    	}
    
    	if (options?.sort) {
    		body.sort = options.sort
    	}
    
    	if (options?.limit) {
    		body.limit = options.limit
    	}
    
    	if (options?.offset) {
    		body.offset = options.offset
    	}
    
    	const response = await fetch(endpoint, {
    		method: 'POST',
    		headers: {
    			Authorization: `Bearer ${resource.apiKey}`,
    			'Content-Type': 'application/json'
    		},
    		body: JSON.stringify(body)
    	})
    
    	if (!response.ok) {
    		throw new Error(`HTTP error! status: ${response.status}`)
    	}
    
    	const data = await response.json()
    
    	return data
    }
    

    Submitted by hugo697 606 days ago