# \[Solved\] Using /\_xpack/sql endpoint with dates with curl

**URL:** https://discuss.elastic.co/t/solved-using-xpack-sql-endpoint-with-dates-with-curl/252742
**Category:** Elasticsearch
**Tags:** elastic-stack-sql
**Created:** [October 20, 2020, 9:57pm UTC](https://discuss.elastic.co/t/solved-using-xpack-sql-endpoint-with-dates-with-curl/252742 "2020-10-20T21:57:55Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Tiago\_Cruz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tiago_cruz/32/49080_2.png) [@Tiago\_Cruz](https://discuss.elastic.co/u/Tiago_Cruz)
#### Post date: [October 20, 2020, 9:57pm UTC](https://discuss.elastic.co/t/solved-using-xpack-sql-endpoint-with-dates-with-curl/252742/1 "2020-10-20T21:57:55Z")

</div>

Hello,

This works good:

```auto
$ curl -X POST "localhost:9200/_xpack/sql?format=txt&pretty" -H 'Content-Type: application/json' -d'
{
    "query": "SELECT count(*) FROM whatsapp_202010 WHERE clientInfo.customerId = 7503"
}
'
   count(*)    
---------------
241176

```

I'm having issues to use with timestamp:

- Using `"... AND requestDatetimes.routedAt >= "2020-10-19T00:00:00":`

Error : "reason" : "Unexpected character ('2' (code 50)): was expecting comma to separate Object entries\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@336a791e; line: 3, column: 122]"

- Using `"... AND requestDatetimes.routedAt >= '2020-10-19T00:00:00'"`

Error: reason" : "line 1:114: identifiers must not start with a digit; please use double quotes"

- Using `"... AND requestDatetimes.routedAt >= \"2020-10-19T00:00:00\""`

Error: "reason" : "Found 1 problem(s)\nline 1:106: Unknown column [2020-10-19T00:00:00]"

Can you help please?  
Thanks!

PS: Using `elasticsearch-sql-cli` works good:

```auto
sql> SELECT count(*) FROM whatsapp_202010 WHERE clientInfo.customerId = 7503 AND requestDatetimes.routedAt >= '2020-10-19T00:00:00';
   count(*)    
---------------
36622

```

---

<div class="post-metadata">

### Author: ![bogdan.pintea](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bogdan.pintea/32/45740_2.png) [@bogdan.pintea](https://discuss.elastic.co/u/bogdan.pintea)
#### Post date: [October 21, 2020, 9:27am UTC](https://discuss.elastic.co/t/solved-using-xpack-sql-endpoint-with-dates-with-curl/252742/2 "2020-10-21T09:27:53Z")

</div>

> [@Tiago\_Cruz](#):
>
> I'm having issues to use with timestamp:
> 
> - Using `"... AND requestDatetimes.routedAt >= "2020-10-19T00:00:00":`
> 
> Error : "reason" : "Unexpected character ('2' (code 50)): was expecting comma to separate Object entries\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@336a791e; line: 3, column: 122]"

This will depend on the shell you use, but smth like the below should work:

```auto
$ curl -X POST "localhost:9200/_xpack/sql?format=txt&pretty" -H 'Content-Type: application/json' -d "{\"query\": \"SELECT count(*) FROM whatsapp_202010 WHERE clientInfo.customerId = 7503 AND requestDatetimes.routedAt >= '2020-10-19T00:00:00'\"}"

```

---

<div class="post-metadata">

### Author: ![Tiago\_Cruz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tiago_cruz/32/49080_2.png) [@Tiago\_Cruz](https://discuss.elastic.co/u/Tiago_Cruz)
#### Post date: [October 21, 2020, 1:21pm UTC](https://discuss.elastic.co/t/solved-using-xpack-sql-endpoint-with-dates-with-curl/252742/3 "2020-10-21T13:21:43Z")

</div>

Thanks bogdan!

Another way that I managed to use was:

```auto
$ curl -X POST "localhost:9200/_xpack/sql?format=txt&pretty" -H 'Content-Type: application/json' -d'
{
    "query": "SELECT count(*) FROM whatsapp_202010 WHERE clientInfo.customerId = 5366 AND requestDatetimes.routedAt >= CURDATE() - INTERVAL 30 DAY"
}
'
   count(*)    
---------------
123456   

```

Thanks

---

<div class="post-metadata">

### Author: ![bogdan.pintea](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bogdan.pintea/32/45740_2.png) [@bogdan.pintea](https://discuss.elastic.co/u/bogdan.pintea)
#### Post date: [October 22, 2020, 7:53am UTC](https://discuss.elastic.co/t/solved-using-xpack-sql-endpoint-with-dates-with-curl/252742/4 "2020-10-22T07:53:04Z")

</div>

> [@Tiago\_Cruz](#):
>
> Another way that I managed to use was:

Sure, and that's probably closer to what you wanted anyways, I guess.  
For the record, single quoting as you initially wanted is possible too, but depending on your shell, you might need to use the "ansi c quoting", i.e. something like:

```auto
... -d $'
{
    "query": "SELE... >= \'2020-10-19T00:00:00\'"
}'

```

---

<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: [November 19, 2020, 7:53am UTC](https://discuss.elastic.co/t/solved-using-xpack-sql-endpoint-with-dates-with-curl/252742/5 "2020-11-19T07:53:14Z")

</div>

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