Webhook Setup

Webhooks let your agent receive real-time notifications when swaps complete or fail, instead of polling GET /swap/status. Suwappu sends an HTTP POST request to your callback URL whenever a swap event occurs.

How It Works

  1. Set your callback URL -- Update your agent profile with PATCH /me

  2. Test delivery -- Send a test webhook to verify your endpoint works

  3. Handle events -- Process incoming webhook payloads in your application

  4. Monitor -- View recent webhook events via GET /webhooks

Step 1: Set Your Callback URL

Configure the webhook endpoint in your agent profile:

curl -X PATCH https://api.suwappu.bot/v1/agent/me \
  -H "Authorization: Bearer suwappu_sk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"callback_url": "https://your-server.com/webhooks/suwappu"}'

Response

{
  "success": true,
  "agent": {
    "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "name": "my-trading-bot",
    "description": "Automated portfolio rebalancer",
    "rate_limit_tier": "standard",
    "stats": {
      "total_requests": 14833,
      "total_swaps": 247
    },
    "created_at": "2026-01-15T08:30:00Z",
    "last_active_at": "2026-03-07T14:25:00Z"
  }
}

To remove the webhook, set callback_url to null:

Step 2: Test Webhook Delivery

Send a test event to verify your endpoint is reachable and working:

This sends a test payload to your configured callback_url. Check your server logs to confirm receipt.

Step 3: Handle Webhook Events

Event Types

Event
Description

swap.completed

A swap has been confirmed on-chain

swap.failed

A swap transaction reverted or could not be confirmed

Webhook Payload

Suwappu sends a POST request to your callback URL with a JSON body:

Your endpoint should return a 200 status code to acknowledge receipt. If the endpoint returns a non-2xx status or times out, Suwappu will retry delivery.

Step 4: View Webhook Events

List recent webhook deliveries for your agent:

Complete Example: curl

Complete Example: Python Flask Receiver

A minimal webhook receiver using Flask:

Install dependencies:

Run the receiver:

Complete Example: Python Setup Script

A script that configures the webhook and tests it:

Complete Example: TypeScript

Webhook Receiver in TypeScript (Node.js)

A minimal receiver using the built-in Node.js HTTP server:

Tips

  • Use HTTPS for your callback URL. Suwappu will not deliver webhooks to plain HTTP endpoints in production.

  • Respond quickly. Return a 200 status code as fast as possible. Process the event asynchronously if your handler involves heavy work.

  • Idempotency. Webhooks may be delivered more than once. Use the swap_id to deduplicate events.

  • Verify the source. Check that incoming requests originate from Suwappu by validating headers or using a secret path in your callback URL.

Last updated