Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

Troubleshooting webhook integration between Sanity and Discord

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}"}]
Mar 20, 2022, 11:30 PM
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.
Mar 21, 2022, 12:38 AM
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?
Mar 21, 2022, 1:01 AM
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.
Mar 21, 2022, 1:26 AM
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.
Mar 21, 2022, 1:42 AM
This one:
Mar 21, 2022, 1:52 AM
How did I miss that 😅 thank you so much for your help I really appreciate it 🙏
Mar 21, 2022, 2:17 AM
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 🙌 🙏
Mar 22, 2022, 8:14 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?