Kibana SavedObject API

I am able to use SavedObject API (https://www.elastic.co/guide/en/kibana/current/saved-objects-api.html) via http POST in local elastic search by using localhost 5601.

However, in cloud Elastic Search there is https and username/password. How to pass this along in the POST?

I know you can pass in -u parameters in CURL. How to do this in a http post (in Java)? is there a Java API for Kibana?

Hi,

I don't believe we have a Java API for Kibana, how about using HttpURLConnection in Java to do the request? https://docs.oracle.com/javase/8/docs/api/java/net/HttpURLConnection.html

Thanks.

So I am following the example here for
https://www.elastic.co/guide/en/kibana/current/saved-objects-api-create.html

This CURL command below does work for my local kibana, it created a index pattern for me:

curl -X POST "http://localhost:5601/api/saved_objects/index-pattern/my-pattern" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d'
{
"attributes": {
"title": "my-pattern-*"
}
}
'
So I substituted the url http://localhost:5601 with my Cloud Kibana url, and try passing credentials along with -u username:password, but it didn't work, it didn't create an index on my kibana cloud. I am getting

curl: (52) Empty reply from server

So my question is... does the Kibana SavedObject API work for the cloud version? if so how to pass the credentials?

@Joseph_Mak Kibana's saved object API does work for the cloud version. If you're using cURL to do so, you use the same -u username:password flag which you do locally. You can use the -I flag with curl to get additional information, which might be helpful in your situation.

Thank you... so my solution (java) is:

		String encoding = Base64.getEncoder().encodeToString((user + ":" + password).getBytes());
		HttpPost request = new HttpPost(<my https kibana url>);
		request.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + encoding);
		request.setHeader("kbn-xsrf","true");
		String payload = <my json>
		StringEntity entity = new StringEntity(payload, ContentType.APPLICATION_JSON);
		request.setEntity(entity);

		HttpResponse response = httpClient.execute(request)

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