# Daily horoscopes in Webflow CMS, refreshed by a scheduled job

> A Webflow site has no server code of its own, and anything in an Embed element or custom code is public. So the AstroNode call does not belong on the page at all: a scheduled job writes each sign's reading into a CMS collection once a day, and your designed template pages display it.

Source: https://astronode.dev/integrations/webflow · Updated: 2026-12-05

**How this page was verified:** Webflow was not contacted. The sync script was executed on Node 24 against the in-memory API for the twelve horoscope calls, and against a local stand-in for the Webflow Data API v2 item routes it uses (list, create, update, publish) that recorded every request. Run twice: the first run created 12 items, the second updated the same 12.

## Where the code runs

Readers never trigger an AstroNode call. A job running somewhere with a scheduler - a cron entry on a server, a scheduled CI workflow, a serverless function with a cron trigger - fetches the twelve readings and writes them through the Webflow Data API. If you host server code alongside the site with Webflow Cloud, the script can live there, but something still has to start it every day. Either way it is twelve AstroNode calls a day, however much traffic the pages get, and the `/v1/horoscope/daily/:sign` endpoint is on the **Free** plan.

## The collection

*A `Horoscopes` collection, one item per sign*

| Field | Type | Field slug used by the API |
| --- | --- | --- |
| Name | built-in | `name` |
| Slug | built-in | `slug` - `aries`, `taurus`... so the page URL never changes |
| Reading date | Plain text | `reading-date` |
| Summary | Plain text | `summary` |
| Focus areas | Rich text | `focus-areas` |
| Cautions | Rich text | `cautions` |

The collection's template page lays out one sign; a collection list on a hub page shows all twelve. Generate a site API token with CMS read and write access in the site's settings and give it, the collection's ID and the AstroNode key to the job as environment variables - neither token ever appears in the Designer.

## The sync script

`sync-horoscopes.mjs` (Node 18+, no dependencies):

```js
// Run once a day by any scheduler (cron, a CI schedule, a serverless cron trigger).
const ASTRONODE = process.env.ASTRONODE_BASE_URL ?? "https://api.astronode.dev";
const WEBFLOW = process.env.WEBFLOW_BASE_URL ?? "https://api.webflow.com";
const COLLECTION = process.env.WEBFLOW_COLLECTION_ID;
const SIGNS = ["Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"];

const webflow = (path, init = {}) =>
  fetch(`${WEBFLOW}/v2/collections/${COLLECTION}${path}`, {
    ...init,
    headers: { Authorization: `Bearer ${process.env.WEBFLOW_TOKEN}`, "Content-Type": "application/json" },
  }).then(async (r) => {
    if (!r.ok) throw new Error(`Webflow ${r.status}: ${await r.text()}`);
    return r.json();
  });

const esc = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
const list = (items) => `<ul>${items.map((i) => `<li>${esc(i)}</li>`).join("")}</ul>`;

// "Today" for your readers, not for the machine running the job (often UTC).
const date = new Intl.DateTimeFormat("en-CA", { timeZone: "Asia/Kolkata" }).format(new Date());

// Existing items, keyed by slug - one item per sign, updated in place every day.
const { items } = await webflow("/items?limit=100");
const bySlug = new Map(items.map((i) => [i.fieldData.slug, i.id]));

const touched = [];
for (const sign of SIGNS) {
  const res = await fetch(`${ASTRONODE}/v1/horoscope/daily/${sign}?date=${date}`, {
    headers: { Authorization: `Bearer ${process.env.ASTRONODE_API_KEY}` },
  });
  const json = await res.json();
  if (!res.ok) throw new Error(`${sign}: ${json.error.code}`);
  const h = json.data;

  const fieldData = {
    name: sign,
    slug: sign.toLowerCase(),
    "reading-date": h.date, // custom fields are keyed by their field slug, not their label
    summary: h.summary,
    "focus-areas": list(h.focus_areas), // a Rich text field takes HTML
    cautions: list(h.cautions),
  };
  const id = bySlug.get(fieldData.slug);
  const item = id
    ? await webflow(`/items/${id}`, { method: "PATCH", body: JSON.stringify({ fieldData }) })
    : await webflow("/items", { method: "POST", body: JSON.stringify({ isArchived: false, isDraft: false, fieldData }) });
  touched.push(item.id);
}

// Changes are staged until published.
await webflow("/items/publish", { method: "POST", body: JSON.stringify({ itemIds: touched }) });
console.log(`updated and published ${touched.length} items for ${date}`);
```

## What the two runs did

*Requests recorded by the Webflow stand-in, 5 December 2026*

|  | First run (empty collection) | Second run (same day) |
| --- | --- | --- |
| List items | 1 | 1 |
| Create item | 12 | 0 |
| Update item | 0 | 12 |
| Publish | 1 (12 item IDs) | 1 (12 item IDs) |
| AstroNode calls | 12 | 12 |

The Virgo item's `fieldData` after the run:

```json
{
  "name": "Virgo",
  "slug": "virgo",
  "reading-date": "2026-12-05",
  "summary": "The Moon sits in your house of courage and effort. This is one of the easier transits - initiative tends to pay today. Saturday is Saturn's day: slow, patient work pays, and shortcuts rarely do.",
  "focus-areas": "<ul><li>The task that needs nerve, not skill</li><li>Reaching out to siblings or neighbours</li><li>Short trips and errands</li></ul>",
  "cautions": "<ul><li>Mistaking busyness for progress</li><li>Starting a third thing before finishing the first</li></ul>"
}
```

Each reading also carries a `disclaimer` string; add a plain-text field for it, or put a fixed line in the template. Escaping before building the rich-text HTML matters even though the text is the API's: it is going into your markup.

## The mistakes that bite first

- **Creating an item every day.** A create-only job grows the collection by twelve items a day and collides with the existing slugs. Look items up by slug and update them, as above - the second run made no new items.
- **Forgetting to publish.** Items changed through the API are staged, not live, until they are published. The last request publishes exactly the items the run touched.
- **The job's own date.** A job on a UTC machine at 00:30 in India still thinks it is yesterday. Compute `date` in your readers' time zone and pass it explicitly - the API serves whichever date you ask for.
- **Labels instead of slugs.** `fieldData` keys are field slugs (`focus-areas`), not the labels in the Designer (`Focus areas`). Renaming a field's label does not change its slug.

## Questions

**Which AstroNode endpoints does the Webflow example call?**

1 endpoint: Daily Sun Sign Horoscope (`GET /v1/horoscope/daily/:sign`).

**Was the Webflow code on this page actually run?**

Webflow was not contacted. The sync script was executed on Node 24 against the in-memory API for the twelve horoscope calls, and against a local stand-in for the Webflow Data API v2 item routes it uses (list, create, update, publish) that recorded every request. Run twice: the first run created 12 items, the second updated the same 12.

## Endpoints

- [`GET /v1/horoscope/daily/:sign`](https://astronode.dev/capabilities/western/horoscope-daily-sign) - Daily Sun Sign Horoscope API
