Skip to Content
Examples & Workflows

Examples & Workflows

Practical examples showing how to use wfapi for common tasks and workflows.

Getting Started

First-Time Setup

Complete setup from scratch:

# Install globally npm install -g @sygnal/wfapi # Configure your API token wfapi config set wfp_your_token_here # List your sites wfapi sites # Set a site context wfapi use site 68f81168c2a32ba4ce25cfc3 # List collections wfapi cms # Set collection context wfapi use cms blog-posts # List items wfapi items

Content Management

Find Recently Updated Content

Check what’s changed in the last week:

# Set context wfapi use site my-site wfapi use cms blog-posts # View recent items wfapi items --recent

Search for Specific Items

Find items matching a search term:

# Find all "featured" posts wfapi items featured # Find "tutorial" posts wfapi items tutorial # Find items with "2024" in name wfapi items 2024

Export CMS Data

Export data to JSON for processing:

# Export all items wfapi items --raw > items.json # Export recent items wfapi items --recent --raw > recent-items.json # Export filtered items wfapi items "featured" --raw > featured-items.json # Export all sites wfapi sites --raw > sites.json

Content Audit

Audit content across multiple collections:

# Set site wfapi use site my-site # Check blog posts wfapi use cms blog-posts wfapi items --recent # Check team members wfapi use cms team-members wfapi items # Check projects wfapi use cms projects wfapi items --recent

Multi-Site Management

Compare Sites

List sites by different criteria:

# All sites wfapi sites # Client sites only wfapi sites client # Portfolio sites wfapi sites portfolio # Recently modified sites wfapi sites --recent

Switch Between Sites

Quick context switching:

# Work on Site A wfapi use site site-a-id wfapi cms wfapi use cms blog wfapi items # Switch to Site B wfapi use site site-b-id wfapi cms wfapi use cms news wfapi items

Multi-Environment Workflows

Development → Staging → Production

Set up three environments:

# Create environment configs echo "API_TOKEN=dev_token_here" > .wfapi.dev echo "API_TOKEN=staging_token_here" > .wfapi.staging echo "API_TOKEN=prod_token_here" > .wfapi.prod # Work in development wfapi env dev wfapi sites wfapi use site dev-site-id # Test in staging wfapi env staging wfapi sites wfapi use site staging-site-id # Deploy to production wfapi env prod wfapi sites # Red badge warns you wfapi use site prod-site-id wfapi items --recent # Verify recent changes

Environment-Specific Context

Each environment can have its own site/collection context:

# Development environment wfapi env dev wfapi use site dev-site-id wfapi use cms blog-posts wfapi items # Production environment wfapi env prod wfapi use site prod-site-id wfapi use cms blog-posts # Same collection, different site wfapi items

Compare Across Environments

Check content differences between environments:

# Get dev items wfapi env dev wfapi use site dev-site wfapi use cms products wfapi items --raw > dev-products.json # Get prod items wfapi env prod wfapi use site prod-site wfapi use cms products wfapi items --raw > prod-products.json # Compare files (using external tool) diff dev-products.json prod-products.json

Team Collaboration

Shared Project Configuration

Set up a project for team collaboration:

# Create example config (commit to git) cat > .wfapi.example << EOF API_TOKEN=your_token_here SITE_ID= COLLECTION_ID= EOF # Add to .gitignore echo ".wfapi" >> .gitignore echo ".wfapi.*" >> .gitignore # Team members copy and configure cp .wfapi.example .wfapi # Edit .wfapi with actual token

Individual Developer Environments

Each developer can use their own environment:

# Developer 1 echo "API_TOKEN=dev1_token" > .wfapi.dev1 wfapi env dev1 # Developer 2 echo "API_TOKEN=dev2_token" > .wfapi.dev2 wfapi env dev2

Automation & Scripting

Bash Script Example

Automate content reporting:

#!/bin/bash # report.sh - Generate weekly content report # Set environment export WEBFLOW_API_TOKEN="your_token_here" # Report directory mkdir -p reports DATE=$(date +%Y-%m-%d) # Export recent sites wfapi sites --recent --raw > "reports/sites-${DATE}.json" # Set site context wfapi use site my-site-id # Export all collections for collection in blog-posts news-items team-members; do wfapi use cms "$collection" wfapi items --recent --raw > "reports/${collection}-${DATE}.json" echo "Exported $collection" done echo "Report generated in reports/"

PowerShell Script Example

Windows automation:

# report.ps1 - Generate content report # Set token $env:WEBFLOW_API_TOKEN = "your_token_here" # Create report directory $date = Get-Date -Format "yyyy-MM-dd" New-Item -Path "reports" -ItemType Directory -Force # Export sites wfapi sites --raw | Out-File "reports/sites-$date.json" # Set site wfapi use site my-site-id # Export collections $collections = @("blog-posts", "news-items", "team-members") foreach ($collection in $collections) { wfapi use cms $collection wfapi items --raw | Out-File "reports/$collection-$date.json" Write-Host "Exported $collection" } Write-Host "Report generated in reports/"

Node.js Integration

Use wfapi in Node.js scripts:

// export-data.js const { execSync } = require('child_process'); const fs = require('fs'); // Execute wfapi commands function wfapi(command) { return execSync(`wfapi ${command}`, { encoding: 'utf8' }); } // Get sites as JSON const sitesJson = wfapi('sites --raw'); const sites = JSON.parse(sitesJson); console.log(`Found ${sites.length} sites`); // Export each site's collections sites.forEach(site => { console.log(`Processing: ${site.displayName}`); // Set site context wfapi(`use site ${site.id}`); // Get collections const collectionsJson = wfapi('cms --raw'); const collections = JSON.parse(collectionsJson); // Export items from each collection collections.forEach(collection => { wfapi(`use cms ${collection.id}`); const itemsJson = wfapi('items --raw'); const filename = `data/${site.shortName}-${collection.slug}.json`; fs.writeFileSync(filename, itemsJson); console.log(` Exported: ${filename}`); }); });

