# \[Fixed\] Custom node - Fetching data

**URL:** <https://discourse.nodered.org/t/fixed-custom-node-fetching-data/45215>\
**Category:** Developing Nodes\
**Created:** [5 May 2021 12:31 UTC](https://discourse.nodered.org/t/fixed-custom-node-fetching-data/45215 "2021-05-05T12:31:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jake123](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jake123](https://discourse.nodered.org/u/jake123)\
**Post date:** [5 May 2021 12:31 UTC](https://discourse.nodered.org/t/fixed-custom-node-fetching-data/45215/1 "2021-05-05T12:31:15Z")

</div>

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.

```auto
   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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [4 July 2021 12:32 UTC](https://discourse.nodered.org/t/fixed-custom-node-fetching-data/45215/2 "2021-07-04T12:32:03Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
