# API call not working as expected

**URL:** <https://discourse.nodered.org/t/api-call-not-working-as-expected/62680>\
**Category:** General\
**Tags:** http-request\
**Created:** [16 May 2022 08:47 UTC](https://discourse.nodered.org/t/api-call-not-working-as-expected/62680 "2022-05-16T08:47:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeetaJ](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/neetaj/32/60934_2.png) [@NeetaJ](https://discourse.nodered.org/u/NeetaJ)\
**Post date:** [16 May 2022 08:47 UTC](https://discourse.nodered.org/t/api-call-not-working-as-expected/62680/1 "2022-05-16T08:47:56Z")

</div>

Hi,

I a trying to call an api from the front end but i dont get the expected result.

This is frontend

```auto
 <div class="grid grid-container--fluid btn-toolbar">
  <div class="column-md-6" v-for="sensor in sensorData">
    <div class="column-md-6" v-if="getCurrentData(sensor.app_id_aqi)">
      <div v-for="data in currentData">
        {%data%}
      </div>
    </div>

```

Javascript method

```auto
 getCurrentData(apiID) {
            console.log("apiid", apiID)

            axios.get("api/getCurrentData/"+apiID).then((response) => {
                this.currentData = response.data;
                console.log("currentData", this.currentData)

            }).catch(error => {
                console.log(error);
                console.log(error.response.data);
                console.log(error.response.headers)
            });
        },
    

```

HTTP request node for API call

```auto
[{"id":"d8226eb44f302e20","type":"http in","z":"e3b2a296f968effa","name":"","url":"/api/getCurrentData/:apiID","method":"get","upload":false,"swaggerDoc":"","x":170,"y":700,"wires":[["4a88ebf475955c77","2af5585dec07c33b"]]},{"id":"2af5585dec07c33b","type":"http request","z":"e3b2a296f968effa","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://data.sensor.community/airrohr/v1/sensor/{apiID}/","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"credentials":{},"x":410,"y":680,"wires":[["644a880fdd5c82a6"]]},{"id":"644a880fdd5c82a6","type":"debug","z":"e3b2a296f968effa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":570,"y":700,"wires":[]}]

```

When i do a normal get method like [https://data.sensor.community/airrohr/v1/sensor/72267/](https://data.sensor.community/airrohr/v1/sensor/72267/) i get the response but when i am passing th apiid from the method, it doesnt work and i get below response

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b356b44e1d337049c2c72a2ac4ae50d51deff4cc.png)

Can anyone help here please

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 May 2022 08:59 UTC](https://discourse.nodered.org/t/api-call-not-working-as-expected/62680/2 "2022-05-16T08:59:45Z")

</div>

From the built in help of the HTTP Requst node...

> When configured within the node, the URL property can contain [mustache-style](http://mustache.github.io/mustache.5.html) tags. These allow the url to be constructed using values of the incoming message. For example, if the url is set to `example.com/{{{topic}}}`

Your URL is set to `https://data.sensor.community/airrohr/v1/sensor/{apiID}/` \<\< note the single `{` `}` curly brackets

---

<div class="post-metadata">

**Author:** ![NeetaJ](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/neetaj/32/60934_2.png) [@NeetaJ](https://discourse.nodered.org/u/NeetaJ)\
**Post date:** [16 May 2022 09:30 UTC](https://discourse.nodered.org/t/api-call-not-working-as-expected/62680/3 "2022-05-16T09:30:06Z")

</div>

Hi @Steve-Mcl

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/6/46739493b66d4538a6a7b0bf011cd3b24a277550.png)

I am passing the apiID which i get from the payload of the function node shown below  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/d/cde86f3bdadb5feb0c12cf1c6383fb01fb7bc295.png)

this is my http request node  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/4/c42acfd6861b78c6cf5ebf12c05af14af93925d4.png)

still the response is same

---

<div class="post-metadata">

**Author:** ![NeetaJ](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/neetaj/32/60934_2.png) [@NeetaJ](https://discourse.nodered.org/u/NeetaJ)\
**Post date:** [16 May 2022 11:07 UTC](https://discourse.nodered.org/t/api-call-not-working-as-expected/62680/4 "2022-05-16T11:07:05Z")

</div>

it works!!!Thanks a ton

---

<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:** [30 May 2022 11:07 UTC](https://discourse.nodered.org/t/api-call-not-working-as-expected/62680/5 "2022-05-30T11:07:16Z")

</div>

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