Help me with HTTP Post script

Hi all,

I am new to the mAirlist community but very enthusiastic about the software and the way everybody is working together in this community.

Hopefully you can help me. I created a Simple Button and fire a script. I want the script to send a HTTP Post to node-red for some studio on-air switching. But… I can’t get HTTP Post working.

My solution is that I do it with curl in the script. But when I click the button the CMD view opens and closes after the script has run. Very annoying, while I think a HTTP Post is more simple.

Does anyone know what to put in a script to send a HTTP Post to a specific http://IP:port and a value to trigger something in node-red.

Please let me know.

For those interested. I have two buttons: ‘ON/OFF AIR’ and ‘CLAIM’. When I click the first button you have five seconds to click on the second one. Then the studio switches on-air or off-air. This logic is done in node-red where all of my studio switching is handled.

What is the curl command in your script like? It might give an idea how the trigger is firing things in node-red..
And is it a POST or a GET command with or without parameters that you need?

I had a similar issue triggering stuff to a vMix API, and I had to change it to a HTTP GET call which took me hours finding out why it wasn’t working..


begin
   
  ShellExecute('powershell.exe', '-WindowStyle Hidden -Command "Invoke-RestMethod -Uri http://localhost:1880/mairlist/onoff -Method Post -Body ''onoff''"');


  SystemLog('PowerShell commando (onzichtbaar) uitgevoerd richting Node-RED.');
end.

Hi,

This is the script that I am using. When I click the button the script is fired. I now do it with a powershell.

But I definately want another (more direct) solution. Also the CMD window is openend.

You can use ShellExecuteHidden against this issue.

That worked well.
Okay, still on the powershell route, but at least it is working.
Thanks!

1 Like

@Tondose Shouldn’t it be possible to fire the http POST command from the mAirlist Script directly, that should eliminate the powershell or curl requirement completely.

I’m jumping in here, because I really want to learn how mAirlist handles the http GET/POST stuff in a script. That will open a lot of possibilities for me.

I struggle at the very beginning because there is HTTPPost and HTTPPostAsync and HTTPPostRaw What is the difference and what are the different use cases?

Hello everyone,

Sure, it’s possible to fire http POST request without curl. Here is an example :

var
	postData: IPersistentObject;
	url: string;

begin

	postData := Factory.CreatePersistentObject;
	postData.SetString('param1', "value1");
	postData.SetString('param2', "value2");

	url := "https://www.domain.com/api";
	HTTPPostRaw(url, 'application/json; charset=iso-8859-1', postData.AsJSON(false, true));

end;

Difference between “async” functions and non-”async” (so “synchronous”) functions is that :

  • Synchronous : calling the function will wait for the answer before going on the next code instructions in the script. If call is very long, script is running during long time.
  • Asynchronous : calling the function will just send the call without waiting for this answer. So, script will going on after the call, no matter the http call result is.

And as far as I know, the “raw” function let us define more detail about the raw “body” part we use, in the http request (as in my example above).

Regards,

1 Like