0

Query an object

by
Published Oct 17, 2025

Queries an object for filtered data.

Script sage_intacct Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type SageIntacct = {
3
	token: string
4
}
5
/**
6
 * Query an object
7
 * Queries an object for filtered data.
8
 */
9
export async function main(
10
	auth: SageIntacct,
11
	body: {
12
		object?: string
13
		fields?: string[]
14
		filters?:
15
			| { $eq?: {} }
16
			| { $ne?: {} }
17
			| { $lt?: {} }
18
			| { $lte?: {} }
19
			| { $gt?: {} }
20
			| { $gte?: {} }
21
			| { $in?: {} }
22
			| { $notIn?: {} }
23
			| { $between?: {} }
24
			| { $notBetween?: {} }
25
			| { $contains?: {} }
26
			| { $notContains?: {} }
27
			| { $startsWith?: {} }
28
			| { $notStartsWith?: {} }
29
			| { $endsWith?: {} }
30
			| { $notEndsWith?: {} }[]
31
		filterExpression?: string
32
		filterParameters?: {
33
			asOfDate?: string
34
			includeHierarchyFields?: false | true
35
			caseSensitiveComparison?: false | true
36
			includePrivate?: false | true
37
		}
38
		orderBy?: {}[]
39
		start?: number
40
		size?: number
41
	}
42
) {
43
	const url = new URL(`https://api.intacct.com/ia/api/v1/services/core/query`)
44

45
	const response = await fetch(url, {
46
		method: 'POST',
47
		headers: {
48
			'Content-Type': 'application/json',
49
			Authorization: 'Bearer ' + auth.token
50
		},
51
		body: JSON.stringify(body)
52
	})
53
	if (!response.ok) {
54
		const text = await response.text()
55
		throw new Error(`${response.status} ${text}`)
56
	}
57
	return await response.json()
58
}
59