cancel
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

user931206
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 :

 

"<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>"

 

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


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

1 REPLY 1

rocuinneagain
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\"}"
`Host`User-Agent`Accept`Content-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.ty`json] .j.j enlist[`text]!enlist"Hello World"

 

 

The server q process prints:

 

" {\"text\":\"Hello World\"}"
`Accept-Encoding`Connection`Host`Content-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)