hello I have a question about fetching inside js.file
In my case i have 2 apis. http://{pathToAPI}/data and http://{pathToAPI}/meta
.
Meta api gives back the details about the data.
Data api gives back the value of the certain data.
In my meta api i have a parameter named count.
fetch("")
.then(res => res.json())
.then(data => {
data.forEach(item => {
console.log(item)
console.log(item.count)
if(item.count > 2) {
const url = `${options}`
fetch(url)
.then(res => res.text())
.then(data => {
data = data.split(',')
msg.payload = data;
node.send(msg)
})
} else {
msg.payload = Number(data);
node.send(msg)
}
Options variable is just the data i select in nodes edit dialog.
So i want to fetch the data and if its count is bigger than 1 i want my msg.payload be array of data. And if that count is 1 i want it to be a number.
Any ideas how would i do it?
EDIT : fetch(
${options}) .then(res => res.json()) .then(data => { const url =
${options}`
fetch(url)
.then(res => res.text())
.then(date => {
if(data.count > 1) {
date = date.split(',');
msg.payload = date;
node.send(msg)
} else {
msg.payload = Number(date);
node.send(msg)
}
})
})`
would this work
EDIT: You can delete this topic . I fixed it