Unlock seamless workflows and faster delivery with our latest releases – get the details

Setting up Sanity webhook API to trigger Github actions dispatch workflow

6 replies
Last updated: Mar 14, 2022
Hey there, I’m trying to setup Sanity webhook API to trigger Github actions dispatch workflow. However I’m running into below issue. I already had a test via Curl before setting up sanity webhook. Can anyone suggest how this can be achieved?
{
id: "atm-xxxxx",
projectId: "xxx",
inProgress: false,
duration: 226,
createdAt: "2022-02-xxxxx",
updatedAt: "2022-02-xxxx",
messageId: "msg-xxxxxxxxxx",
hookId: "xxxxxxxxx",
isFailure: true,
failureReason: "other",
resultCode: 422,
resultBody: "{"message":"Invalid request.\n\n\"_createdAt\", \"_id\", \"_rev\", \"_type\", \"_updatedAt\", \"header\", \"slug\", \"title\" are not permitted keys.\n\"event_type\" wasn't supplied.","documentation_url":"<https://docs.github.com/rest/reference/repos#create-a-repository-dispatch-event>"}"
}
Feb 21, 2022, 10:44 PM
Thank you for your patience while we were out for a long holiday weekend.
I haven’t personally had enough experience with webhooks and github actions to give you a quick answer off the top of my head. But just at a glance, it seems that github isn’t happy with the object headers you are trying to send. I have asked the team for some input or similar working examples to get started.
Feb 22, 2022, 4:46 PM
Hi Dev C. It looks like your webhook’s projection is either blank (so everything is being sent) or not configured to what GitHub is expecting. From the URL at the bottom of the error, it looks like GitHub requires the
event_type
parameter. It also looks like if you want to pass details about the document, you’ll do so via the
client_payload
object parameter.
In your webhook setup, you’ll likely want your projection to look like this:


{
  'event_type': 'event_type'
}
or this to send specific fields:


{
  'event_type': 'event_type',
  'client_payload': {
    title,
    _id,
  }
}
or this to send full document details in the payload:


{
  'event_type': 'event_type',
  'client_payload': {
    ...
  }
}
Feb 22, 2022, 6:12 PM
In case you would like to test and replicate this in vision for groq webhooks in your project manager at sanityio, here is an quick query example of altering object ids that might help:
Feb 22, 2022, 7:21 PM
user A
How can we specify the event_type and client_payload parameters in Webhooks in your Sanity Content Lake? Another way is it possible? I can’t see where I can forge a special body parameters? Any advice?
EDIT: Maybe add a proxy endpoint for forging this Github usecase?
Mar 14, 2022, 4:16 PM
Now I understand this message from
user U
I figured out CROQ projection 😅
Mar 14, 2022, 4:23 PM
user U
Ha! I figured out CROQ projection 😅
Mar 14, 2022, 4:23 PM

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?