HTTP POST request to 3 party API

Hi,

I need to do a Http POST request to a 3rd party API. I need to send two files and some data.
In python i use requests.post(url, data=json_data, files=filesHolder) where json_data and filesHolder are dictionary and they are as follows:-
json_data={‘key’:value}
filesHolder = {‘file1’:open(‘somefile1.txt’, ‘r’), ‘file2’:open(‘somefile2.txt’, ‘r’)}

I need to realize this from openHAB rules/scripts. Eclipse smart home provides the following 2 implementations for HTTP POST request:-
sendHttpPostRequest(String url) : String - HTTP
sendHttpPostRequest(String url, String contentType, String content) : String - HTTP

How do I use the above sendHttpPostRequest function to do what I did in python??

Regards,
Abin

I don’t think there is an easy way to do it in rules. You will have to look at the HTTP POST spec, sniff some packets, or figure out how to see the actual text that gets generated. Then write a rule that creates the text for the content that looks proper.

It would probably be easier to just call the python script you have working using the exec binding.

1 Like