0

Download Translated Document

by
Published Apr 8, 2025

Once the status of the document translation process is `done`, the result can be downloaded. For privacy reasons the translated document is automatically removed from the server once it was downloaded and cannot be downloaded again.

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
 * Download Translated Document
8
 * Once the status of the document translation process is `done`, the result can be downloaded.
9

10

11
For privacy reasons the translated document is automatically removed from the server once it was downloaded and cannot be downloaded again.
12
 */
13
export async function main(
14
  auth: Deepl,
15
  document_id: string,
16
  body: { document_key: string },
17
) {
18
  const url = new URL(
19
    `${auth.baseUrl}/v2/document/${document_id}/result`,
20
  );
21

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