# Kibana route not registered in plugin API

**URL:** <https://discuss.elastic.co/t/kibana-route-not-registered-in-plugin-api/162829>\
**Category:** Kibana\
**Created:** [January 3, 2019, 3:30pm UTC](https://discuss.elastic.co/t/kibana-route-not-registered-in-plugin-api/162829 "2019-01-03T15:30:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Valentin\_Courtois](https://avatars.discourse-cdn.com/v4/letter/v/3e96dc/32.png) [@Valentin\_Courtois](https://discuss.elastic.co/u/Valentin_Courtois)\
**Post date:** [January 3, 2019, 3:30pm UTC](https://discuss.elastic.co/t/kibana-route-not-registered-in-plugin-api/162829/1 "2019-01-03T15:30:02Z")

</div>

I'm currently developing a plugin for Kibana (7.0, es 7.0, win10), but I'm having an unexpected issue. The first two routes I created worked fine (under server/routes/routing.js) but for some reason the third one won't be created, and no log would show up in console even though I call console.log().

Here is my code:

```
  async function getStatuses(server){
      let promise = fetch("http://es_instance:port/index/_search",{
        method: "GET",
        mode: "cors",
        headers: {"Content-Type": "application/json"},
        body: {
          "query": { "match_all": {} },
          "aggs": {
            "max_status": {
              "max": {
                "field": "global_status",
                "missing": 0
              }
            }
          }
        }
      }).then(res=>res.json()).then(body=>{
        console.log(body);
        let a = body.hits.hits;
        return { global_status: body.aggregations.max_status.value,
          last_message: a[a.length-1] };
      });

      let res = await promise;

      console.log(res);
      server.route({
        path: '/api/my_plugin_name/my_route',
        method: 'GET',
        handler() {
          return { statuses: JSON.stringify(res) };
        }
      });
}

```

My function is called there:

```
export default function (server) {
    [...]//registering routes in API
    getStatuses(server);
}

```

When I'm hitting directly `/api/my_plugin_name/my_route`, I get a 404. Is it possible that registering routes can somehow return (stop function execution) before `getStatuses()` is even called? Or am I missing something?

---

<div class="post-metadata">

**Author:** ![Valentin\_Courtois](https://avatars.discourse-cdn.com/v4/letter/v/3e96dc/32.png) [@Valentin\_Courtois](https://discuss.elastic.co/u/Valentin_Courtois)\
**Post date:** [January 3, 2019, 4:00pm UTC](https://discuss.elastic.co/t/kibana-route-not-registered-in-plugin-api/162829/2 "2019-01-03T16:00:55Z")

</div>

Now I know for sure function is called. I did a GET instead of a POST. But anyway, route is still not registered. I'm having trouble parsing response of the request. Whatever the way I get the result (json(), text(), blob() or arrayBuffer()), when I parse it and log it, it says

> found START\_ARRAY instead of START\_OBJECT

and I can't manage to find why. I'd be glad if someone could help.

For reference, when I get it as a blob, I see this:

> Blob {  
> [Symbol(type)]: 'application/json; charset=utf-8',  
> [Symbol(buffer)]:  
> \<Buffer 7b 22 65 72 72 6f 72 22 3a 7b 22 72 6f 6f 74 5f 63 61 75 73 65 22 3a 5b 7b 22 74 79 70 65 22 3a 22 70 61 72 73 69 6e 67 5f 65 78 63 65 70 74 69 6f 6e ... \>  
> }

so json() should work well. And it's not an array but a simple json, I know it because I tested the exact same request with postman.

---

<div class="post-metadata">

**Author:** ![tylersmalley](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tylersmalley/32/8833_2.png) [@tylersmalley](https://discuss.elastic.co/u/tylersmalley)\
**Post date:** [January 3, 2019, 11:47pm UTC](https://discuss.elastic.co/t/kibana-route-not-registered-in-plugin-api/162829/3 "2019-01-03T23:47:02Z")

</div>

> [@Valentin\_Courtois](#):
>
> export default function (server) { [...]//registering routes in API getStatuses(server); }

Where is this being called from? This should be in the init function of your plugin.

---

<div class="post-metadata">

**Author:** ![Valentin\_Courtois](https://avatars.discourse-cdn.com/v4/letter/v/3e96dc/32.png) [@Valentin\_Courtois](https://discuss.elastic.co/u/Valentin_Courtois)\
**Post date:** [January 4, 2019, 8:02am UTC](https://discuss.elastic.co/t/kibana-route-not-registered-in-plugin-api/162829/4 "2019-01-04T08:02:12Z")

</div>

Yes it is  
in `init()` function in `index.js` precisely

---

<div class="post-metadata">

**Author:** ![Valentin\_Courtois](https://avatars.discourse-cdn.com/v4/letter/v/3e96dc/32.png) [@Valentin\_Courtois](https://discuss.elastic.co/u/Valentin_Courtois)\
**Post date:** [January 4, 2019, 9:16am UTC](https://discuss.elastic.co/t/kibana-route-not-registered-in-plugin-api/162829/5 "2019-01-04T09:16:16Z")

</div>

Ok, I managed to solve it. For those who got here, my mistake was to put the body straight in json in the fetch. I should have done it like that:

```
  body: JSON.stringify({
    "query": { "match_all": {} },
    "aggs": {
      "max_status": {
        "max": {
          "field": "global_status",
          "missing": 0
        }
      }
    }
  })
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 1, 2019, 9:16am UTC](https://discuss.elastic.co/t/kibana-route-not-registered-in-plugin-api/162829/6 "2019-02-01T09:16:19Z")

</div>

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