Skip to content

Commit 049413c

Browse files
Update index.html.md - axios
1 parent fa985bb commit 049413c

File tree

1 file changed

+143
-120
lines changed

1 file changed

+143
-120
lines changed

source/index.html.md

Lines changed: 143 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -147,28 +147,42 @@ HttpResponse<String> response=Unirest.post("https://api.amberscript.com/api/jobs
147147
```
148148

149149
```javascript
150-
const request = require('request');
151-
const fs = require('fs');
152-
153-
let options = {
154-
method: 'POST',
155-
url: 'https://api.amberscript.com/api/jobs/upload-media',
156-
qs: {
157-
apiKey: 'YOUR_API_KEY',
158-
transcriptionType: 'transcription',
159-
jobType: 'direct',
160-
language: 'nl',
161-
numberOfSpeakers: '2'
162-
},
163-
headers: {'content-type': 'multipart/form-data'},
164-
formData: {file: fs.createReadStream("./path/to/my_file.mp3")}
165-
};
166-
167-
request(options, function (error, response, body) {
168-
if (error) throw new Error(error);
150+
import axios from 'axios';
151+
import FormData from 'form-data';
152+
import fs from 'fs';
153+
154+
async function uploadMedia() {
155+
const apiKey = 'YOUR_API_KEY';
156+
const transcriptionType = 'transcription';
157+
const jobType = 'perfect';
158+
const language = 'nl';
159+
const numberOfSpeakers = '2';
160+
161+
const formData = new FormData();
162+
formData.append('file', fs.createReadStream('./path/to/my_file.mp3'));
163+
164+
const url = 'https://api.amberscript.com/api/jobs/upload-media';
165+
const queryString = new URLSearchParams({
166+
apiKey,
167+
transcriptionType,
168+
jobType,
169+
language,
170+
numberOfSpeakers
171+
}).toString();
172+
173+
const options = {
174+
headers: {
175+
...formData.getHeaders()
176+
}
177+
};
169178

170-
console.log(body);
171-
});
179+
try {
180+
const response = await axios.post(`${url}?${queryString}`, formData, options);
181+
console.log(response.data);
182+
} catch (error) {
183+
console.error('Error:', error.response.data)
184+
}
185+
}
172186
```
173187

174188
```python
@@ -333,30 +347,37 @@ HttpResponse<String> response=Unirest.post("https://api.amberscript.com/api/jobs
333347
```
334348
335349
```javascript
336-
const request = require('request');
337-
const fs = require('fs');
338-
339-
let options = {
340-
method: 'POST',
341-
url: 'https://api.amberscript.com/api/jobs/upload-media-from-url',
342-
qs: {
343-
apiKey: 'YOUR_API_KEY'
344-
},
345-
body: {
346-
"sourceUrl": "https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4",
347-
"transcriptionType": "transcription",
348-
"jobType": "direct",
349-
"language": "nl",
350-
"numberOfSpeakers": "2"
351-
},
352-
headers: {'content-type': 'application/json'}
353-
};
354-
355-
request(options, function (error, response, body) {
356-
if (error) throw new Error(error);
350+
import axios from 'axios';
351+
352+
async function uploadMediaFromUrl() {
353+
const apiKey = 'YOUR_API_KEY';
354+
355+
const url = 'https://api.amberscript.com/api/jobs/upload-media-from-url';
356+
const queryString = new URLSearchParams({
357+
apiKey
358+
}).toString();
359+
360+
const body = {
361+
sourceUrl: 'https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4',
362+
transcriptionType: 'transcription',
363+
jobType: 'direct',
364+
language: 'nl',
365+
numberOfSpeakers: '2'
366+
};
367+
368+
const options = {
369+
headers: {
370+
'content-type': 'application/json'
371+
}
372+
};
357373
358-
console.log(body);
359-
});
374+
try {
375+
const response = await axios.post(`${url}?${queryString}`, body, options);
376+
console.log(response.data);
377+
} catch (error) {
378+
console.error('Error:', error.response.data)
379+
}
380+
}
360381
```
361382
362383
```python
@@ -583,19 +604,22 @@ HttpResponse<String> response=Unirest.get("https://api.amberscript.com/api/jobs/
583604
```
584605

585606
```javascript
586-
var request = require("request");
607+
import axios from 'axios';
587608

588-
var options = {
589-
method: 'GET',
590-
url: 'https://api.amberscript.com/api/jobs/status',
591-
qs: {jobId: 'JOB_ID', apiKey: 'YOUR_API_KEY'}
592-
};
609+
async function createTranslatedSubtitles() {
610+
const sourceJobId = 'SOURCE_JOB_ID';
611+
const targetLanguage = 'nl';
612+
const apiKey = 'YOUR_API_KEY';
593613

594-
request(options, function (error, response, body) {
595-
if (error) throw new Error(error);
614+
const url = `https://api.amberscript.com/api/jobs/translatedSubtitles?sourceJobId=${sourceJobId}&targetLanguage=${targetLanguage}&apiKey=${apiKey}`;
596615

597-
console.log(body);
598-
});
616+
try {
617+
const response = await axios.post(url, {}, { headers: { 'content-type': 'application/json' } });
618+
console.log(response.data);
619+
} catch (error) {
620+
console.error('Error:', error.response.data)
621+
}
622+
}
599623
```
600624

601625
```python
@@ -727,19 +751,19 @@ HttpResponse<String> response=Unirest.get("https://api.amberscript.com/api/jobs/
727751
```
728752

729753
```javascript
730-
var request = require("request");
731-
732-
var options = {
733-
method: 'GET',
734-
url: 'https://api.amberscript.com/api/jobs/export-srt',
735-
qs: {jobId: 'JOB_ID', apiKey: 'YOUR_API_KEY'}
736-
};
754+
async function exportSTL() {
755+
const jobId = 'JOB_ID';
756+
const apiKey = 'YOUR_API_KEY';
737757

738-
request(options, function (error, response, body) {
739-
if (error) throw new Error(error);
758+
const url = `https://api.amberscript.com/api/jobs/export-stl?jobId=${jobId}&apiKey=${apiKey}`;
740759

741-
console.log(body);
742-
});
760+
try {
761+
const response = await axios.get(url, { headers: { 'Content-Type': 'application/json' } });
762+
console.log(response.data);
763+
} catch (error) {
764+
console.error('Error:', error.response.data);
765+
}
766+
}
743767
```
744768

745769
```python
@@ -805,19 +829,19 @@ HttpResponse<String> response=Unirest.get("https://api.amberscript.com/api/jobs/
805829
```
806830

807831
```javascript
808-
var request = require("request");
832+
async function exportVTT() {
833+
const jobId = 'JOB_ID';
834+
const apiKey = 'YOUR_API_KEY';
809835

810-
var options = {
811-
method: 'GET',
812-
url: 'https://api.amberscript.com/api/jobs/export-vtt',
813-
qs: {jobId: 'JOB_ID', apiKey: 'YOUR_API_KEY'}
814-
};
836+
const url = `https://api.amberscript.com/api/jobs/export-vtt?jobId=${jobId}&apiKey=${apiKey}`;
815837

816-
request(options, function (error, response, body) {
817-
if (error) throw new Error(error);
818-
819-
console.log(body);
820-
});
838+
try {
839+
const response = await axios.get(url, { headers: { 'Content-Type': 'application/json' } });
840+
console.log(response.data);
841+
} catch (error) {
842+
console.error('Error:', error.response.data);
843+
}
844+
}
821845
```
822846

823847
```python
@@ -885,19 +909,19 @@ HttpResponse<String> response=Unirest.get("https://api.amberscript.com/api/jobs/
885909
```
886910

887911
```javascript
888-
var request = require("request");
912+
async function exportTXT() {
913+
const jobId = 'JOB_ID';
914+
const apiKey = 'YOUR_API_KEY';
889915

890-
var options = {
891-
method: 'GET',
892-
url: 'https://api.amberscript.com/api/jobs/export-txt',
893-
qs: {jobId: 'JOB_ID', apiKey: 'YOUR_API_KEY'}
894-
};
895-
896-
request(options, function (error, response, body) {
897-
if (error) throw new Error(error);
916+
const url = `https://api.amberscript.com/api/jobs/export-txt?jobId=${jobId}&apiKey=${apiKey}`;
898917

899-
console.log(body);
900-
});
918+
try {
919+
const response = await axios.get(url, { headers: { 'Content-Type': 'application/json' } });
920+
console.log(response.data);
921+
} catch (error) {
922+
console.error('Error:', error.response.data);
923+
}
924+
}
901925
```
902926

903927
```python
@@ -948,19 +972,19 @@ HttpResponse<String> response=Unirest.get("https://api.amberscript.com/api/jobs/
948972
```
949973

950974
```javascript
951-
var request = require("request");
952-
953-
var options = {
954-
method: 'GET',
955-
url: 'https://api.amberscript.com/api/jobs/export-json',
956-
qs: {jobId: 'JOB_ID', apiKey: 'YOUR_API_KEY'}
957-
};
975+
async function exportJSON() {
976+
const jobId = 'JOB_ID';
977+
const apiKey = 'YOUR_API_KEY';
958978

959-
request(options, function (error, response, body) {
960-
if (error) throw new Error(error);
979+
const url = `https://api.amberscript.com/api/jobs/export-json?jobId=${jobId}&apiKey=${apiKey}`;
961980

962-
console.log(body);
963-
});
981+
try {
982+
const response = await axios.get(url, { headers: { 'Content-Type': 'application/json' } });
983+
console.log(response.data);
984+
} catch (error) {
985+
console.error('Error:', error.response.data);
986+
}
987+
}
964988
```
965989

966990
```python
@@ -1059,19 +1083,19 @@ HttpResponse<String> response=Unirest.delete("https://api.amberscript.com/api/jo
10591083
```
10601084

10611085
```javascript
1062-
var request = require("request");
1063-
1064-
var options = {
1065-
method: 'DELETE',
1066-
url: 'https://api.amberscript.com/api/jobs',
1067-
qs: {jobId: 'JOB_ID', apiKey: 'YOUR_API_KEY'}
1068-
};
1086+
async function deleteJob() {
1087+
const jobId = '6638de0ba17717297470040c';
1088+
const apiKey = 'YOUR_API_KEY';
10691089

1070-
request(options, function (error, response, body) {
1071-
if (error) throw new Error(error);
1090+
const url = `https://api.amberscript.com/api/jobs?jobId=${jobId}&apiKey=${apiKey}`;
10721091

1073-
console.log(body);
1074-
});
1092+
try {
1093+
const response = await axios.delete(url, { headers: { 'Content-Type': 'application/json' } });
1094+
console.log(response.data);
1095+
} catch (error) {
1096+
console.error('Error:', error.response.data)
1097+
}
1098+
}
10751099
```
10761100

10771101
```python
@@ -1119,19 +1143,18 @@ HttpResponse<String> response=Unirest.get("https://api.amberscript.com/api/jobs?
11191143
```
11201144

11211145
```javascript
1122-
var request = require("request");
1146+
async function listJobs() {
1147+
const apiKey = 'YOUR_API_KEY';
11231148

1124-
var options = {
1125-
method: 'GET',
1126-
url: 'https://api.amberscript.com/api/jobs',
1127-
qs: {apiKey: 'YOUR_API_KEY'}
1128-
};
1149+
const url = `https://api.amberscript.com/api/jobs?apiKey=${apiKey}`;
11291150

1130-
request(options, function (error, response, body) {
1131-
if (error) throw new Error(error);
1132-
1133-
console.log(body);
1134-
});
1151+
try {
1152+
const response = await axios.get(url, { headers: { 'Content-Type': 'application/json' } });
1153+
console.log(response.data);
1154+
} catch (error) {
1155+
console.error('Error:', error.response.data)
1156+
}
1157+
}
11351158
```
11361159

11371160
```python

0 commit comments

Comments
 (0)