From 59bcbce06d5630e0cdacec28b19da6137201f3fa Mon Sep 17 00:00:00 2001 From: jnorsa-amberscript <117842447+jnorsa-amberscript@users.noreply.github.com> Date: Mon, 6 May 2024 17:11:42 +0200 Subject: [PATCH] Update index.html.md - Modification to use axios in node examples --- source/index.html.md | 231 +++++++++++++++++++++++-------------------- 1 file changed, 125 insertions(+), 106 deletions(-) diff --git a/source/index.html.md b/source/index.html.md index deaa046..af5e394 100644 --- a/source/index.html.md +++ b/source/index.html.md @@ -527,19 +527,20 @@ HttpResponse response=Unirest.post("https://api.amberscript.com/api/jobs ``` ```javascript -var request = require("request"); - -var options = { - method: 'POST', - url: 'https://api.amberscript.com/api/jobs/translatedSubtitles', - qs: {sourceJobId: 'SOURCE_JOB_ID', targetLanguage: 'nl', apiKey: 'YOUR_API_KEY'} -}; +async function createTranslatedSubtitles() { + const sourceJobId = 'SOURCE_JOB_ID'; + const targetLanguage = 'nl'; + const apiKey = 'YOUR_API_KEY'; -request(options, function (error, response, body) { - if (error) throw new Error(error); + const url = `https://api.amberscript.com/api/jobs/translatedSubtitles?sourceJobId=${sourceJobId}&targetLanguage=${targetLanguage}&apiKey=${apiKey}`; - console.log(body); -}); + try { + const response = await axios.post(url, {}, { headers: { 'content-type': 'application/json' } }); + console.log(response.data); + } catch (error) { + console.error('Error:', error.response.data) + } +} ``` ```python @@ -604,17 +605,14 @@ HttpResponse response=Unirest.get("https://api.amberscript.com/api/jobs/ ``` ```javascript -import axios from 'axios'; - -async function createTranslatedSubtitles() { - const sourceJobId = 'SOURCE_JOB_ID'; - const targetLanguage = 'nl'; +async function fetchJobStatus() { + const jobId = '6638de0ba17717297470040c'; const apiKey = 'YOUR_API_KEY'; - const url = `https://api.amberscript.com/api/jobs/translatedSubtitles?sourceJobId=${sourceJobId}&targetLanguage=${targetLanguage}&apiKey=${apiKey}`; + const url = `https://api.amberscript.com/api/jobs/status?jobId=${jobId}&apiKey=${apiKey}`; try { - const response = await axios.post(url, {}, { headers: { 'content-type': 'application/json' } }); + const response = await axios.get(url, { headers: { 'Content-Type': 'application/json' } }); console.log(response.data); } catch (error) { console.error('Error:', error.response.data) @@ -751,11 +749,11 @@ HttpResponse response=Unirest.get("https://api.amberscript.com/api/jobs/ ``` ```javascript -async function exportSTL() { +async function exportSRT() { const jobId = 'JOB_ID'; const apiKey = 'YOUR_API_KEY'; - const url = `https://api.amberscript.com/api/jobs/export-stl?jobId=${jobId}&apiKey=${apiKey}`; + const url = `https://api.amberscript.com/api/jobs/export-srt?jobId=${jobId}&apiKey=${apiKey}`; try { const response = await axios.get(url, { headers: { 'Content-Type': 'application/json' } }); @@ -1084,7 +1082,7 @@ HttpResponse response=Unirest.delete("https://api.amberscript.com/api/jo ```javascript async function deleteJob() { - const jobId = '6638de0ba17717297470040c'; + const jobId = 'JOB_ID'; const apiKey = 'YOUR_API_KEY'; const url = `https://api.amberscript.com/api/jobs?jobId=${jobId}&apiKey=${apiKey}`; @@ -1276,19 +1274,28 @@ HttpResponse response=Unirest.get("https://api.amberscript.com/api/gloss ``` ```javascript -var request = require("request"); +import fetch from 'node-fetch'; -var options = { - method: 'GET', - url: 'https://api.amberscript.com/api/glossary', - qs: {apiKey: 'YOUR_API_KEY'} -}; +async function getGlossary() { + const url = 'https://api.amberscript.com/api/glossary'; + const queryParams = new URLSearchParams({ + apiKey: 'YOUR_API_KEY' + }); -request(options, function (error, response, body) { - if (error) throw new Error(error); + const options = { + method: 'GET', + headers: {'Content-Type': 'application/json'}, + }; + + try { + const response = await fetch(`${url}?${queryParams}`, options); + const data = await response.json(); + console.log(data); + } catch (error) { + console.error('Error:', error.response.data); + } +} - console.log(body); -}); ``` ```python @@ -1395,41 +1402,44 @@ String body="{\n"+ ``` ```javascript -var request = require("request"); - -var body = { - "name": "Name of first glossary", - "names": [ - "Test name one", - "Test name two" - ], - "items": [ - { - "name": "Item one name", - "description": "description of item one" - }, - { - "name": "Item two name", - "description": "description of item two" - } - ] -} +async function createGlossary() { + const url = 'https://api.amberscript.com/api/glossary'; + const body = { + "name": "Name of first glossary", + "names": [ + "Test name one", + "Test name two" + ], + "items": [ + { + "name": "Item one name", + "description": "description of item one" + }, + { + "name": "Item two name", + "description": "description of item two" + } + ] + }; -var options = { - method: 'POST', - url: 'https://api.amberscript.com/api/glossary', - headers: { - 'Content-Type': 'application/json' - }, - qs: {apiKey: 'YOUR_API_KEY'}, - body: body -}; + const options = { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify(body) + }; -request(options, function (error, response, body) { - if (error) throw new Error(error); + const queryParams = new URLSearchParams({ + apiKey: 'YOUR_API_KEY' + }); - console.log(body); -}); + try { + const response = await fetch(`${url}?${queryParams}`, options); + const data = await response.json(); + console.log(data); + } catch (error) { + console.error('Error:', error.response.data); + } +} ``` ```python @@ -1561,41 +1571,44 @@ String body="{\n"+ ``` ```javascript -var request = require("request"); - -var body = { - "name": "Name of first glossary", - "names": [ - "Test name one", - "Test name two" - ], - "items": [ - { - "name": "Item one name", - "description": "description of item one" - }, - { - "name": "Item two name", - "description": "description of item two" - } - ] -} +async function updateGlossary() { + const url = 'https://api.amberscript.com/api/glossary/GLOSSARY_ID'; + const body = { + "name": "Name of first glossary", + "names": [ + "Test name one", + "Test name two" + ], + "items": [ + { + "name": "Item one name", + "description": "description of item one" + }, + { + "name": "Item two name", + "description": "description of item two" + } + ] + }; -var options = { - method: 'PUT', - url: 'https://api.amberscript.com/api/glossary/GLOSSARY_ID', - headers: { - 'Content-Type': 'application/json' - }, - qs: {apiKey: 'YOUR_API_KEY'}, - body: body -}; + const queryParams = new URLSearchParams({ + apiKey: 'YOUR_API_KEY' + }); -request(options, function (error, response, body) { - if (error) throw new Error(error); + const options = { + method: 'PUT', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify(body) + }; - console.log(body); -}); + try { + const response = await fetch(`${url}?${queryParams}`, options); + const data = await response.json(); + console.log(data); + } catch (error) { + console.error('Error:', error.response.data); + } +} ``` ```python @@ -1708,19 +1721,25 @@ HttpResponse response=Unirest.delete("https://api.amberscript.com/api/gl ``` ```javascript -var request = require("request"); - -var options = { - method: 'DELETE', - url: 'https://api.amberscript.com/api/glossary/GLOSSARY_ID', - qs: {apiKey: 'YOUR_API_KEY'} -}; +async function deleteGlossary() { + const url = 'https://api.amberscript.com/api/glossary/6638e42835d0580edd5e35c2'; + const queryParams = new URLSearchParams({ + apiKey: 'YOUR_API_KEY' + }); -request(options, function (error, response, body) { - if (error) throw new Error(error); + const options = { + method: 'DELETE', + headers: {'Content-Type': 'application/json'}, + }; - console.log(body); -}); + try { + const response = await fetch(`${url}?${queryParams}`, options); + const data = await response.text(); + console.log(data); + } catch (error) { + console.error('Error:', error.response.data); + } +} ``` ```python