Showing results for 
Search instead for 
Did you mean: 

Why a curl command works but a similar .Q.hp command fails when sending alerts to TEAMS from KDB

New Contributor II

I have this curl command to send alerts to TEAMS and it works fine:```


system"curl -H 'Content-Type: application/json' -d '{\"text\" : \"Hello World\"}' https://<link to webhook>"


I wanted to use `.Q.hp` instead just to keep things in KDB and I constructed this one :


.Q.hp["https://<link to webhook>";.h.ty`json] .j.j enlist[`text]!enlist"Hello World"


and I get the following error :


<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />


Any ideas why the .Q.hp is not working?

I also tried without 'Content-Type: ', just .h.ty` json


Valued Contributor
Valued Contributor

You can use a second q process help you to debug.

Set a Listening-port \p and have the HTTP Post handler (.z.pp) print incoming message contents


\p 5000
.z.pp:{show x;x}



Trying curl from command line


$ curl -H 'Content-type: application/json' -d '{"text":"Hello World"}' localhost:5000



The server q process prints:


" {\"text\":\"Hello World\"}"



From a client q process using .Q.hp


q).Q.hp["http://localhost:5000";.h.ty`json] .j.j enlist[`text]!enlist"Hello World"



The server q process prints:


" {\"text\":\"Hello World\"}"



 There are only slight differences in the headers. 

You may need to consult documentation of the server you are connecting to to confirm if it has specific header requirements.

(Clients using KX Insights have access to kurl  with more options than .Q.hp)