Created
November 9, 2025 02:53
-
-
Save jorgeasaurus/e008b3b433be7ff5b89e4484a23fbb0b to your computer and use it in GitHub Desktop.
Retrieves upcoming rocket launches from the RocketLaunch.Live API.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Get-NextRocketLaunch { | |
| <# | |
| .SYNOPSIS | |
| Retrieves upcoming rocket launches from the RocketLaunch.Live API. | |
| .DESCRIPTION | |
| Gets information about upcoming rocket launches from the RocketLaunch.Live API. | |
| This API provides real-time launch data including vehicle information, launch pads, | |
| missions, and media links. | |
| .PARAMETER Count | |
| Number of upcoming launches to retrieve. Default is 5. Maximum is 5 (API limit). | |
| .PARAMETER Provider | |
| Filter launches by provider name (e.g., "SpaceX", "Blue Origin", "CASC"). | |
| .PARAMETER Vehicle | |
| Filter launches by vehicle name (e.g., "Falcon 9", "New Glenn", "Long March 12"). | |
| .PARAMETER Location | |
| Filter launches by launch location name (e.g., "Kennedy Space Center", "Cape Canaveral"). | |
| .PARAMETER Country | |
| Filter launches by country (e.g., "United States", "China"). | |
| .PARAMETER Detailed | |
| Return all properties from the API. By default, only a summary with key properties is shown. | |
| .EXAMPLE | |
| Get-NextRocketLaunch | |
| Retrieves the next 5 upcoming launches with summary information. | |
| .EXAMPLE | |
| Get-NextRocketLaunch -Count 5 | Where-Object { $_.provider.name -eq "SpaceX" } | |
| Retrieves the next 5 launches and filters for SpaceX missions. | |
| .EXAMPLE | |
| Get-NextRocketLaunch | Select-Object name, ProviderName, VehicleName, LaunchTime | |
| Retrieves upcoming launches with custom property selection. | |
| .EXAMPLE | |
| Get-NextRocketLaunch -Detailed | |
| Retrieves the next 5 upcoming launches with all API properties. | |
| .OUTPUTS | |
| PSCustomObject[] containing launch information. | |
| By default (summary mode), returns: | |
| - id: Launch ID | |
| - name: Mission name | |
| - LaunchTime: Launch time (DateTime object) | |
| - ProviderName: Launch service provider name | |
| - VehicleName: Launch vehicle name | |
| - LocationName: Launch location name | |
| - LaunchDescription: Launch Description | |
| With -Detailed flag, returns all API properties including: | |
| - provider, vehicle, pad (full objects) | |
| - missions, tags, media (arrays) | |
| - win_open, win_close, date_str, slug, modified, etc. | |
| .NOTES | |
| API Endpoint: https://fdo.rocketlaunch.live/json/launches/next/{count} | |
| The RocketLaunch.Live API does not require authentication for the /next/5 endpoint. | |
| This free endpoint is limited to a maximum of 5 launches. | |
| For full API access with authentication and more results, see: https://rocketlaunch.live/api | |
| ATTRIBUTION REQUIRED: | |
| When using this data, please display "Data by RocketLaunch.Live" near the data. | |
| .LINK | |
| https://rocketlaunch.live | |
| #> | |
| [CmdletBinding()] | |
| param( | |
| [Parameter()] | |
| [ValidateRange(1, 5)] | |
| [int]$Count = 5, | |
| [Parameter()] | |
| [string]$Provider, | |
| [Parameter()] | |
| [string]$Vehicle, | |
| [Parameter()] | |
| [string]$Location, | |
| [Parameter()] | |
| [string]$Country, | |
| [Parameter()] | |
| [switch]$Detailed | |
| ) | |
| begin { | |
| Write-Information "Starting Get-NextRocketLaunch cmdlet" -InformationAction Continue | |
| # API configuration | |
| $baseUrl = "https://fdo.rocketlaunch.live/json/launches/next" | |
| $maxRetries = 3 | |
| $retryDelay = 2 | |
| } | |
| process { | |
| try { | |
| # Build the request URI | |
| $uri = "$baseUrl/$Count" | |
| Write-Information "Request URI: $uri" -InformationAction Continue | |
| # Make the request with retry logic | |
| $retryCount = 0 | |
| do { | |
| try { | |
| Write-Information "Fetching next $Count launches from RocketLaunch.Live API" -InformationAction Continue | |
| $response = Invoke-RestMethod -Uri $uri -Method GET -ErrorAction Stop | |
| # Validate response structure | |
| if (-not $response.result) { | |
| throw "Invalid API response: 'result' property not found" | |
| } | |
| Write-Information "Successfully retrieved $($response.count) launches" -InformationAction Continue | |
| # Get the results | |
| $launches = $response.result | |
| # Apply filters if specified | |
| if ($Provider) { | |
| Write-Information "Filtering by provider: $Provider" -InformationAction Continue | |
| $launches = $launches | Where-Object { $_.provider.name -like "*$Provider*" } | |
| } | |
| if ($Vehicle) { | |
| Write-Information "Filtering by vehicle: $Vehicle" -InformationAction Continue | |
| $launches = $launches | Where-Object { $_.vehicle.name -like "*$Vehicle*" } | |
| } | |
| if ($Location) { | |
| Write-Information "Filtering by location: $Location" -InformationAction Continue | |
| $launches = $launches | Where-Object { $_.pad.location.name -like "*$Location*" } | |
| } | |
| if ($Country) { | |
| Write-Information "Filtering by country: $Country" -InformationAction Continue | |
| $launches = $launches | Where-Object { $_.pad.location.country -like "*$Country*" } | |
| } | |
| # Add calculated properties for easier consumption | |
| $launches | ForEach-Object { | |
| # Convert t0 to DateTime if available | |
| if ($_.t0) { | |
| $_ | Add-Member -NotePropertyName 'LaunchTime' -NotePropertyValue ([DateTime]$_.t0) -Force | |
| } | |
| # Add provider name as top-level property for easier access | |
| $_ | Add-Member -NotePropertyName 'ProviderName' -NotePropertyValue $_.provider.name -Force | |
| $_ | Add-Member -NotePropertyName 'VehicleName' -NotePropertyValue $_.vehicle.name -Force | |
| $_ | Add-Member -NotePropertyName 'LocationName' -NotePropertyValue $_.pad.location.name -Force | |
| } | |
| # Display attribution | |
| Write-Host "`nData by RocketLaunch.Live" -ForegroundColor Cyan | |
| Write-Host "https://rocketlaunch.live`n" -ForegroundColor Cyan | |
| Write-Host "Retrieving next 5 launches (Free API Limit)" -ForegroundColor Yellow | |
| # Return summary or detailed view | |
| if ($Detailed) { | |
| # Return all properties | |
| Write-Information "Returning detailed launch data" -InformationAction Continue | |
| return $launches | |
| } | |
| else { | |
| # Return summary with key properties only | |
| Write-Information "Returning summary launch data" -InformationAction Continue | |
| return $launches | Select-Object id, name, LaunchTime, ProviderName, VehicleName, LocationName, launch_description | |
| } | |
| break | |
| } | |
| catch { | |
| $retryCount++ | |
| if ($_.Exception.Response.StatusCode -eq 429) { | |
| # Rate limited | |
| Write-Warning "Rate limit exceeded. Retrying in $retryDelay seconds... (Attempt $retryCount of $maxRetries)" | |
| Start-Sleep -Seconds $retryDelay | |
| $retryDelay *= 2 # Exponential backoff | |
| } | |
| elseif ($retryCount -ge $maxRetries) { | |
| throw | |
| } | |
| else { | |
| Write-Warning "Request failed. Retrying... (Attempt $retryCount of $maxRetries)" | |
| Start-Sleep -Seconds 1 | |
| } | |
| } | |
| } while ($retryCount -lt $maxRetries) | |
| } | |
| catch { | |
| $errorMessage = "Failed to retrieve launch data from RocketLaunch.Live API: $($_.Exception.Message)" | |
| if ($_.Exception.Response) { | |
| $statusCode = $_.Exception.Response.StatusCode.value__ | |
| $errorMessage += " (Status Code: $statusCode)" | |
| } | |
| Write-Error $errorMessage | |
| throw | |
| } | |
| } | |
| } | |
| <# | |
| # Sample Output | |
| jorgeasaurus > Get-NextRocketLaunch | |
| Starting Get-NextRocketLaunch cmdlet | |
| Request URI: https://fdo.rocketlaunch.live/json/launches/next/5 | |
| Fetching next 5 launches from RocketLaunch.Live API | |
| Successfully retrieved 5 launches | |
| Data by RocketLaunch.Live | |
| https://rocketlaunch.live | |
| Retrieving next 5 launches (Free API Limit) | |
| Returning summary launch data | |
| id : 5668 | |
| name : TBD | |
| LaunchTime : 11/8/2025 7:30:00 PM | |
| ProviderName : CAS Space | |
| VehicleName : Kinetica-1 | |
| LocationName : Jiuquan Satellite Launch Center | |
| launch_description : A CAS Space Kinetica-1 rocket will launch the TBD mission on Sunday, November 9, 2025 at 3:30 AM (UTC). | |
| id : 5663 | |
| name : Starlink (10-51) | |
| LaunchTime : | |
| ProviderName : SpaceX | |
| VehicleName : Falcon 9 | |
| LocationName : Kennedy Space Center | |
| launch_description : A SpaceX Falcon 9 rocket will launch the Starlink (10-51) mission on Sunday, November 9, 2025 at 8:10 AM (UTC). | |
| id : 139 | |
| name : ESCAPADE | |
| LaunchTime : 11/9/2025 11:45:00 AM | |
| ProviderName : Blue Origin | |
| VehicleName : New Glenn | |
| LocationName : Cape Canaveral SFS | |
| launch_description : A Blue Origin New Glenn rocket will launch the ESCAPADE mission on Sunday, November 9, 2025 at 7:45 PM (UTC). | |
| id : 5669 | |
| name : TBD | |
| LaunchTime : 11/9/2025 6:42:00 PM | |
| ProviderName : CASC | |
| VehicleName : Long March 12 | |
| LocationName : Wenchang Satellite Launch Center | |
| launch_description : A CASC Long March 12 rocket will launch the TBD mission on Monday, November 10, 2025 at 2:42 AM (UTC). | |
| id : 5675 | |
| name : TBD | |
| LaunchTime : 11/9/2025 8:00:00 PM | |
| ProviderName : Galactic Energy | |
| VehicleName : Ceres-1 | |
| LocationName : Jiuquan Satellite Launch Center | |
| launch_description : A Galactic Energy Ceres-1 rocket will launch the TBD mission on Monday, November 10, 2025 at 4:00 AM (UTC). | |
| #> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment