Cancel a Scheduled Event in Hasura

Jason Brown
InstructorJason Brown
Share this video with your friends

Social Share Links

Send Tweet

Hasura provides the ability to schedule HTTP events to be fired at a given date and time. We will use the /v1/query endpoint and the comment section to allow for cancelling events with an id that we create.

Jason Brown: [0:00] Hasura offers two ways to schedule one-off events. One, you can be using their API, or you can do it through their console. You would set up a webhook to be called at a specific time with a specific payload, and then create that scheduled event.

[0:16] There is one issue though. Unless you're using their console, there's no way to cancel this scheduled event via the API. However, if you click on this, and click OK to cancel, you can see that it does make a request to the API.

[0:34] It makes a request to v1/query as you normally would with a specific payload. If we copy our payload, you can go inspect it. If we take that payload and we go into postman and we can paste that into our body, and select JSON as the type, we can see what is doing is a delete a specific event in a table where our id is equal to this particular thing.

[1:04] Hasura does offer an advanced feature. If we type in another one to create at a time, there's an advanced feature where it allows you to leave a comment. We'll leave a comment that says test_id and we create this event.

[1:24] We can then go manipulate the query that we had here, where rather than id, we can specify the id of the comment that we made. You can see here we have our test_id for our comment and we can change this to comment equals our test_id.

[1:47] We go ahead and execute this. We just make sure that we have our admin-secret ends our header. We can see that it had one affected row. If we refresh our pending events, you can see that it is no longer there.

[1:59] However, just note that this will delete for everything that has that specific comment. Make sure that the ids that you are putting in there are unique, or you know that in fact you want to delete multiple things with that particular comment.