michoel
12/09/2020, 10:57 PM(async()=>{
console.clear();
async function fetchRetry(url, options, n) {
// based on <https://dev.to/ycmjason/javascript-fetch-retry-upon-failure-3p6g>
try {
const response = await fetch(url, options);
if (response.status !== 200) {
throw `Non 200 response ($response.status)`;
}
return response;
} catch (err) {
if (n === 1) {
throw err;
}
return await fetchRetry(url, options, n - 1);
}
}
async function callEndPoint(action, data) {
const endpoint = '/app/recordscatalog/rcendpoint.nl';
const dataEncoded = encodeURI(JSON.stringify(data));
const response = await fetchRetry(`${endpoint}?action=${action}&data=${dataEncoded}'`, undefined, 3);
const responseJson = await response.json();
return responseJson.data;
}
// Get all tables
const recordTypes = (await callEndPoint('getRecordTypes', {
structureType: "FLAT"
}));
console.log(recordTypes);
// Get fields from a table
const getRecordTypeDetail= await callEndPoint('getRecordTypeDetail', {
scriptId: 'transaction',
detailType: "SS_ANAL"
});
console.log(getRecordTypeDetail);
}
)().then(()=>null).catch(error=>console.error(error));