# 🔌 AutoZap Templates — Zap Cheat Codes

This page is the “quick-start brain” for your Zapier automations. Copy/paste patterns for Webhooks → Scheduler → Delay Until → Formatter → Router → Platform Actions.

Webhook Delay Until Formatter Paths Retries Rate limits

← Back to SZAM Hub

## 1) Webhook intake (SZAM → Zapier)

Use Webhooks by Zapier → Catch Hook. Expect JSON payload from SMM publish button.

    {
      "title": "{{title}}",
      "body": "{{html}}",
      "tags": "tag1,tag2,tag3",
      "media": {
        "image_url": "https://...",
        "video_url": "https://..."
      },
      "region": "Americas|China|Thailand|India|Portugal",
      "post_type": "class|short|blog|promo",
      "status": "NEW"
    }

## 2) Best-time scheduling (Delay Until)

Call your scheduler endpoint, then feed the result into Delay Until.

    Step A: Webhooks by Zapier → GET
    URL: https://YOURDOMAIN.com/szam/scheduler/public/api/next_best_time.php?region={{region}}&type={{post_type}}

    Step B: Delay by Zapier → Delay Until
    Time: {{scheduler.next_run}}

## 3) Formatter “Cheat Codes”

Common Zapier formatter tricks.

    # Trim to 280 chars (X/Twitter)
    Formatter → Text → Truncate
    Input: {{caption}}
    Length: 280

    # Hashtag list
    Formatter → Text → Replace
    Find: " "
    Replace: ","

## 4) Router logic (Paths)

Send different content to different platforms based on type or region.

    Paths by Zapier
    IF post_type = "short"  → TikTok / YT Shorts / IG Reels
    IF post_type = "class"  → YouTube (private) + email members
    IF region = "China"     → Weibo/WeChat-compatible actions

## 5) Retry + rate-limit pattern

Use Storage + Delay for soft retries when APIs rate limit.

    Storage → Get retry_count
    IF retry_count < 3:
      Delay 10 minutes
      Increment retry_count
      Retry platform action
    ELSE:
      Send alert email / Slack

## 6) Copy/paste “Zap skeleton”

Minimal stable skeleton you can clone.

    1. Catch Hook (Webhook)
    2. GET next_best_time.php (Scheduler)
    3. Delay Until next_run
    4. Formatter (caption, hashtags, truncation)
    5. Paths (short/class/blog)
    6. Platform Action(s)
    7. Log result (Google Sheet / Airtable)