#Lesson 9.1 - Configure webhooks
In this lesson, you will configure a webhook that triggers a new deployment whenever a product entry is published in Hygraph. Without this, publishing content in Hygraph does not update the live storefront and the deployed site continues to show the version built at the last deployment.
#Generate a build hook
Before configuring the webhook in Hygraph, generate a build hook URL on your deployment platform. Hygraph will send a POST request to this URL whenever the webhook fires.
#Netlify
- Go to your site in Netlify and navigate to Project configuration > Build & deploy > Continuous deployment > Build hooks.
- In the Build hook name field, enter
Deploy from Hygraph. - In the Branch to build dropdown, select
main. - Click Save.
- Copy the generated URL.
#Vercel
- Go to your project in Vercel and navigate to Settings > Git > Deploy Hooks.
- In the hook name field, enter
Deploy from Hygraph. - In the branch field, enter
main. - Click Create Hook.
- Copy the generated URL.
#Configure the webhook in Hygraph
-
Navigate to Project Settings > Automation > Webhooks in your Hygraph project.
-
Click Add webhook.
-
Fill in the following information:
Field Input Name Deploy to Storefront Description Trigger published Include payload Enable to send data via the webhook Method POST URL Paste the build hook URL copied from Netlify or Vercel Secret key Generate a strong random string and enter it here. See the note below. Headers Leave blank The secret key is how the receiving endpoint verifies the request came from Hygraph. Without it, any POST request to the build hook URL triggers a deployment. Add a strong secret and store it securely.
-
Under Triggers, configure the following:
Field Input Content model Product Stage PUBLISHED Actions Leave empty Sources Leave empty You need to select the
Productmodel because product content is what the storefront displays. SelectingPUBLISHEDmeans the webhook only fires when content is published, and saving a content entry does not trigger a deployment. LeavingActionsandSourcesempty acts as a wildcard: all publish actions from all sources trigger the webhook. -
Click Add webhook to save.
Publishing any Product entry in Hygraph automatically triggers a new storefront deployment.
#Verify the webhook
To verify the webhook is working, publish a content entry and confirm a new build starts on your deployment platform.
- Navigate to Content and open any
Productentry. - Modify the product entry, for example, edit the product description.
- Click Save & Publish.
- Check your deployment platform for a new build.
- Netlify: Navigate to Deploys in your Netlify site and check if a new build appears at the top of the list, triggered by the webhook.
- Vercel: Navigate to Deployments in your Vercel project and check if a new deployment appears, triggered by the webhook.
If no build starts, check the following:
- The webhook URL matches the build hook URL exactly. There should be no trailing spaces or missing characters.
- The content entry you published belongs to the Product model. The trigger is scoped to Product only.
- The entry moved to the
PUBLISHEDstage. Saving an entry does not trigger the webhook.
#What's next
Go to the wrap-upOr, go to the Tutorial overview for the full lesson list.