Edits history of script submission #9094 for ' Create Custom Attribute (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,
    	target: 'collection' | 'list',
    	targetId: string,
    	attributeData: {
    		apiKeyName: string
    		inputType: string
    		name: string
    		config: {
    			currencyDisplayType?: 'code' | 'name' | 'narrowSymbol' | 'symbol'
    			currencyCode?: string
    			recordReference?: Array<string>
    			aiWizard?: string
    			dateDisplayType?: string
    		}
    		defaultValue?: string
    		description?: string
    		isEditable?: boolean
    		isMultiSelect?: boolean
    		isRequired?: boolean
    		isUnique?: boolean
    		validation?: 'none' | 'email' | 'url' | 'phone' | 'customRegex'
    	}
    ) {
    	const endpoint = `https://api.zixflow.com/api/v1/attributes/${target}/${targetId}`
    
    	const response = await fetch(endpoint, {
    		method: 'POST',
    		headers: {
    			Authorization: `Bearer ${resource.apiKey}`,
    			'Content-Type': 'application/json'
    		},
    		body: JSON.stringify(attributeData)
    	})
    
    	if (!response.ok) {
    		throw new Error(`HTTP error! status: ${response.status}`)
    	}
    
    	const data = await response.json()
    
    	return data
    }
    

    Submitted by hugo697 606 days ago