0

Retrieve Glossary Entries

by
Published Apr 8, 2025

List the entries of a single glossary in the format specified by the `Accept` header.

Script deepl Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Deepl = {
3
  apiKey: string;
4
  baseUrl: string;
5
};
6
/**
7
 * Retrieve Glossary Entries
8
 * List the entries of a single glossary in the format specified by the `Accept` header.
9
 */
10
export async function main(auth: Deepl, glossary_id: string, Accept: string) {
11
  const url = new URL(
12
    `${auth.baseUrl}/v2/glossaries/${glossary_id}/entries`,
13
  );
14

15
  const response = await fetch(url, {
16
    method: "GET",
17
    headers: {
18
      Accept: Accept,
19
      Authorization: "DeepL-Auth-Key " + auth.apiKey,
20
    },
21
    body: undefined,
22
  });
23
  if (!response.ok) {
24
    const text = await response.text();
25
    throw new Error(`${response.status} ${text}`);
26
  }
27
  return await response.text();
28
}
29