zfarnworth Posted January 6 Posted January 6 (edited) Hi guys, Got access to the Bromcom API finally, and was just wondering whether anybody knows how to connect through Powershell? And if someone’s got any commands/scripts they’d be willing to share? 🙂 thanks Edited January 6 by zfarnworth Grammar correction
jthompson Posted January 7 Posted January 7 (edited) Gemini et al are such good starting off points for this sort of thing now. I've noticed Gemini's output for anything PowerShell-related has improved so much recently. The only API's I've written PowerShell scripts for are the Google AppSheet API and the GLPI API. Essentially, you'd be constructing something around using the Invoke-RestMethod cmdlet to make the actual API calls (afaik). When it comes to handling the API key(s), you want to be nice a secure with those as they are keys to MIS data, so store them using a SecretStore vault https://learn.microsoft.com/en-us/powershell/utility-modules/secretmanagement/how-to/manage-secretstore?view=ps-modules. Kinda like a password manager for use in PowerShell scripts, rather than having them stored in plain text or in the script itself. EDIT: This page covers using a SecretStore in automation - https://learn.microsoft.com/en-us/powershell/utility-modules/secretmanagement/how-to/using-secrets-in-automation?view=ps-modules Edited January 7 by jthompson 1
ThomL Posted January 7 Posted January 7 Once you got your App ID And Secret setup and delegated the permissions needed to the endpoints you wish to access (in the following example you'd need access to the students data) - you can then start poking around the API/data. This should get all current students data: ### Bromcom API Request Variables # Define API credentials and parameters $applicationId = "App id here" $applicationSecret = "Secret here" $schoolId = "school ID here" $entityFilter = "endDate IS NULL" $baseUrl = "https://api.bromcomcloud.com/v2/" $EndpointStudents = 'Students?' # Build URI $uri = "$baseUrl$EndpointStudents`entityFilter=$([System.Web.HttpUtility]::UrlEncode($entityFilter))&schoolId=$schoolId" # Set up the headers $headers = @{ "accept" = "text/plain" "ApplicationId" = $applicationId "ApplicationSecret" = $applicationSecret } # Set TLS 1.2 [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 ### API Reqest variables end # GET request try { # Get request $resAllStudents = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers # Harvest response data $AllStudents = $resAllStudents.data # Display results Write-Host $AllStudents | Format-List } catch { # Display error if encountered... Write-Error "Error occurred: $_" } 1
zfarnworth Posted January 7 Author Posted January 7 Thanks both @ThomL @jthompson - Interestingly, Gemini is loads better than CoPilot and ChatGPT at getting me the right api scripts for the different endpoints. Gemini for the win! Thanks so much. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now