Code Examples

Integration Examples

Real-world examples of integrating processa into your applications.

Node.js/TypeScript

Express

Complete example using Express.js with TypeScript.

import express from 'express'
import fetch from 'node-fetch'

const app = express()
app.use(express.json())

const PROCESSA_API_KEY = process.env.PROCESSA_API_KEY
const PROCESSA_BASE_URL = 'https://api.getprocessa.com/v1'

// Send content for approval
async function createDraft(title: string, content: any) {
  const response = await fetch(`${PROCESSA_BASE_URL}/drafts`, {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${PROCESSA_API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({ title, content })
  })

  return response.json()
}

// Webhook endpoint to receive approved content
app.post('/webhooks/processa', async (req, res) => {
  const { event, draft } = req.body

  if (event === 'draft.approved') {
    // Execute the approved action
    console.log('Executing approved action:', draft.title)

    // Example: send email
    if (draft.content.action === 'send_email') {
      await sendEmail(draft.content)
    }

    // Example: deploy code
    if (draft.content.action === 'deploy') {
      await deployToProduction(draft.content)
    }
  }

  res.status(200).json({ received: true })
})

// Example: AI agent wants to send an email
app.post('/ai/send-email', async (req, res) => {
  const { to, subject, body } = req.body

  // Send to processa instead of sending directly
  const draft = await createDraft('Send email', {
    action: 'send_email',
    to,
    subject,
    body
  })

  res.json({
    message: 'Email sent for approval',
    draftId: draft.id
  })
})

app.listen(3000)

Python

FastAPI

Example using FastAPI with async/await.

from fastapi import FastAPI, Request
import httpx
import os

app = FastAPI()

PROCESSA_API_KEY = os.getenv('PROCESSA_API_KEY')
PROCESSA_BASE_URL = 'https://api.getprocessa.com/v1'

async def create_draft(title: str, content: dict):
    async with httpx.AsyncClient() as client:
        response = await client.post(
            f'{PROCESSA_BASE_URL}/drafts',
            headers={
                'Authorization': f'Bearer {PROCESSA_API_KEY}',
                'Content-Type': 'application/json'
            },
            json={'title': title, 'content': content}
        )
        return response.json()

@app.post('/webhooks/processa')
async def handle_webhook(request: Request):
    data = await request.json()
    event = data['event']
    draft = data['draft']

    if event == 'draft.approved':
        # Execute the approved action
        print(f"Executing: {draft['title']}")

        if draft['content'].get('action') == 'send_email':
            await send_email(draft['content'])

    return {'received': True}

@app.post('/ai/database-query')
async def ai_database_query(request: Request):
    data = await request.json()
    query = data['query']

    # Send dangerous query for approval first
    draft = await create_draft(
        'Execute database query',
        {
            'action': 'database_query',
            'query': query,
            'database': 'production'
        }
    )

    return {
        'message': 'Query sent for approval',
        'draft_id': draft['id']
    }

Go

net/http

Example using Go's standard library.

package main

import (
    "bytes"
    "encoding/json"
    "net/http"
    "os"
)

type Draft struct {
    Title   string                 `json:"title"`
    Content map[string]interface{} `json:"content"`
}

func createDraft(title string, content map[string]interface{}) error {
    draft := Draft{Title: title, Content: content}
    body, _ := json.Marshal(draft)

    req, _ := http.NewRequest(
        "POST",
        "https://api.getprocessa.com/v1/drafts",
        bytes.NewBuffer(body),
    )

    apiKey := os.Getenv("PROCESSA_API_KEY")
    req.Header.Set("Authorization", "Bearer "+apiKey)
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        return err
    }
    defer resp.Body.Close()

    return nil
}

func webhookHandler(w http.ResponseWriter, r *http.Request) {
    var payload struct {
        Event string                 `json:"event"`
        Draft map[string]interface{} `json:"draft"`
    }

    json.NewDecoder(r.Body).Decode(&payload)

    if payload.Event == "draft.approved" {
        // Execute approved action
        content := payload.Draft["content"].(map[string]interface{})
        executeAction(content)
    }

    w.WriteHeader(http.StatusOK)
    json.NewEncoder(w).Encode(map[string]bool{"received": true})
}

func main() {
    http.HandleFunc("/webhooks/processa", webhookHandler)
    http.ListenAndServe(":8080", nil)
}

cURL

CLI

Quick testing with cURL commands.

Create a draft

curl -X POST https://api.getprocessa.com/v1/drafts \
  -H "Authorization: Bearer ${PROCESSA_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Deploy to production",
    "content": {
      "environment": "production",
      "branch": "main",
      "commit": "abc123"
    }
  }'

List all drafts

curl -X GET https://api.getprocessa.com/v1/drafts \
  -H "Authorization: Bearer ${PROCESSA_API_KEY}"

Approve a draft

curl -X POST https://api.getprocessa.com/v1/drafts/DRAFT_ID/approve \
  -H "Authorization: Bearer ${PROCESSA_API_KEY}"

Common Use Cases

AI Email Assistant

Before sending emails on behalf of users, route them through processa for review.

Deployment Automation

Let AI suggest deployments but require human approval before pushing to production.

Database Operations

Review DELETE or UPDATE queries generated by AI before execution.

Social Media Posts

Approve AI-generated social media content before publishing.

Financial Transactions

Require approval for payments or refunds suggested by AI agents.