> For the complete documentation index, see [llms.txt](https://docs.omnata.com/omnata-product-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.omnata.com/omnata-product-documentation/omnata-sync-for-snowflake/integrations/custom-hook.md).

# Custom hook

## Pre run hook

At the start of each sync run, the Sync Engine lists all stored procedures named `SYNC_RUN_PRE_HOOK`, with a single `object` parameter. All that exist are executed with the following parameter value:

```
{
  "branch_id": <the id of the branch, or null>,
  "new_health_state": <the new health state of the run, e.g. "HEALTHY">,
  "sync_id": <the id of the sync>,
  "sync_slug": <the slug of the sync>,
  "sync_run_id": <the id of the sync run>,
  "previous_sync_run_id", <the id of the previous sync run, or null if this is the first run>,
  "previous_health_state", <the health state of the previous run, or null if this is the first run>
}
```

Note: Health states are listed [here](https://docs.omnata.com/omnata-product-documentation/omnata-sync-for-snowflake/how-it-works/terminology#sync-health-states).

## Post run hook

At the end of each sync run, the Sync Engine lists all stored procedures named `SYNC_RUN_POST_HOOK`, with a single `object` parameter. All that exist are executed with the following parameter value:

```
{
  "branch_id": <the id of the branch, or null>,
  "new_health_state": <the new health state of the run, e.g. "HEALTHY">,
  "sync_id": <the id of the sync>,
  "sync_slug": <the slug of the sync>,
  "sync_run_id": <the id of the sync run>
}
```

Note: Health states are listed [here](https://docs.omnata.com/omnata-product-documentation/omnata-sync-for-snowflake/how-it-works/terminology#sync-health-states).

## Example

Below is an example of a hook which simply writes the run information to a table:

```
create table TEST_HOOK_LOG(payload OBJECT);

CREATE OR REPLACE PROCEDURE SYNC_RUN_POST_HOOK(result OBJECT)
RETURNS VARCHAR NOT NULL
LANGUAGE SQL
EXECUTE AS OWNER
AS
BEGIN
  INSERT INTO TEST_HOOK_LOG select :result;
  RETURN 'Rows inserted: ' || SQLROWCOUNT;
END;

grant usage on procedure SYNC_RUN_POST_HOOK(OBJECT) to application OMNATA_SYNC_ENGINE;

-- you also need to grant usage on SYNC_RUN_POST_HOOK's database and schema
grant usage on database <DB> to application OMNATA_SYNC_ENGINE;
grant usage on schema <DB>.<Schema> to application OMNATA_SYNC_ENGINE;

```

{% hint style="warning" %}
The procedure must be created with Owners rights, or an error will be raised.

The Sync Engine will wait for the procedure to complete before the run finishes, so it may be better to start a task for log running processes.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.omnata.com/omnata-product-documentation/omnata-sync-for-snowflake/integrations/custom-hook.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
