Hi Experts,
I am writing JavaScript to fetch data from a logic app endpoint. The code like below:
function DynamicFlyoutMenu(commandProperties) {
debugger;
var templates = []; //global templates variable
const requestOptions = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ get_templates: 'Yes' })
};
fetch('prod-16.canadaeast.logic.azure.com:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', requestOptions)
.then(response => response.json())
.then(data => {
alert(JSON.stringify(data));
for (const key in data) {
console.log(`${JSON.stringify(data[key])}`) //access values
for (var i in data)
templates.push([data[i]]);
templates = templates[0][0];
}
})
==========================================================
I need to get the template array, but when I run the script, the templates still empty, but the alert display the data like below
{"all-template-data":
[
{"templateName":"Temp001.docx","templateId":"DOC001"},
{"templateName":"Temp002.docx","templateId":"DOC002"},
{"templateName":"Temp003.docx","templateId":"DOC003"}
]
}
Can you help to suggest correct code? Thanks.