{
  "slug": "aggregate-contentful-with-algolia-search",
  "title": "Aggregate contentful content with algolia search",
  "metaTitle": "Aggregate contentful content with - RealComposer",
  "metaDescription": "Aggregate contentful content with algolia search. Merge Contentful and Algolia in one Next.js / React call with parallel Worker steps.",
  "headline": "Headless site search with CMS hits",
  "category": "aggregation",
  "categoryLabel": "Multi-API Aggregation",
  "urgency": 8,
  "clientPlatform": "Next.js / React",
  "upstreamServices": [
    "Contentful",
    "Algolia"
  ],
  "searchIntentQuery": "aggregate contentful content with algolia search",
  "directAnswerSummary": "Algolia search results enriched with Contentful entry fields at edge. For \"aggregate contentful content with algolia search\", store CONTENTFUL_ACCESS_TOKEN, ALGOLIA_API_KEY in Secret Vault, call https://cdn.contentful.com/spaces/{{query.spaceId}}/entries from a Worker, and let Next.js / React hit only https://realcomposer.com/v1/workspace/aggregate-contentful-with-algolia-search with an rc_live_ client token. POST upstream calls are not stored in caches.default; clients must send JSON bodies and headers forward unchanged.",
  "problem": {
    "title": "Waterfall latency from multiple Contentful and Algolia requests",
    "explanation": "Next.js / React widgets often await Contentful and Algolia sequentially, multiplying TLS handshakes on cellular networks and amplifying failure rates.",
    "risks": [
      "Race conditions between parallel manual fetches",
      "Higher mobile data usage from redundant JSON",
      "Timeouts when any upstream exceeds cellular RTT"
    ]
  },
  "solutionSteps": [
    {
      "stepNumber": 1,
      "title": "Store upstream credentials in Secret Vault",
      "description": "Create CONTENTFUL_ACCESS_TOKEN, ALGOLIA_API_KEY vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders."
    },
    {
      "stepNumber": 2,
      "title": "Configure upstream steps and output mapping",
      "description": "Point step contentful at https://cdn.contentful.com/spaces/{{query.spaceId}}/entries with POST. Add output mapping fields that mirror the JSON contract your screen already expects. POST pipelines set cache TTL to 0 because RealComposer only stores GET responses at the edge."
    },
    {
      "stepNumber": 3,
      "title": "Call from Next.js / React",
      "description": "Allowed origins on the token should list every Next.js / React host that calls this URL.",
      "codeSnippet": "// app/api route or client component\nconst res = await fetch('https://realcomposer.com/v1/workspace/aggregate-contentful-with-algolia-search', {\n  cache: 'no-store',\n  headers: { Authorization: 'Bearer rc_live_your_token' }\n});"
    }
  ],
  "pipelineConfig": {
    "name": "Aggregate contentful content with algolia search",
    "method": "POST",
    "cacheTtlSeconds": 0,
    "authMode": "client_token",
    "steps": [
      {
        "stepKey": "contentful",
        "upstreamUrlTemplate": "https://cdn.contentful.com/spaces/{{query.spaceId}}/entries",
        "httpMethod": "GET",
        "headersTemplate": {
          "Authorization": "Bearer {{secrets.CONTENTFUL_ACCESS_TOKEN}}"
        },
        "timeoutMs": 3000
      },
      {
        "stepKey": "algolia",
        "upstreamUrlTemplate": "https://{{secrets.ALGOLIA_APP_ID}}-dsn.algolia.net/1/indexes/{{query.index}}/query",
        "httpMethod": "POST",
        "headersTemplate": {
          "X-Algolia-API-Key": "{{secrets.ALGOLIA_API_KEY}}",
          "X-Algolia-Application-Id": "{{secrets.ALGOLIA_APP_ID}}",
          "Content-Type": "application/json"
        },
        "timeoutMs": 10000
      }
    ],
    "outputMapping": {
      "version": 1,
      "fields": [
        {
          "targetPath": "contentful.entryId",
          "sourcePath": "items.0.sys.id",
          "type": "string",
          "sourceStep": "contentful"
        },
        {
          "targetPath": "contentful.title",
          "sourcePath": "items.0.fields.title",
          "type": "string",
          "sourceStep": "contentful"
        },
        {
          "targetPath": "algolia.hitCount",
          "sourcePath": "nbHits",
          "type": "number",
          "sourceStep": "algolia"
        },
        {
          "targetPath": "algolia.firstHit",
          "sourcePath": "hits.0.objectID",
          "type": "string",
          "sourceStep": "algolia"
        }
      ]
    }
  },
  "sampleBloatedInput": {
    "requestId": "req_aggregat",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "aggregate-contentful-with-algolia-search"
    },
    "payload": {
      "id": "sample_id",
      "status": "active",
      "nested": {
        "tags": [
          "demo"
        ],
        "internal": true
      },
      "unused_blob": {
        "foo": "bar",
        "bar": "baz"
      }
    }
  },
  "sampleSlimmedOutput": {
    "contentful_entryId": "sample",
    "contentful_title": "sample",
    "algolia_hitCount": "sample",
    "algolia_firstHit": "sample"
  },
  "curlSnippet": "curl -X POST \"https://realcomposer.com/v1/workspace/aggregate-contentful-with-algolia-search\" \\\n  -H \"Authorization: Bearer rc_live_client_token\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"model\":\"example\"}'",
  "faqs": [
    {
      "question": "Is it safe to log Contentful responses in Next.js / React?",
      "answer": "Use scoped tokens where the vendor allows them on aggregate-contentful-with-algolia-search. Admin keys stay {{secrets.*}} references only."
    },
    {
      "question": "When does edge caching apply to this recipe?",
      "answer": "aggregate-contentful-with-algolia-search keeps cache TTL at 0 because it uses POST upstream calls or per-user responses. Add ids to query strings before enabling GET cache."
    },
    {
      "question": "Can I restrict which domains call this pipeline?",
      "answer": "Allowed origins on the aggregate-contentful-with-algolia-search client token restrict which domains may call the edge URL."
    }
  ],
  "relatedRecipeSlugs": [
    "combine-algolia-search-with-user-favorites",
    "stitch-contentful-with-shopify-products"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/aggregate-contentful-with-algolia-search",
    "markdown": "https://realcomposer.com/recipes/aggregate-contentful-with-algolia-search.md",
    "json": "https://realcomposer.com/recipes/aggregate-contentful-with-algolia-search.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=aggregate-contentful-with-algolia-search&via=agent"
  }
}