Open sitestudio opened 1 month ago
Here is a Bash script that creates a C# file, Program.cs, with an HTTP POST request to the Event-API in STUDENTPUB:
#!/bin/bash
# Create a C# file
cat << EOF > Program.cs
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
private static readonly HttpClient client = new HttpClient();
static async Task Main(string[] args)
{
await PostEventAsync();
}
private static async Task PostEventAsync()
{
var payload = @"{
'array': [
{
'eventType': 'EventName',
'subject': 'EventSubject',
'eventTime': '2020-06-27T00:00:00',
'id': '831e1650-001e-001b-66ab-eeb76e069631',
'data': {
'primaryKey': '987654321',
'zoneId': '2282',
'actionType': 'I'
},
'dataVersion': '1.0'
}
]
}";
var data = new StringContent(payload, Encoding.UTF8, "application/json");
var url = "http://your-url.com/event-api/events";
var response = await client.PostAsync(url, data);
string result = await response.Content.ReadAsStringAsync();
Console.WriteLine(result);
}
}
EOF
echo "C# file created successfully."
This script will create a C# file, Program.cs
, with a static HTTP client that posts data to the Event-API. The payload is based on the example given. You will need to replace "http://your-url.com/event-api/events"
with the actual URL of your API. The response from the API is read as a string and then printed to the console.
Please note that for the script to work correctly, you need to have full permissions to create and write to a file in the directory where the script is executed.
Please review and run the script in your test environment before implementing it into a production scenario.
Provide a C# example of calling a POST method from STUDENTPUB