0

Check Document Status

by
Published Apr 8, 2025

Retrieve the current status of a document translation process. If the translation is still in progress, the estimated time remaining is also included in the response.

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
 * Check Document Status
8
 * Retrieve the current status of a document translation process.
9
If the translation is still in progress, the estimated time remaining is also included in the response.
10
 */
11
export async function main(
12
  auth: Deepl,
13
  document_id: string,
14
  body: { document_key: string },
15
) {
16
  const url = new URL(`${auth.baseUrl}/v2/document/${document_id}`);
17

18
  const response = await fetch(url, {
19
    method: "POST",
20
    headers: {
21
      "Content-Type": "application/json",
22
      Authorization: "DeepL-Auth-Key " + auth.apiKey,
23
    },
24
    body: JSON.stringify(body),
25
  });
26
  if (!response.ok) {
27
    const text = await response.text();
28
    throw new Error(`${response.status} ${text}`);
29
  }
30
  return await response.json();
31
}
32