# Bad Request Answer from Orthanc upon query

**URL:** https://discourse.orthanc-server.org/t/bad-request-answer-from-orthanc-upon-query/913
**Category:** Google Groups archive
**Created:** [March 3, 2018, 4:11pm UTC](https://discourse.orthanc-server.org/t/bad-request-answer-from-orthanc-upon-query/913 "2018-03-03T16:11:11Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Robert\_H](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@Robert\_H](https://discourse.orthanc-server.org/u/Robert_H)
#### Post date: [March 3, 2018, 4:11pm UTC](https://discourse.orthanc-server.org/t/bad-request-answer-from-orthanc-upon-query/913/1 "2018-03-03T16:11:11Z")

</div>

I am still hung up on this Issue… Also the examples in the tests are not working,  
can anyone provide me with example querys that are accepted by orthanc?

the way I am querying is via curl eg:

curl -v [http://localhost:8042/modalities/KAP2/query](http://localhost:8042/modalities/KAP2/query) -X POST -d ‘{“Level”:“Patient”,“CaseSensitive”:False,“Query”:{“PatientName”:“_n_”}}’

with verbose on, the output is:

Note: Unnecessary use of -X or --request, POST is already inferred.

- Trying ::1…
- TCP\_NODELAY set
- Trying 127.0.0.1…
- TCP\_NODELAY set
- Connected to localhost (127.0.0.1) port 8042 (#0)

> POST /modalities/KAP2/query HTTP/1.1  
> Host: localhost:8042  
> User-Agent: curl/7.58.0  
> Accept: _/_  
> Content-Length: 61  
> Content-Type: application/x-www-form-urlencoded

- upload completely sent off: 61 out of 61 bytes  
\< HTTP/1.1 400 Bad Request  
\< Content-Length: 0  
\<
- Connection #0 to host localhost left intact

I am really quite lost on the matter, as this is a basic functionality and besides [the code of the test repo](https://bitbucket.org/sjodogne/orthanc-tests/src/90e5331ddee905afbe4657e7547c8e10bdb2349d/Tests/Tests.py?fileviewer=file-view-default#Tests.py-1548) which does get me nowhere. I cant find documentation on the structure.

Greatful for every bit,

Robert

---

<div class="post-metadata">

### Author: ![bdearlove](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/bdearlove/32/1661_2.png) [@bdearlove](https://discourse.orthanc-server.org/u/bdearlove)
#### Post date: [March 3, 2018, 6:48pm UTC](https://discourse.orthanc-server.org/t/bad-request-answer-from-orthanc-upon-query/913/2 "2018-03-03T18:48:21Z")

</div>

This works for me, copied from Insomnia REST tool. I’m also using Mirth to do queries and working ok.

curl --request POST   
–url [http://IPADDRESS:8042/modalities/KAP2/query](http://IPADDRESS:8042/modalities/KAP2/query)   
–data ‘{“Level”:“Study”,“Query”:{“PatientID”:“P12345”,“StudyDescription”:“Chest”,“PatientName”:“”,“ModalitiesInStudy”:“”}}’

---

<div class="post-metadata">

### Author: ![Robert\_H](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@Robert\_H](https://discourse.orthanc-server.org/u/Robert_H)
#### Post date: [March 3, 2018, 7:25pm UTC](https://discourse.orthanc-server.org/t/bad-request-answer-from-orthanc-upon-query/913/3 "2018-03-03T19:25:28Z")

</div>

Ok, so by trial and error I found a way to query successfully.  
it does not work inline but like:

curl -v -X POST [http://localhost:8042/modalities/KAP2/query](http://localhost:8042/modalities/KAP2/query) -d @- \<\< EOF  
{“Level” : “Patient”, “Query” : {“PatientID” : “0”}}  
EOF

Now I have queries, I can look at them by:

curl -v [http://localhost:8042/queries](http://localhost:8042/queries)

My next hurdle is: What content does

curl -v [http://localhost:8042/modalities/KAP2/retrieve](http://localhost:8042/modalities/KAP2/retrieve) -d @- \<\< EOF  
EXPECT HERE?  
EOF  
?

---

<div class="post-metadata">

### Author: ![Robert\_H](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@Robert\_H](https://discourse.orthanc-server.org/u/Robert_H)
#### Post date: [March 3, 2018, 8:36pm UTC](https://discourse.orthanc-server.org/t/bad-request-answer-from-orthanc-upon-query/913/4 "2018-03-03T20:36:00Z")

</div>

Hi Brian,  
I just saw your answer now, But thanks anyway!!! =)

I figured out how retrieval of the queries works, only that it doesn’t =(

curl -v [http://localhost:8042/queries/ebb8e082-94ad-4f5b-9605-ad5c4cf776ac/answers/0/retrieve](http://localhost:8042/queries/ebb8e082-94ad-4f5b-9605-ad5c4cf776ac/answers/0/retrieve) -d “KAP1”  
or  
curl -v [http://localhost:8042/queries/ebb8e082-94ad-4f5b-9605-ad5c4cf776ac/retrieve](http://localhost:8042/queries/ebb8e082-94ad-4f5b-9605-ad5c4cf776ac/retrieve) -d “KAP1”

both finish with 200 OK but  
curl -v [http://localhost:8042/studies](http://localhost:8042/studies)  
is still empty.  
and I checked, answers/content was listing the study I wanted.

still desperate for help,

Robert

---

<div class="post-metadata">

### Author: ![bdearlove](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/bdearlove/32/1661_2.png) [@bdearlove](https://discourse.orthanc-server.org/u/bdearlove)
#### Post date: [March 3, 2018, 9:51pm UTC](https://discourse.orthanc-server.org/t/bad-request-answer-from-orthanc-upon-query/913/5 "2018-03-03T21:51:44Z")

</div>

Here you go, this works for me no problem:

curl --request POST   
–url [http://ORTHANCADDRESS:8042/queries/6326083f-512f-422f-ad61-8c7cd7643a6e/retrieve](http://ORTHANCADDRESS:8042/queries/6326083f-512f-422f-ad61-8c7cd7643a6e/retrieve)   
–data ORTHANCAE

---

<div class="post-metadata">

### Author: ![Robert\_H](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@Robert\_H](https://discourse.orthanc-server.org/u/Robert_H)
#### Post date: [March 3, 2018, 11:56pm UTC](https://discourse.orthanc-server.org/t/bad-request-answer-from-orthanc-upon-query/913/6 "2018-03-03T23:56:02Z")

</div>

Thank you again, after checking all my configurations 5 times and still getting servererrors, I found my problem.  
Somehow the machine on which my second Orthanc is running, every now and then (quite often) disconnects from my wifi…  
But that is another issue =)

for anyone who might ever have the same struggle as I, here is everything that worked for me(KAP1 was my AET and KAP2 the distant AET):

store sth:  
curl -v [http://localhost:8042/modalities/KAP2/store](http://localhost:8042/modalities/KAP2/store) -d “9fcadbc3-58807fe5-05a2969e-ab4aafaa-af735eaa”

if all is fine the http says 200 OK and the output is {}

delete sth:  
curl -v -X DELETE [http://localhost:8042/studies/fc6fbffe-8531efa2-7434a372-09242661-fe012bc6](http://localhost:8042/studies/fc6fbffe-8531efa2-7434a372-09242661-fe012bc6)

if it worked http says 200 OK and the output tells you the remaining ancestor

qery stuff:  
//this worked in bash but not in windows cmd  
curl -v -X POST [http://localhost:8042/modalities/KAP2/query](http://localhost:8042/modalities/KAP2/query) -d @- \<\< EOF  
{“Level” : “Study”, “Query” : {“PatientID” : “2c\*”}}  
EOF

returns something like this  
{“ID” : “4c39b9e8-3ebc-418e-8041-73531bc924f1”, “Path” : “/queries/4c39b9e8-3ebc-418e-8041-73531bc924f1”}  
Bad request is returned if the level- query structure is off and bad fileformat, well, if the format of the data is off

retrieve query:  
curl -v -X POST [http://localhost:8042/queries/46a139eb-2871-402c-9fa1-3fd2c9d1de29/answers/0/retrieve](http://localhost:8042/queries/46a139eb-2871-402c-9fa1-3fd2c9d1de29/answers/0/retrieve) -d “KAP1”  
triggers a C-Move on the query answer with index 0

Thank you for your help,

Robert
