Skip to main content

PowerShell Quickstart

This guide walks through a complete Praeto Dispatcher flow using PowerShell. It covers:
  1. Health check
  2. Tenant creation
  3. API key creation
  4. Endpoint creation
  5. Event publishing
  6. Idempotency verification
  7. Delivery attempt inspection
  8. Usage and metrics inspection

1. Set variables

$BaseUrl = "https://api.praeto.dev"
$AdminApiKey = "YOUR_ADMIN_API_KEY"
If you already have a tenant API key:
$ApiKey = "praeto_live_YOUR_TENANT_KEY"

2. Health check

Invoke-RestMethod "$BaseUrl/health"
Expected:
{
  "status": "healthy",
  "database": "connected",
  "timestamp": "2026-04-28T09:00:00.000Z"
}

3. Create or update tenant

Invoke-RestMethod -Method POST `
  -Uri "$BaseUrl/v1/admin/tenants" `
  -Headers @{ Authorization = "Bearer $AdminApiKey" } `
  -ContentType "application/json" `
  -Body (@{
    tenant_id = "default"
    tenant_slug = "default"
  } | ConvertTo-Json)

4. Create tenant API key

$key = Invoke-RestMethod -Method POST `
  -Uri "$BaseUrl/v1/admin/api-keys" `
  -Headers @{ Authorization = "Bearer $AdminApiKey" } `
  -ContentType "application/json" `
  -Body (@{
    tenant_id = "default"
    name = "quickstart-key"
  } | ConvertTo-Json)

$key
Save the returned key:
$ApiKey = $key.api_key
$env:PRAETO_API_KEY = $ApiKey

5. Create endpoint

$EndpointUrl = "https://webhook.site/YOUR-UUID"

$endpointResponse = Invoke-RestMethod -Method POST `
  -Uri "$BaseUrl/v1/endpoints" `
  -Headers @{ Authorization = "Bearer $ApiKey" } `
  -ContentType "application/json" `
  -Body (@{
    url = $EndpointUrl
    description = "PowerShell quickstart endpoint"
    subscribed_events = @("test.event", "invoice.created")
  } | ConvertTo-Json)

$endpointResponse
Save:
$EndpointId = $endpointResponse.endpoint.endpoint_id
$SigningSecret = $endpointResponse.signing_secret
The signing secret is only returned on create and rotate. Store it securely.

6. Publish event

$IdempotencyKey = "quickstart-test-$([guid]::NewGuid().ToString())"

$eventResponse = Invoke-RestMethod -Method POST `
  -Uri "$BaseUrl/v1/events" `
  -Headers @{
    Authorization = "Bearer $ApiKey"
    "Idempotency-Key" = $IdempotencyKey
  } `
  -ContentType "application/json" `
  -Body (@{
    event_type = "test.event"
    payload = @{
      message = "Hello from PowerShell"
      timestamp = (Get-Date).ToString("o")
    }
  } | ConvertTo-Json -Depth 5)

$eventResponse
Save:
$EventId = $eventResponse.event_id
$DeliveryId = $eventResponse.delivery_ids[0]

7. Test idempotency

Send the exact same request again with the same Idempotency-Key and exact same body.
# Store the original body so it stays identical
$body = @{
  event_type = "test.event"
  payload = @{
    message = "idempotency test"
    value = 123
  }
} | ConvertTo-Json -Depth 5

$key = "idem-$([guid]::NewGuid().ToString())"

$r1 = Invoke-RestMethod -Method POST `
  -Uri "$BaseUrl/v1/events" `
  -Headers @{
    Authorization = "Bearer $ApiKey"
    "Idempotency-Key" = $key
  } `
  -ContentType "application/json" `
  -Body $body

$r2 = Invoke-RestMethod -Method POST `
  -Uri "$BaseUrl/v1/events" `
  -Headers @{
    Authorization = "Bearer $ApiKey"
    "Idempotency-Key" = $key
  } `
  -ContentType "application/json" `
  -Body $body

$r1
$r2
Expected second response:
{
  "ok": true,
  "duplicate": true,
  "idempotent_replay": true,
  "message": "event already accepted for this idempotency key"
}

8. Inspect event deliveries

Invoke-RestMethod `
  -Uri "$BaseUrl/v1/events/$EventId/deliveries" `
  -Headers @{ Authorization = "Bearer $ApiKey" }

9. Inspect delivery attempts

Invoke-RestMethod `
  -Uri "$BaseUrl/v1/deliveries/$DeliveryId/attempts" `
  -Headers @{ Authorization = "Bearer $ApiKey" }

10. Check endpoint health

Invoke-RestMethod `
  -Uri "$BaseUrl/v1/endpoints/$EndpointId/health" `
  -Headers @{ Authorization = "Bearer $ApiKey" }

11. Check metrics summary

Invoke-RestMethod `
  -Uri "$BaseUrl/v1/metrics/summary" `
  -Headers @{ Authorization = "Bearer $ApiKey" }

12. Check usage

Invoke-RestMethod `
  -Uri "$BaseUrl/v1/usage/current" `
  -Headers @{ Authorization = "Bearer $ApiKey" }

13. Rotate endpoint signing secret

Invoke-RestMethod -Method POST `
  -Uri "$BaseUrl/v1/endpoints/$EndpointId/rotate-secret" `
  -Headers @{ Authorization = "Bearer $ApiKey" }
The response returns the new secret and the previous secret validity window.

14. Replay delivery

Invoke-RestMethod -Method POST `
  -Uri "$BaseUrl/v1/deliveries/$DeliveryId/replay" `
  -Headers @{ Authorization = "Bearer $ApiKey" }