{
  "slug": "trim-sendgrid-activity-api",
  "title": "Trim Sendgrid Activity API JSON Response",
  "metaDescription": "Trim sendgrid activity api json response. Map only UI fields from SendGrid before Frontend / Web parses JSON. RealComposer edge vault and client tokens kee",
  "headline": "Field-level SendGrid projection at the edge",
  "category": "slimmer",
  "categoryLabel": "Payload Slimmer",
  "urgency": 7,
  "clientPlatform": "Frontend / Web",
  "upstreamServices": [
    "SendGrid"
  ],
  "searchIntentQuery": "trim sendgrid activity api json response",
  "directAnswerSummary": "SendGrid responses include fields Frontend / Web never renders. Map id, status, and UI columns at the edge after calling https://api.sendgrid.com/v3/marketing/stats?start_date={{query.startDate}}.",
  "problem": {
    "title": "Unmapped SendGrid fields waste bandwidth",
    "explanation": "SendGrid returns nested CRM, audit, and configuration objects. Frontend / Web parses them on the main thread even when the UI binds three fields.",
    "risks": [
      "Large arrays kept in memory after navigation",
      "Analytics showing poor LCP on API-heavy screens",
      "Developers shipping defensive null checks for unused paths"
    ]
  },
  "solutionSteps": [
    {
      "stepNumber": 1,
      "title": "Bind vault keys to the Worker",
      "description": "Add SENDGRID_API_KEY to RealComposer Secret Vault. Values decrypt only inside the Cloudflare Worker that calls the upstream."
    },
    {
      "stepNumber": 2,
      "title": "Target the real upstream URL",
      "description": "Point step sendgrid at https://api.sendgrid.com/v3/marketing/stats?start_date={{query.startDate}} with GET. Map only the UI fields in output mapping so clients never download audit or nested blobs. Leave cache TTL at 0 when each response is user-specific (include userId or record id in query params before enabling cache)."
    },
    {
      "stepNumber": 3,
      "title": "Call from Frontend / Web",
      "description": "Call https://realcomposer.com/v1/workspace/trim-sendgrid-activity-api with a restricted rc_live_ client token. Frontend / Web never sends upstream secrets.",
      "codeSnippet": "const res = await fetch('https://realcomposer.com/v1/workspace/trim-sendgrid-activity-api', {\n  headers: { Authorization: 'Bearer rc_live_your_token' }\n});"
    }
  ],
  "pipelineConfig": {
    "name": "Trim Sendgrid Activity API JSON Response",
    "method": "GET",
    "cacheTtlSeconds": 0,
    "authMode": "client_token",
    "steps": [
      {
        "stepKey": "sendgrid",
        "upstreamUrlTemplate": "https://api.sendgrid.com/v3/marketing/stats?start_date={{query.startDate}}",
        "httpMethod": "GET",
        "headersTemplate": {
          "Authorization": "Bearer {{secrets.SENDGRID_API_KEY}}"
        },
        "timeoutMs": 3000
      }
    ],
    "outputMapping": {
      "version": 1,
      "fields": [
        {
          "targetPath": "delivered",
          "sourcePath": "0.stats.0.metrics.delivered",
          "type": "number",
          "sourceStep": "sendgrid"
        },
        {
          "targetPath": "opens",
          "sourcePath": "0.stats.0.metrics.opens",
          "type": "number",
          "sourceStep": "sendgrid"
        }
      ]
    }
  },
  "sampleBloatedInput": {
    "requestId": "req_trim-sen",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "trim-sendgrid-activity-api"
    },
    "payload": {
      "id": "sample_id",
      "status": "active",
      "nested": {
        "tags": [
          "demo"
        ],
        "internal": true
      },
      "unused_blob": {
        "foo": "bar",
        "bar": "baz"
      }
    }
  },
  "sampleSlimmedOutput": {
    "delivered": "sample",
    "opens": "sample"
  },
  "curlSnippet": "curl -X GET \"https://realcomposer.com/v1/workspace/trim-sendgrid-activity-api\" \\\n  -H \"Authorization: Bearer rc_live_client_token\"",
  "faqs": [
    {
      "question": "What should Frontend / Web store instead of SendGrid secrets?",
      "answer": "Log request IDs for trim-sendgrid-activity-api, not raw SendGrid payloads, because upstream bodies may include PII."
    },
    {
      "question": "How do I forward JSON bodies to POST upstreams?",
      "answer": "trim-sendgrid-activity-api vault headers attach server-side, but Anthropic or OpenAI model and messages must come from the client body."
    },
    {
      "question": "Can I restrict which domains call this pipeline?",
      "answer": "Rotate vault secrets for trim-sendgrid-activity-api anytime; clients keep the same rc_live_ token."
    }
  ],
  "relatedRecipeSlugs": [
    "mobile-friendly-api-from-legacy-rest",
    "optimize-api-response-size-react-native",
    "plaid-api-proxy-flutter"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/trim-sendgrid-activity-api",
    "markdown": "https://realcomposer.com/recipes/trim-sendgrid-activity-api.md",
    "json": "https://realcomposer.com/recipes/trim-sendgrid-activity-api.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=trim-sendgrid-activity-api&via=agent"
  }
}