Manage webhook consumers via the Codat Platform API.
Webhook consumers are HTTPS endpoints that Codat POSTs to when events occur. This module wraps the Platform API for creating and managing them programmatically.
For receiving and verifying webhooks in your Elixir app, see:
Codat.Webhooks.Plug— drop-in Plug for Phoenix/Plug appsCodat.Webhooks.Verifier— standalone signature verificationCodat.Webhooks.Handler— behaviour for typed event handling
Example
# Create a webhook consumer
{:ok, consumer} = Codat.Platform.Webhooks.create(client, %{
name: "Production Events",
url: "https://myapp.com/webhooks/codat",
eventTypes: ["company.dataConnectionStatusChanged", "invoices.write.successful"]
})
# List all configured consumers
{:ok, page} = Codat.Platform.Webhooks.list(client)
Summary
Functions
Creates a new webhook consumer endpoint.
Deletes a webhook consumer.
Disables a webhook consumer so it no longer receives events.
Enables a previously disabled webhook consumer.
Fetches a webhook consumer by ID.
Lists all webhook consumers.
Returns the delivery log for a specific webhook consumer.
Updates an existing webhook consumer.
Functions
@spec create(Codat.Client.t() | map(), map() | keyword()) :: {:ok, map()} | {:error, Codat.Error.t()}
Creates a new webhook consumer endpoint.
Required Fields
url— HTTPS endpoint to POST events to (must respond with 2xx within 15s)
Optional Fields
name— human-readable labeleventTypes— list of event type strings to subscribe to. Pass["*"]to receive all events. Defaults to all events if omitted.companyId— scope to a single companytype—"Portal"or"API"(informational)
Example
{:ok, consumer} = Codat.Platform.Webhooks.create(client, %{
name: "Invoice Events",
url: "https://myapp.com/webhooks/codat",
eventTypes: [
"invoices.write.successful",
"invoices.write.unsuccessful"
]
})
@spec delete(Codat.Client.t() | String.t(), String.t() | keyword()) :: {:ok, nil} | {:error, Codat.Error.t()}
Deletes a webhook consumer.
Example
{:ok, nil} = Codat.Platform.Webhooks.delete(client, "webhook-id")
@spec disable(Codat.Client.t() | String.t(), String.t() | keyword()) :: {:ok, map()} | {:error, Codat.Error.t()}
Disables a webhook consumer so it no longer receives events.
Example
{:ok, consumer} = Codat.Platform.Webhooks.disable(client, "webhook-id")
consumer["status"] # => "Inactive"
@spec enable(Codat.Client.t() | String.t(), String.t() | keyword()) :: {:ok, map()} | {:error, Codat.Error.t()}
Enables a previously disabled webhook consumer.
Example
{:ok, consumer} = Codat.Platform.Webhooks.enable(client, "webhook-id")
consumer["status"] # => "Active"
@spec get(Codat.Client.t() | String.t(), String.t() | keyword()) :: {:ok, map()} | {:error, Codat.Error.t()}
Fetches a webhook consumer by ID.
Example
{:ok, consumer} = Codat.Platform.Webhooks.get(client, "webhook-id")
consumer["url"] # => "https://myapp.com/webhooks/codat"
consumer["status"] # => "Active"
@spec list( Codat.Client.t() | keyword(), keyword() ) :: {:ok, Codat.Pagination.t()} | {:error, Codat.Error.t()}
Lists all webhook consumers.
Example
{:ok, page} = Codat.Platform.Webhooks.list(client)
consumers = page.results
@spec messages(Codat.Client.t() | String.t(), String.t() | keyword(), keyword()) :: {:ok, Codat.Pagination.t()} | {:error, Codat.Error.t()}
Returns the delivery log for a specific webhook consumer.
Example
{:ok, page} = Codat.Platform.Webhooks.messages(client, "webhook-id")
msgs = page.results
@spec update(Codat.Client.t() | String.t(), String.t() | map(), map() | keyword()) :: {:ok, map()} | {:error, Codat.Error.t()}
Updates an existing webhook consumer.
Example
{:ok, consumer} = Codat.Platform.Webhooks.update(client, "webhook-id", %{
eventTypes: ["*"]
})