0

List Locale Reports

by
Published Oct 17, 2025

List all locale reports for the given project

Script phrase Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Phrase = {
3
	token: string
4
	baseUrl: string
5
}
6
/**
7
 * List Locale Reports
8
 * List all locale reports for the given project
9
 */
10
export async function main(
11
	auth: Phrase,
12
	project_id: string,
13
	page: string | undefined,
14
	per_page: string | undefined,
15
	locale_codes: string | undefined,
16
	tag: string | undefined,
17
	branch: string | undefined
18
) {
19
	const url = new URL(`${auth.baseUrl}/projects/${project_id}/report/locales`)
20
	for (const [k, v] of [
21
		['page', page],
22
		['per_page', per_page],
23
		['locale_codes', locale_codes],
24
		['tag', tag],
25
		['branch', branch]
26
	]) {
27
		if (v !== undefined && v !== '' && k !== undefined) {
28
			url.searchParams.append(k, v)
29
		}
30
	}
31
	const response = await fetch(url, {
32
		method: 'GET',
33
		headers: {
34
			Authorization: 'ApiToken ' + auth.token
35
		},
36
		body: undefined
37
	})
38
	if (!response.ok) {
39
		const text = await response.text()
40
		throw new Error(`${response.status} ${text}`)
41
	}
42
	return await response.json()
43
}
44