[Help] RESTAPI/Powershell GUI

Evening all,

I’ve recently written a script that makes a post request, it works perfectly find in a terminal but now that I’ve put it into a GUI it seems that although the requests are successful they’re not being updated in the application until a secondary request is made (e.g. I’m making 2 post requests for 1 to be updated within the application, the 3rd post request will then make the 2nd request display).

Can anyone explain what is causing this behavior?

Thanks

$NoteData = $richTextBox1.Text
$ReqID = $textBox1.Text
$sdphost = “http://localhost/
$techkey = “9481D00C-B591-4A2F-8103-D819969922F7”
$url = $sdphost + “sdpapi/request/” + $ReqID + “/notes”
$method = “POST”
$operation = “ADD_NOTE”
$inputdata = @"
{
“operation”: {
“details”: {
“notes”: {
“note”: {
“ispublic”: “false”,
“notestext”: $NoteData
}
}
}
}
}
"@
$params = @{INPUT_DATA=$inputdata;OPERATION_NAME=$operation;TECHNICIAN_KEY=$techkey;format=‘json’}

$button2_Click = {
Invoke-WebRequest -Uri $url -Method POST -Body $params -Timeoutsec 10 > D:\Output$NoteData.txt
}

. (Join-Path $PSScriptRoot ‘Form1.designer.ps1’)
$Form1.ShowDialog()