0

Create Custom Attribute

by
Published Oct 11, 2024

This endpoint creates a new attribute for a specified target.

Script zixflow Verified

The script

Submitted by hugo697 Bun
Verified 606 days ago
1
//native
2

3
type Zixflow = {
4
	apiKey: string
5
}
6

7
export async function main(
8
	resource: Zixflow,
9
	target: 'collection' | 'list',
10
	targetId: string,
11
	attributeData: {
12
		apiKeyName: string
13
		inputType: string
14
		name: string
15
		config: {
16
			currencyDisplayType?: 'code' | 'name' | 'narrowSymbol' | 'symbol'
17
			currencyCode?: string
18
			recordReference?: Array<string>
19
			aiWizard?: string
20
			dateDisplayType?: string
21
		}
22
		defaultValue?: string
23
		description?: string
24
		isEditable?: boolean
25
		isMultiSelect?: boolean
26
		isRequired?: boolean
27
		isUnique?: boolean
28
		validation?: 'none' | 'email' | 'url' | 'phone' | 'customRegex'
29
	}
30
) {
31
	const endpoint = `https://api.zixflow.com/api/v1/attributes/${target}/${targetId}`
32

33
	const response = await fetch(endpoint, {
34
		method: 'POST',
35
		headers: {
36
			Authorization: `Bearer ${resource.apiKey}`,
37
			'Content-Type': 'application/json'
38
		},
39
		body: JSON.stringify(attributeData)
40
	})
41

42
	if (!response.ok) {
43
		throw new Error(`HTTP error! status: ${response.status}`)
44
	}
45

46
	const data = await response.json()
47

48
	return data
49
}
50