AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

HTTP Post request without JSON?
 
 

Are there alternative ways to make post requests to APIs? The documentation seems only to cover ^jsonopen() and ^tcpopen(), neither of which work, though I may be missing something.

Current block is trying to send sms from the bot, via an api. I am getting a “badly formed request error”. The api receives UTF8, so I suspect my obstacle is using JSON, in which case I’m not sure what the alternative is.

A direct post request to this url works fine (key and number are fake):

https://api.clockworksms.com/http/send.aspx?key=a469528a3126eb9bc0ddf7414fb4e75a568b0c78&to=447983908899content=CStest

In contrast, several variations of:

u: (sms _* and say _*) ^keep() $tmp _0 $$tmp _1
     
$$url = ^"https://api.clockworksms.com/http/send.aspx?key=a469528a3126eb9bc0ddf7414fb4e75a668b0c49&to=447983908595&content=CStest"
                   
$$user_agent = ^"User-Agent: %bot, ChatScript"
                   
$_header = ^" ~Accept: application/json
                                     
$_userAgent
                                     ~Content-Type: application/json
                                      ~charset: UTF8"
                   
^jsonopen(transient POST $$url $_data $_header $$user_agent)
     
I have texted $tmp 

all result in

....,...JSON response400 size311 - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<
HTML><HEAD><TITLE>Bad Request</TITLE>
<
META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<
BODY><h2>Bad Request</h2>
<
hr><p>HTTP Error 400. The request is badly formed.</p>
</
BODY></HTML

When I try the same code with apis like https://reqres.in it all works fine.

As ever, thanks community, and specially Bruce, for your ongoing assistance - making the learning curve much smoother. 

 

 

 

 
  [ # 1 ]

It works for many people, so clearly something is wrong with your call. But since $_data is not shown, I cant say much more.  If you showed the JSON trace on input, that might help

 

 
  [ # 2 ]

This is the full JSON test (spoofed key and details). But the URL call works fine on postman or the browser. And the CS code works fine with other APIs. It is just this one which specifies utf8

ismael: > sms Lucia and say hello

....,...Json method/urlPOST https://api.clockworksms.com/http/send.aspx?key=a469528a3126eb9bc0ddf7414fb4e75a668b0c49&to=447983908595&content=CStest

....,...Json  data 0 bytes:

....,...
....,...
JSON header:  :
....,...
JSON headerAccept:  application/json
....,...JSON headerContent-Type:  application/json
....,...JSON headercharset:  UTF8
....,...JsonParse Call: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<
HTML><HEAD><TITLE>Bad Request</TITLE>
<
META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<
BODY><h2>Bad Request</h2>
<
hr><p>HTTP Error 400. The request is badly formed.</p>
</
BODY></HTML>


....,...
JSON response400 size311 - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<
HTML><HEAD><TITLE>Bad Request</TITLE>
<
META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<
BODY><h2>Bad Request</h2>
<
hr><p>HTTP Error 400. The request is badly formed.</p>
</
BODY></HTML>

....,...
Responduser:ismael bot:skywalker ip: (~chitchat25   sms Lucia and say hello ==> I have texted Lucia  When:Feb19'19-21:33:22 Why:~chitchat.4.0.~control.9.0   F:634
Luke:  I have texted Lucia
ismael: > 

(happy to email you the actual api details if it helps)

 

 
  [ # 3 ]

according to the trace, the data you supply is:
Json data 0 bytes:

While you have shown me the call, your prior code did not show where $_data was created.

 

 
  login or register to react