Sanity Webhook to Discord Returns 400 Error: "Cannot send an empty message

7 replies
Last updated: Mar 22, 2022
Hi everyone, Im new to webhooks and am struggling to make a webhook to work with sanity and discord. Here is an image on how i configured my webhook inside of my sanity.io account. I’m not sure what I am doing wrong here i check the webhook log inside in sanity and get this log:
{"id":"atm-26f8IwI5sj8vuLk7Kxd2BwTNLAw","projectId":"1234567","inProgress":false,"duration":126,"createdAt":"2022-03-20T19:06:43.856Z","updatedAt":"2022-03-20T19:06:43.856Z","messageId":"msg-26f8Iy5zvkQYhjE2nZMgXU3VbkB","hookId":"VeIn6ryKBtnmVljy","isFailure":true,"failureReason":"other","resultCode":400,"resultBody":"{\"message\": \"Cannot send an empty message\", \"code\": 50006}"}]
AI Update

The error you're seeing ("Cannot send an empty message", "code": 50006) from Discord is happening because your webhook is sending an empty payload to Discord's webhook endpoint. Discord webhooks require specific fields like content, embeds, or file to be present - they can't accept completely empty messages.

The issue is almost certainly with your Projection field in the Sanity webhook configuration. When you leave the Projection field blank, Sanity sends an empty body to Discord, which triggers this exact error.

Here's how to fix it:

Add a GROQ Projection

In your webhook configuration in Sanity, you need to add a GROQ projection that formats the data specifically for Discord's API. Discord expects a JSON object with at minimum a content field containing the message text.

Try adding this to your Projection field:

{
  "content": "New document: " + ^.name + " (Type: " + ^._type + ")"
}

This will send a simple text message to Discord with the document name and type. The ^ syntax refers to the document that triggered the webhook.

More Advanced Example

For richer messages, you can use Discord's embed format:

{
  "content": "Content updated in Sanity!",
  "embeds": [{
    "title": ^.title,
    "description": ^.description,
    "color": 5814783,
    "fields": [
      {
        "name": "Document Type",
        "value": ^._type
      }
    ]
  }]
}

Important Notes

  • Make sure your projection always outputs at least a content field with some text
  • Test your GROQ projection syntax - invalid GROQ will also cause webhook failures
  • You can use webhook.site to test what payload Sanity is actually sending before pointing it at Discord
  • The projection runs on the document that triggered the webhook, so make sure the fields you reference (like title, name, etc.) actually exist on your documents

This is a common gotcha when setting up Discord webhooks with Sanity - Discord is strict about requiring actual message content, and an empty projection means an empty message body! You can read more about how projections work in Sanity webhooks to customize your messages further.

Show original thread
7 replies
You’re getting that error because you’ve left the
Projection
field blank, resulting in an empty post body to Discord.
I don’t know what type of payload Discord expects so you may need something in between to convert your Sanity webhook to something Discord understands.
thank you for taking the time to reply🙏 I believe the type of payload discord expects is json. I already made a webhook to work with github and discord using a json payload. If i’m understanding correctly from the sanity docs, sanity formats their payload as an associative array. You mention that I may have to possibly convert this payload?
Yeah it’s likely JSON but it’ll also need data in a specific shape, eg:
{
  "channelId": 12345
  "message": "This is a message for Discord."
}
So that data either needs to be constructed in the
Projection
field in the Sanity admin otherwise you’ll need need another method to format it.
I am trying to find what you are calling the Projection field in the Sanity admin. I can’t seem to find it. I recall when I made a webhook with github and discord, I was able to select json in github’s webhook, but don’t seem to see sanity’s webhook providing that configuration option.
This one:
How did I miss that 😅 thank you so much for your help I really appreciate it 🙏
Wanted to follow up, I figured it out finally how to fix the empty message error from reading this stack overflow article https://stackoverflow.com/questions/52565121/discord-webhook-can-not-send-empty-message . I entered this in the Projection
{"content": "Test"}
apparently sanity required the word “content” keyword for it to know that is the “message”. Thank you again for your help earlier pointing me in the right direction 🙌 🙏

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?