This is code for an Azure Function that is triggered every 5 minutes to do a GET from an API, check for duplicated records in Azure blob storage it has already seen and POST any new alerts to another API.
This code was written specifically to poll the Translink API for Alerts and broadcast them to a Microsoft Flow endpoint which in turn sends notifications via Teams and SMS, but could be adapted to poll many APIs and broadcast updates.
To make this work for any other API change the Classes.cs file to match the response from the API you would like to poll.
- Note: If you don't need to check for duplicates consider using a Logic App or Microsoft Flow instead
To run in Azure, run the ARM Template found in azuredeploy.json and then fill in the app settings with the following values:
- BearerToken : the Auth token for the API you want to GET from
- PollUrl : The URL of the API you want to get from
- PostUrl : The URL of the API you want to POST to
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "",
"BlobStorageConnectionString": "",
"BlobStorageAccountName":"",
"BlobStorageContainerName": "",
"BlobStorageBlobName": "",
"BearerToken":"",
"PollUrl" : "",
"PostUrl" :""
}
}