From d979f99267759c8a6a62b9155e42ac1f74f6a4b4 Mon Sep 17 00:00:00 2001 From: ttsukagoshi Date: Wed, 21 Feb 2024 01:30:45 +0900 Subject: [PATCH] Refactor `deepLGetLanguages()` --- src/sheetsl.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/sheetsl.ts b/src/sheetsl.ts index 2632c22..ddb00bc 100644 --- a/src/sheetsl.ts +++ b/src/sheetsl.ts @@ -499,10 +499,13 @@ export function deepLGetLanguages( const apiKey = getDeepLApiKey(); const baseUrl = getDeepLApiBaseUrl(apiKey); // Call the DeepL API - const url = baseUrl + endpoint + `?auth_key=${apiKey}&type=${type}`; - const response = handleDeepLErrors( - UrlFetchApp.fetch(url, { muteHttpExceptions: true }), - ); + const url = baseUrl + endpoint + `?type=${type}`; + const options: GoogleAppsScript.URL_Fetch.URLFetchRequestOptions = { + method: 'get', + headers: { Authorization: `DeepL-Auth-Key ${apiKey}` }, + muteHttpExceptions: true, + }; + const response = handleDeepLErrors(UrlFetchApp.fetch(url, options)); return JSON.parse(response.getContentText()) as DeepLSupportedLanguages[]; }