cURL Examples

Command-line examples using cURL for quick API testing and shell script integration.

Configuration

Set your API key as an environment variable for easier usage:

# Set your API key
export ADBOT_API_KEY="your_api_key_here"

# Base URL
export ADBOT_API="https://api.adbot.fi"

List Templates

curl -X GET "$ADBOT_API/api/templates" \
  -H "Authorization: Bearer $ADBOT_API_KEY" \
  -H "Content-Type: application/json"

Response

{
  "success": true,
  "data": [
    {
      "id": "tpl_social_v1",
      "name": "Social Media Video",
      "description": "Vertical video for TikTok and Instagram",
      "formats": ["1080x1920", "1080x1080", "1920x1080"]
    }
  ]
}

Get Template Configuration

curl -X GET "$ADBOT_API/api/templates/tpl_social_v1/configs" \
  -H "Authorization: Bearer $ADBOT_API_KEY" \
  -H "Content-Type: application/json"

Create a Video

curl -X POST "$ADBOT_API/api/templates/tpl_social_v1/materials" \
  -H "Authorization: Bearer $ADBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Summer Sale Video",
    "data": {
      "headline": "Summer Sale - 50% Off!",
      "productImage": "https://example.com/product.png",
      "ctaText": "Shop Now"
    },
    "outputs": ["1080x1920", "1080x1080"]
  }'

Response

{
  "success": true,
  "data": {
    "id": "mat_abc123",
    "name": "Summer Sale Video",
    "templateId": "tpl_social_v1",
    "status": "processing",
    "outputs": ["1080x1920", "1080x1080"],
    "createdAt": "2024-01-15T10:30:00Z"
  }
}

Check Material Status

curl -X GET "$ADBOT_API/api/materials/mat_abc123" \
  -H "Authorization: Bearer $ADBOT_API_KEY" \
  -H "Content-Type: application/json"

Response (Ready)

{
  "success": true,
  "data": {
    "id": "mat_abc123",
    "name": "Summer Sale Video",
    "status": "ready",
    "videos": [
      {
        "format": "1080x1920",
        "url": "https://cdn.adbot.fi/videos/mat_abc123_1080x1920.mp4"
      },
      {
        "format": "1080x1080",
        "url": "https://cdn.adbot.fi/videos/mat_abc123_1080x1080.mp4"
      }
    ]
  }
}

Poll Until Ready (Bash Script)

#!/bin/bash

MATERIAL_ID="mat_abc123"
TIMEOUT=120
INTERVAL=3
ELAPSED=0

echo "Waiting for material $MATERIAL_ID..."

while [ $ELAPSED -lt $TIMEOUT ]; do
  RESPONSE=$(curl -s -X GET "$ADBOT_API/api/materials/$MATERIAL_ID" \
    -H "Authorization: Bearer $ADBOT_API_KEY" \
    -H "Content-Type: application/json")

  STATUS=$(echo $RESPONSE | jq -r '.data.status')

  case $STATUS in
    "ready")
      echo "Material is ready!"
      echo $RESPONSE | jq '.data.videos'
      exit 0
      ;;
    "failed")
      echo "Material generation failed!"
      exit 1
      ;;
    *)
      echo "Status: $STATUS ($${ELAPSED}s elapsed)"
      sleep $INTERVAL
      ELAPSED=$((ELAPSED + INTERVAL))
      ;;
  esac
done

echo "Timeout waiting for material"
exit 1

Upload Image

curl -X POST "$ADBOT_API/api/assets/upload" \
  -H "Authorization: Bearer $ADBOT_API_KEY" \
  -F "file=@/path/to/product.png" \
  -F "name=My Product Image"

Response

{
  "success": true,
  "data": {
    "id": "asset_xyz789",
    "name": "My Product Image",
    "url": "https://cdn.adbot.fi/assets/asset_xyz789.png",
    "type": "image",
    "size": 245678,
    "createdAt": "2024-01-15T10:35:00Z"
  }
}

Remove Background

curl -X POST "$ADBOT_API/api/assets/remove-background" \
  -H "Authorization: Bearer $ADBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "assetId": "asset_xyz789"
  }'

List Materials

# List all materials
curl -X GET "$ADBOT_API/api/materials" \
  -H "Authorization: Bearer $ADBOT_API_KEY" \
  -H "Content-Type: application/json"

# With pagination
curl -X GET "$ADBOT_API/api/materials?page=1&limit=20" \
  -H "Authorization: Bearer $ADBOT_API_KEY" \
  -H "Content-Type: application/json"

# Filter by status
curl -X GET "$ADBOT_API/api/materials?status=ready" \
  -H "Authorization: Bearer $ADBOT_API_KEY" \
  -H "Content-Type: application/json"

Update Material

curl -X PUT "$ADBOT_API/api/materials/mat_abc123" \
  -H "Authorization: Bearer $ADBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Updated Campaign Video",
    "data": {
      "headline": "Winter Sale - 60% Off!"
    }
  }'

Delete Material

curl -X DELETE "$ADBOT_API/api/materials/mat_abc123" \
  -H "Authorization: Bearer $ADBOT_API_KEY" \
  -H "Content-Type: application/json"

Generate Preview

curl -X POST "$ADBOT_API/api/templates/tpl_social_v1/preview" \
  -H "Authorization: Bearer $ADBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "data": {
      "headline": "Preview Text",
      "productImage": "https://example.com/product.png"
    },
    "format": "1080x1920"
  }'

Create Project

curl -X POST "$ADBOT_API/api/projects" \
  -H "Authorization: Bearer $ADBOT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Q1 Marketing Campaign",
    "description": "Videos for Q1 2024 campaign"
  }'

Authentication with Token

# Login to get token
TOKEN_RESPONSE=$(curl -s -X POST "$ADBOT_API/api/auth/login" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "password": "your_password"
  }')

# Extract token
TOKEN=$(echo $TOKEN_RESPONSE | jq -r '.data.accessToken')

# Use token for subsequent requests
curl -X GET "$ADBOT_API/api/materials" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json"

Useful jq Commands

# Pretty print response
curl ... | jq '.'

# Get specific field
curl ... | jq '.data.id'

# List all template names
curl ... | jq '.data[].name'

# Filter by status
curl ... | jq '.data | map(select(.status == "ready"))'

# Get video URLs only
curl ... | jq '.data.videos[].url'

# Count items
curl ... | jq '.data | length'