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

https://learninghub.kx.com/forums/topic/why-a-curl-command-works-but-a-similar-q-hp-command-fails-when-sending-alerts-to-teams-from-kdb

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://"

 

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

 

.Q.hp[“https://”;.h.tyjson] .j.j enlist[text]!enlist"Hello World"

 

and I get the following error :

 

"

400 Bad Request

Bad Request

Your browser sent a request that this server could not understand.

"

 

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

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

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”}" HostUser-AgentAcceptContent-type`Content-Length!(“localhost:5000”;“curl/7.58.0”;“/”;“application/json”;“22”)

 

 

From a client q process using .Q.hp

 

q).Q.hp[“http://localhost:5000”;.h.tyjson] .j.j enlist[text]!enlist"Hello World"

 

 

The server q process prints:

 

" {“text”:“Hello World”}" Accept-EncodingConnectionHostContent-type`Content-length!(“gzip”;“close”;“localhost:5000”;“application/json”;“22”)

 

 

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)