CI/CD Pipeline

Integrate with GitHub Actions:

# .github/workflows/webflow-audit.yml name: Webflow Content Audit on: schedule: - cron: '0 9 * * 1' # Every Monday at 9am workflow_dispatch: jobs: audit: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup Node.js uses: actions/setup-node@v3 with: node-version: '18' - name: Install wfapi run: npm install -g @sygnal/wfapi - name: Export content env: WEBFLOW_API_TOKEN: ${{ secrets.WEBFLOW_API_TOKEN }} run: | mkdir -p reports wfapi sites --raw > reports/sites.json wfapi use site ${{ secrets.SITE_ID }} wfapi use cms blog-posts wfapi items --recent --raw > reports/recent-posts.json - name: Upload reports uses: actions/upload-artifact@v3 with: name: webflow-reports path: reports/

Data Analysis

Count Items

Count CMS items using jq:

# Count total items wfapi items --raw | jq '. | length' # Count recent items wfapi items --recent --raw | jq '. | length' # Count by status (if available in data) wfapi items --raw | jq '[.[] | select(.isPublished)] | length'

Extract Specific Fields

Extract just the fields you need:

# Get item names and slugs wfapi items --raw | jq '.[] | {name: .name, slug: .slug}' # Get item IDs wfapi items --raw | jq '.[].id' # Create CSV wfapi items --raw | jq -r '.[] | [.name, .slug, .id] | @csv' > items.csv

Find Duplicates

Check for duplicate slugs:

# Extract slugs wfapi items --raw | jq -r '.[].slug' | sort > slugs.txt # Find duplicates sort slugs.txt | uniq -d

Productivity Tips

Alias Common Commands

Add to your shell profile (.bashrc, .zshrc, etc.):

# Quick shortcuts alias wf='wfapi' alias wfs='wfapi sites' alias wfc='wfapi cms' alias wfi='wfapi items' alias wfu='wfapi use' # Environment shortcuts alias wfdev='wfapi env dev' alias wfstage='wfapi env staging' alias wfprod='wfapi env prod' # Common workflows alias wfrecent='wfapi items --recent' alias wfexport='wfapi items --raw'

Usage:

wf sites # Instead of wfapi sites wfdev # Switch to dev wfu site my-site # Set site context wfrecent # Show recent items

Shell Functions

Create reusable functions:

# Switch to site and collection in one command wfset() { wfapi use site "$1" wfapi use cms "$2" } # Usage wfset my-site-id blog-posts

Quick Context Switching

Save frequently used contexts:

# .wfapi.blog API_TOKEN=your_token SITE_ID=blog_site_id COLLECTION_ID=blog_posts_id # .wfapi.ecommerce API_TOKEN=your_token SITE_ID=shop_site_id COLLECTION_ID=products_id # Switch contexts cp .wfapi.blog .wfapi # Work on blog cp .wfapi.ecommerce .wfapi # Work on ecommerce

Troubleshooting Examples

Debug Configuration

Check what config is being used:

# Show current environment wfapi env # Show current token wfapi config show # Show current context wfapi use

Test Permissions

Verify your API token has correct permissions:

# Can you list sites? wfapi sites # Can you list collections? wfapi use site <site-id> wfapi cms # Can you list items? wfapi use cms <collection-slug> wfapi items

Environment Issues

Debug environment configuration:

# Check which config files exist ls -la .wfapi* ls -la ~/.wfapi* # View config contents (careful with tokens!) cat .wfapi cat .wfapi.dev # Check environment variable echo $WEBFLOW_API_TOKEN # Check current environment wfapi env

Advanced Patterns

Bulk Export All Collections

Export all collections from a site:

#!/bin/bash SITE_ID="your-site-id" wfapi use site "$SITE_ID" # Get collections as JSON COLLECTIONS=$(wfapi cms --raw) # Loop through collections echo "$COLLECTIONS" | jq -c '.[]' | while read collection; do SLUG=$(echo "$collection" | jq -r '.slug') ID=$(echo "$collection" | jq -r '.id') echo "Exporting $SLUG..." wfapi use cms "$ID" wfapi items --raw > "export-${SLUG}.json" done echo "Export complete!"

Daily Backup Script

Automate daily backups:

#!/bin/bash # config BACKUP_DIR="backups/$(date +%Y-%m-%d)" mkdir -p "$BACKUP_DIR" # Sites backup wfapi sites --raw > "$BACKUP_DIR/sites.json" # Set site SITE_ID="your-site-id" wfapi use site "$SITE_ID" # Backup each collection for collection in blog-posts team-members projects; do wfapi use cms "$collection" wfapi items --raw > "$BACKUP_DIR/${collection}.json" done echo "Backup saved to $BACKUP_DIR"

Content Migration Helper

Compare content between sites:

#!/bin/bash # Source site wfapi use site source-site-id wfapi use cms blog-posts wfapi items --raw > source-items.json # Destination site wfapi use site dest-site-id wfapi use cms blog-posts wfapi items --raw > dest-items.json # Find differences echo "Items in source but not in destination:" comm -23 \ <(jq -r '.[].slug' source-items.json | sort) \ <(jq -r '.[].slug' dest-items.json | sort)

Next Steps

These examples should give you a solid foundation for using wfapi in your workflows. For complete command documentation, see the Commands Reference.

Additional Resources

Last updated on