# Sending a post to ES

**URL:** <https://discuss.elastic.co/t/sending-a-post-to-es/78029>\
**Category:** Elasticsearch\
**Created:** [March 9, 2017, 5:24pm UTC](https://discuss.elastic.co/t/sending-a-post-to-es/78029 "2017-03-09T17:24:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanziee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seanziee/32/45151_2.png) [@seanziee](https://discuss.elastic.co/u/seanziee)\
**Post date:** [March 9, 2017, 5:24pm UTC](https://discuss.elastic.co/t/sending-a-post-to-es/78029/1 "2017-03-09T17:24:44Z")

</div>

I'm trying to design a custom button on my dashboard that will make a watch for a specific query. Going into the API and editing watches based off of data I have in the dashboard is a bit slow and I'm in the process of trying to just create a simple button that the user will enter the Error they would like to set a watch for and press send.

I'm now just trying to make a POST work for a simple index and I can't get it to work and I'm wondering if there is anything in ES stopping me from doing it or if anyone has any suggestions. Here is what I've written thus far:

```
 <!DOCTYPE html>
 <html>
 <head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $.post("172.28.97.54:9200/customer/external?pretty",
        
{
  "name": "Jane Doe"
},
        function(data,status){
            alert("Data: " + data + "\nStatus: " + status);
        });
    });
});
</script>
</head>
<body>

<button>Send an HTTP POST request to a page and get the result back</button>

</body>
</html>
```

---

<div class="post-metadata">

**Author:** ![seanziee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seanziee/32/45151_2.png) [@seanziee](https://discuss.elastic.co/u/seanziee)\
**Post date:** [March 9, 2017, 5:59pm UTC](https://discuss.elastic.co/t/sending-a-post-to-es/78029/2 "2017-03-09T17:59:24Z")

</div>

Or if anyone has any suggestions on sending posts through the browser url bar, I could make something work with that.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 9, 2017, 6:33pm UTC](https://discuss.elastic.co/t/sending-a-post-to-es/78029/3 "2017-03-09T18:33:39Z")

</div>

Kibana dev console would help you?

---

<div class="post-metadata">

**Author:** ![seanziee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seanziee/32/45151_2.png) [@seanziee](https://discuss.elastic.co/u/seanziee)\
**Post date:** [March 9, 2017, 7:02pm UTC](https://discuss.elastic.co/t/sending-a-post-to-es/78029/4 "2017-03-09T19:02:00Z")

</div>

I've been using that, but I'd like to access the kibana dev console with HTML or Javascript in order to send commands from a dashboard. In other words, I want to be able to send commands to ES without necessarily going into the dev API.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 9, 2017, 10:14pm UTC](https://discuss.elastic.co/t/sending-a-post-to-es/78029/5 "2017-03-09T22:14:59Z")

</div>

Ok. Your previous answer confused me.

Anyway. Did you look at the JS Client we have?

[https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html)

---

<div class="post-metadata">

**Author:** ![seanziee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seanziee/32/45151_2.png) [@seanziee](https://discuss.elastic.co/u/seanziee)\
**Post date:** [March 10, 2017, 1:39pm UTC](https://discuss.elastic.co/t/sending-a-post-to-es/78029/6 "2017-03-10T13:39:06Z")

</div>

If anyone in the future is interested how I finally did this, here's my code:

```
<!DOCTYPE html>
<html>
<head>
</head>
<body>

<script>
var xhr = new XMLHttpRequest();
//Starts the variable xhr as the variable for the request
xhr.open('POST',"http://localhost:9200/customer/external", true);
xhr.setRequestHeader("Content-type", "application/json");
//Runs method 'open' which defines the request
xhr.send ("{\"name\": \"Jane Doe\"}");
//Sends the request

xhr.addEventListener("readystatechange",processRequest, false);
//Listens for the response of the request

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === 4) {
var jsonObj = JSON.parse(this.responseText);
var jsonPretty = JSON.stringify(jsonObj, null, '\t');
    alert(jsonPretty);
  }
});
</script>
</body>
</html>

```

This can be used to send a POST request to ES from outside of ES. If you want to have a different request, just change "/customer/external" to whatever you need. Then for the body of the request, if it is complicated, you can download the Postman app where you can change the "body" tab to "raw", copy and paste the exact command like you would from the Kibana API, then press "code"\>\> javascriptXHR. This can be used to create a custom button on your Kibana dash, or whatever other application you can think of that requires you to send POSTs to ES.

Thanks for the support everyone 🙂

---

<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:** [April 7, 2017, 1:39pm UTC](https://discuss.elastic.co/t/sending-a-post-to-es/78029/7 "2017-04-07T13:39:16Z")

</div>

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