55 lines
1.7 KiB
PowerShell
55 lines
1.7 KiB
PowerShell
|
# Define API URLs
|
||
|
$loginUrl = "http://localhost:8080/api/v1/login"
|
||
|
$generateNotebookUrl = "http://localhost:8080/api/v1/notebook"
|
||
|
$docsUrl = "http://localhost:8080/swagger/doc.json" # URL to fetch the docs.json
|
||
|
|
||
|
# User credentials
|
||
|
$username = "admin"
|
||
|
$password = "defaultPassword" # Replace with the actual password
|
||
|
|
||
|
# Prepare login request body
|
||
|
$loginBody = @{
|
||
|
username = $username
|
||
|
password = $password
|
||
|
} | ConvertTo-Json
|
||
|
|
||
|
# Send login request
|
||
|
$response = Invoke-RestMethod -Method Post -Uri $loginUrl -Body $loginBody -ContentType "application/json"
|
||
|
|
||
|
# Extract token from login response
|
||
|
$token = $response.token
|
||
|
|
||
|
# Check if we got a token
|
||
|
if (-not $token) {
|
||
|
Write-Error "Authentication failed"
|
||
|
exit
|
||
|
}
|
||
|
|
||
|
# Prepare the request header with the received token
|
||
|
$headers = @{
|
||
|
Authorization = "Bearer $token"
|
||
|
}
|
||
|
|
||
|
# Fetch the docs.json
|
||
|
$docs = Invoke-RestMethod -Uri $docsUrl
|
||
|
|
||
|
# Extract NotebookRuleInput model
|
||
|
$notebookRuleInputModel = $docs.definitions."rules.NotebookRuleInput".properties
|
||
|
|
||
|
# Create newNotebookParams based on the NotebookRuleInput model
|
||
|
$newNotebookParams = @{}
|
||
|
foreach ($prop in $notebookRuleInputModel.PSObject.Properties) {
|
||
|
$userInput = Read-Host -Prompt "Enter value for $($prop.Name)"
|
||
|
$newNotebookParams[$prop.Name] = $userInput
|
||
|
}
|
||
|
|
||
|
# Convert newNotebookParams to JSON
|
||
|
$newNotebookParamsJson = $newNotebookParams | ConvertTo-Json
|
||
|
|
||
|
# Send request to generate a new notebook
|
||
|
$newNotebookResponse = Invoke-RestMethod -Method Post -Uri $generateNotebookUrl -Headers $headers -Body $newNotebookParamsJson -ContentType "application/json"
|
||
|
|
||
|
# Output the response
|
||
|
Write-Output "New Notebook Response:"
|
||
|
$newNotebookResponse
|