> ## Documentation Index
> Fetch the complete documentation index at: https://docs.praeto.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# PowerShell Quickstart

> Complete Praeto Dispatcher workflow using PowerShell.

# 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

```powershell theme={null}
$BaseUrl = "https://api.praeto.dev"
$AdminApiKey = "YOUR_ADMIN_API_KEY"
```

If you already have a tenant API key:

```powershell theme={null}
$ApiKey = "praeto_live_YOUR_TENANT_KEY"
```

***

## 2. Health check

```powershell theme={null}
Invoke-RestMethod "$BaseUrl/health"
```

Expected:

```json theme={null}
{
  "status": "healthy",
  "database": "connected",
  "timestamp": "2026-04-28T09:00:00.000Z"
}
```

***

## 3. Create or update tenant

```powershell theme={null}
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

```powershell theme={null}
$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:

```powershell theme={null}
$ApiKey = $key.api_key
$env:PRAETO_API_KEY = $ApiKey
```

***

## 5. Create endpoint

```powershell theme={null}
$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:

```powershell theme={null}
$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

```powershell theme={null}
$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:

```powershell theme={null}
$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.

```powershell theme={null}
# 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:

```json theme={null}
{
  "ok": true,
  "duplicate": true,
  "idempotent_replay": true,
  "message": "event already accepted for this idempotency key"
}
```

***

## 8. Inspect event deliveries

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

***

## 9. Inspect delivery attempts

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

***

## 10. Check endpoint health

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

***

## 11. Check metrics summary

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

***

## 12. Check usage

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

***

## 13. Rotate endpoint signing secret

```powershell theme={null}
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

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