Skip to content

Set up Netlify build hook and Sanity webhook for automatic rebuilds #11

Description

@dogmar

Context

The klink.ing website is statically built on Netlify. Once Sanity CMS is integrated (issues 01–03 in the sanity-blog-and-projects feature), content changes in Sanity (blog posts, projects) won't appear on the live site until Netlify rebuilds. This issue tracks the manual dashboard configuration needed to connect the two.

PRD: .sandcastle/specs/sanity-blog-and-projects.md § 6 — Netlify Rebuild on Sanity Changes

Prerequisites

  • Issues sanity-blog-and-projects/01-sanity-studio, 02-sanity-integration-blog-projects, and 03-hamburger-menu are merged and deployed
  • You have admin access to the Netlify site dashboard
  • You have admin access to the Sanity project dashboard (manage.sanity.io)

Step 1: Create a Netlify Build Hook

  1. Go to the Netlify dashboard and select the klink.ing site
  2. Navigate to Site configuration → Build & deploy → Build hooks
  3. Click Add build hook
  4. Name it sanity-cms (or similar — this is just a label)
  5. Select the main branch (or whichever branch Netlify deploys from)
  6. Click Save
  7. Copy the generated URL — it will look like:
    https://api.netlify.com/build_hooks/XXXXXXXXXXXXXXXX
    
    ⚠️ Treat this URL as a secret. Anyone with it can trigger builds on your site.

Step 2: Create a Sanity Webhook

  1. Go to manage.sanity.io and select your project
  2. Navigate to API → Webhooks
  3. Click Create webhook and fill in:
    • Name: Netlify rebuild
    • URL: Paste the Netlify build hook URL from Step 1
    • Dataset: production (or whichever dataset the website reads from)
    • Trigger on: Select Create, Update, and Delete
    • Filter: _type in ["post", "project"]
      • This limits rebuilds to content changes only — schema or config edits won't trigger unnecessary builds
    • Projection: Leave empty (Netlify ignores the POST body)
    • Status: Enabled
    • HTTP method: POST
    • HTTP Headers: None needed
    • Secret: Leave empty (Netlify build hooks don't validate secrets)
  4. Click Save

Step 3: Verify the Integration

  1. In Sanity Studio, create or edit a blog post or project and click Publish
  2. Within a few seconds, check the Netlify dashboard — a new deploy should appear in the Deploys tab with the source shown as "Build hook: sanity-cms"
  3. Wait for the build to complete and verify the content change appears on the live site

Troubleshooting

  • Build not triggering: Check the Sanity webhook logs at manage.sanity.io → API → Webhooks → click the webhook → Activity log. Look for failed deliveries or HTTP errors.
  • Build triggers but content is stale: Make sure the Astro build is reading from the correct Sanity dataset and that useCdn is set appropriately (CDN may have a short cache delay).
  • Too many builds: If you're making many rapid edits, consider adding a short delay or batching publishes. Netlify automatically deduplicates overlapping builds.

Acceptance Criteria

  • Netlify build hook exists and is named descriptively
  • Sanity webhook POSTs to the build hook on post and project publish/unpublish
  • A Sanity publish triggers a visible Netlify deploy
  • The rebuilt site reflects the content change

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions