Hygraph
Docs

#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

  1. Go to your site in Netlify and navigate to Project configuration > Build & deploy > Continuous deployment > Build hooks.
  2. In the Build hook name field, enter Deploy from Hygraph.
  3. In the Branch to build dropdown, select main.
  4. Click Save.
  5. Copy the generated URL.

#Vercel

  1. Go to your project in Vercel and navigate to Settings > Git > Deploy Hooks.
  2. In the hook name field, enter Deploy from Hygraph.
  3. In the branch field, enter main.
  4. Click Create Hook.
  5. Copy the generated URL.

#Configure the webhook in Hygraph

  1. Navigate to Project Settings > Automation > Webhooks in your Hygraph project.

  2. Click Add webhook.

  3. Fill in the following information:

    FieldInput
    NameDeploy to Storefront
    DescriptionTrigger published
    Include payloadEnable to send data via the webhook
    MethodPOST
    URLPaste the build hook URL copied from Netlify or Vercel
    Secret keyGenerate a strong random string and enter it here. See the note below.
    HeadersLeave 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.

  4. Under Triggers, configure the following:

    FieldInput
    Content modelProduct
    StagePUBLISHED
    ActionsLeave empty
    SourcesLeave empty

    You need to select the Product model because product content is what the storefront displays. Selecting PUBLISHED means the webhook only fires when content is published, and saving a content entry does not trigger a deployment. Leaving Actions and Sources empty acts as a wildcard: all publish actions from all sources trigger the webhook.

  5. 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.

  1. Navigate to Content and open any Product entry.
  2. Modify the product entry, for example, edit the product description.
  3. Click Save & Publish.
  4. 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 PUBLISHED stage. Saving an entry does not trigger the webhook.

#What's next

Go to the wrap-up

Or, go to the Tutorial overview for the full lesson list.