Error in custom plugin of Kibana

hi team,
Please, help with issue. Getting error while making a POST/PUT requests from custom plugin from browser to elastic index:

status: 401,
 displayName: 'AuthenticationException',
 message:
'[security_exception] missing authentication token for REST request [/_bulk?0=&1=&2=&3=],      with { header={ WWW-Authenticate="Basic realm=\\"security\\" charset=\\"UTF-  8\\"" } }',
 path: '/_bulk',
 query:
  { '0': [Object], '1': [Object], '2': [Object], '3': [Object] },
 body: { error: [Object], status: 401 },
 statusCode: 401,
 response:
‘{"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication token for     REST request [/_bulk?0=&1=&2=&3=]","header":{"WWW-Authenticate":"Basic  realm=\\"security\\" charset=\\"UTF-8\\""}}],"type":"security_exception","reason":"missing authentication token for REST request [/_bulk?0=&1=&2=&3=]","header":{"WWW-Authenticate":"Basic realm=\\"security\\" charset=\\"UTF-8\\""}},"status":401}',
 wwwAuthenticateDirective: 'Basic realm="security" charset="UTF-8"',
 toString: [Function],
 toJSON: [Function],
 isBoom: true,
 isServer: false,
 data: null,
 output: { statusCode: 401, payload: [Object], headers: [Object] },

Few more follow up questions: what version of the stack are you on ? License level? Is there a proxy in btw Kibana and ES .

Thanks
Rashmi

I use ES 6.7.0 with trial x-pack license. There is no proxy btw them.

team, any help here?

Hey @masterThomas,

How are you making the request from the browser to elasticsearch? Is the browser making the request directly to ES, or is it going through the Kibana server to proxy the request to ES?

it goes through Kibana server : client goes to endpoint, endpoint makes PUT or POST or DELETE request and then makes records, but in my case it does not record with the error " missing authentication token for REST request [/_bulk] "

Can you share how you're making the request to Kibana from the kibana server on behalf of the end user?

i used Postman to make requests. i just send my JSON to custom endpoint to post or update changes and then get the error.

You should use Kibana's built-in Elasticsearch client to perform requests to ES. See Communicating with Elasticsearch for more details. If you're looking to make requests on behalf of the end user, then you'll want to use the callWithRequest described in that link.

i already use callWithRequest in my endpoint. so this error is with callWithRequest method.
I made my endpoint with settings described in that link. so i usecallWithRequest and get the error in this topic

Is your plugin code available on github? I really need to see a code sample to help out any further.

i commited my code on github with reference kibana plugin github

Thanks @masterThomas. I see it doesn't have the public directory/code, so I won't be able to run this, but the code itself looks correct on the surface.

How do you have Kibana and Elasticsearch configured? Can you post your kibana.yml and elasticsearch.yml configuration, redacting any sensitive information such as passwords?

are all bulk requests failing, or are just one/some of them failing?

all bulk request are failing. I posted my config files on github: kibana.yml and elasticsearch.yml

Thanks for the update, your configuration looks fine on the surface as well. Are you in a position to share the complete plugin code on github? The public folder is missing at the very least, so I'm not able to download and run this to help diagnose problems.

Unfortunately, im not able to share my code. Can we use teamviewer session or kind of that?

Sent you a DM

Hi Larry, many thanks for your help. I resolved this strange issue. Hope, it will not return.

For anyone else following along, make sure your bulk requests have a body property:

:no_entry_sign: BAD

const bulkRequests = [
  {"update": { ... } },
  { ... },
  {"index": { ... } },
  { ... } 
];

await callWithRequest(request, 'bulk', bulkRequest);

:white_check_mark: GOOD

const bulkRequests = [
  {"update": { ... } },
  { ... },
  {"index": { ... } },
  { ... } 
];

await callWithRequest(request, 'bulk', { body: bulkRequests });