Send subgraph-driven webhooks
Receive real-time HTTP POST requests based on your subgraphs.
Power Discord notifications, back-end operations, orderbooks, and more with webhooks for subgraphs. Receive real-time HTTP POST requests to your backends whenever a subgraph indexes a new event. Every project has webhooks enabled by default for free.
Let’s speed-run a simple example of a webhook. We’ll create a webhook that sends a POST request to a URL of your choice whenever a trade occurs on the X2Y2 exchange.
What you’ll need
-
One or more subgraphs in your project - this can be from community subgraphs, a deployed subgraph, or a no-code subgraph.
-
A webhook handler; making a fully functional webhook handler is out of scope for this walkthrough so we’ll be using a test platform called Webhook.site.
Walkthrough
Deploy subgraph
Use Messari’s x2y2 subgraph to the x2y2 exchange.
> goldsky subgraph deploy x2y2/v1 --from-ipfs-hash Qmaj3MHPQ5AecbPuzUyLo9rFvuQwcAYpkXrf3dTUPV8rRu
Deploying Subgraph:
✔ Downloading subgraph from IPFS (This can take a while)
✔ Validating build path
✔ Packaging deployment bundle from /var/folders/p5/7qc7spd57jbfv00n84yzc97h0000gn/T/goldsky-deploy-Qmaj3MHPQ5AecbPuzUyLo9rFvuQwcAYpkXrf3dTUPV8rRu
Create webhook handler
Let’s use a pre-made webhook handler by going to webhook.site and copying the URL. It may look like something like https://webhook.site/<YOUR-UNIQUE-WEBHOOK-SITE-ID>
Don’t use format https://webhook.site/#!/<YOUR-UNIQUE-WEBHOOK-SITE-ID>
Any new webhook can be sent to this URL and we’ll be able to see and inspect the request body.
Create webhook
Create a webhook to receive x2y2 trades.
> goldsky subgraph webhook create x2y2/v1 --name x2y2-trade-webhook --entity trade --url https://webhook.site/<YOUR-UNIQUE-WEBHOOK-URL>
✔ Creating webhook
Webhook 'x2y2-trade-webhook' created.
Make sure calls to your endpoint have the following value for the 'goldsky-webhook-secret' header: whs_01GNV4RMJCFVH14S4YAFW7RGQK
A secret will be generated for you to use in your webhook handler. This secret is used to authenticate the webhook request. You can ignore it for the purposes for this speed run.
Test webhook
Inspect the webhook.site URL (or your custom handler) again, you should see events start to stream in.
Can't find what you're looking for? Reach out to us at support@goldsky.com for help.
Was this page helpful?