# Called with an invalid endpoint: sql.query

**URL:** <https://discuss.elastic.co/t/called-with-an-invalid-endpoint-sql-query/209586>\
**Category:** Kibana\
**Created:** [November 26, 2019, 9:53pm UTC](https://discuss.elastic.co/t/called-with-an-invalid-endpoint-sql-query/209586 "2019-11-26T21:53:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pgervais](https://avatars.discourse-cdn.com/v4/letter/p/65b543/32.png) [@pgervais](https://discuss.elastic.co/u/pgervais)\
**Post date:** [November 26, 2019, 9:53pm UTC](https://discuss.elastic.co/t/called-with-an-invalid-endpoint-sql-query/209586/1 "2019-11-26T21:53:18Z")

</div>

I'm trying to develop a kibana plugin (Elasticsearch & Kibana both Ver 7.4.1). In order to get started i have used the known plugin analyse\_api as an example and starting point.

I'm trying to invoke the Elasticsearch API of sql query. i.e. sql.query. This requires that i pass the required SQL string along with a know format string. My string is very simple: "SELECT ObsDate from websphere". Format is json.

At this point i'm getting the error "called with an invalid endpoint: sql.query" shown above and must admit i'm completely at a loss as to why!

To get things started , i call the sqlquery method to perform the post operation from the browser to the kibana server. Code segments are shown below.

import chrome from 'ui/chrome';  
let httpClient;  
export const setHttpClient = client =\> {  
httpClient = client;  
};

export const getHttpClient = () =\> {  
return httpClient;  
};

const apiPrefix = chrome.addBasePath('/api/analyze\_api\_ui');  
export async function sqlquery(params) {  
console.log('httpClient:' + httpClient);

console.log('sqlquery : Params:Query: ' + params.query + ' JSON:' + JSON.stringify(params));  
console.log('sqlquery addBasepath:' + apiPrefix + ' params:' + params);  
const response = await httpClient.post(`${apiPrefix}/sqlquery`, params);  
return response;  
}

Eventually this gets routed to the following below:  
let call = server.plugins.elasticsearch.getCluster('data').callWithRequest;

server.route({  
path: '/api/analyze\_api\_ui/sqlquery',  
method: 'POST',  
options: {  
validate: {  
payload: Joi.object()  
.keys({  
query: Joi.string().required(),  
})  
.required(),  
},  
},  
handler: async req =\> {  
let param = {  
body: {  
format: 'json',  
query: req.payload.query,  
},  
};

```
  try {
    console.log('Sql.query params:' + JSON.stringify(param));
    const response = await call(req, 'sql.query', param);

    console.log(
      'Sql.query response details:' + JSON.stringify(response.detail),
      ' Request:' + param.body
    );
    return {
      detail: response.detail,
      request: param.body,
    };
  } catch (error) {
    console.log('Sql.query Error result:' + convertEsError(param.index, error));
    return convertEsError(param.index, error);
  }

```

Error Trace:

In server route sqlquery:{"body":{"format":"json","query":"SELECT ObsDate FROM websphere"}}  
Sql.query params:{"body":{"format":"json","query":"SELECT ObsDate FROM websphere"}}  
callAPI:endpoint sql.query clientPath:sql,query api:undefined  
Sql.query Error result:Error: called with an invalid endpoint: sql.query  
server error [16:19:18.836] Error: called with an invalid endpoint: sql.query  
at callAPI (/Users/pgervais/kibana/src/core/server/elasticsearch/cluster\_client.ts:77:11)  
at ScopedClusterClient.callAPI [as scopedAPICaller] (/Users/pgervais/kibana/src/core/server/elasticsearch/cluster\_client.ts:222:18)  
at ScopedClusterClient.scopedAPICaller (/Users/pgervais/kibana/src/core/server/elasticsearch/scoped\_cluster\_client.ts:93:17)  
at callAsCurrentUser (/Users/pgervais/kibana/src/legacy/core\_plugins/elasticsearch/lib/cluster.ts:37:8)  
at call (/Users/pgervais/kibana/plugins/cbsa/server/routes/analyze.js:190:32)  
at module.exports.internals.Manager.execute (/Users/pgervais/kibana/node\_modules/hapi/lib/toolkit.js:35:106)  
at Object.internals.handler (/Users/pgervais/kibana/node\_modules/hapi/lib/handler.js:50:48)  
at exports.execute (/Users/pgervais/kibana/node\_modules/hapi/lib/handler.js:35:36)  
at Request.\_lifecycle (/Users/pgervais/kibana/node\_modules/hapi/lib/request.js:263:62)  
at process.\_tickCallback (internal/process/next\_tick.js:68:7)

I have tried a number of obvious changes:

1. tried all permutations of params format all to no avail.
2. Have added debug statements wherever i can.
3. I have put console printouts in callAPI.

callAPI:endpoint sql.query clientPath:sql,query api:undefined  
Note that the endpoint has sql.query whereas the clientPath has sql,query ? A comma separator. It's in callAPI where the error message is generated portions of the vcode shown below.

async function callAPI(  
client: Client,  
endpoint: string,  
clientParams: Record\<string, any\> = {},  
options: CallAPIOptions = { wrap401Errors: true }  
): Promise {  
const clientPath = endpoint.split('.');  
const api: any = get(client, clientPath);  
if (!api) {  
console.log('callAPI:endpoint' + endpoint + ' clientPath:' + clientPath + ' api:' + api);  
throw new Error(`called with an invalid endpoint: ${endpoint}`);  
}

Any help from kibana plugin gurus would be highly appreciated.

---

<div class="post-metadata">

**Author:** ![matw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matw/32/13913_2.png) [@matw](https://discuss.elastic.co/u/matw)\
**Post date:** [November 28, 2019, 3:54pm UTC](https://discuss.elastic.co/t/called-with-an-invalid-endpoint-sql-query/209586/2 "2019-11-28T15:54:58Z")

</div>

Hi  
Could you try using

xpack.sql.query

thx,  
Matthias

---

<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:** [December 26, 2019, 3:55pm UTC](https://discuss.elastic.co/t/called-with-an-invalid-endpoint-sql-query/209586/3 "2019-12-26T15:55:15Z")

</div>

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