This guide specifically covers how to create and report results for custom assertions in DataHub.
Custom Assertions are those not natively run or directly modeled by DataHub, and managed by a 3rd party framework or tool.
To create _native_ assertions using the API (e.g. for DataHub to manage), please refer to the [Assertions API](./assertions.md).
This guide may be used as reference for partners seeking to integrate their own monitoring tools with DataHub.
## Goal Of This Guide
In this guide, you will learn how to
1. Create and update custom assertions via GraphQL and Python APIs
2. Report results for custom assertions via GraphQL and Python APIs
3. Retrieve results for custom assertions via GraphQL and Python APIs
4. Delete custom assertions via GraphQL and Python APIs
## Prerequisites
The actor making API calls must have the `Edit Assertions` and `Edit Monitors` privileges for the Tables being monitored.
## Create And Update Custom Assertions
You may create custom assertions using the following APIs for a Dataset in DataHub.
<Tabs>
<TabItemvalue="graphql"label="GraphQL"default>
To create a new assertion, use the `upsertCustomAssertion` GraphQL Mutation. This mutation both allows you to
create and update a given assertion.
```graphql
mutation upsertCustomAssertion {
upsertCustomAssertion(
urn: "urn:li:assertion:my-custom-assertion-id", # Optional: if you want to provide a custom id. If not, one will be generated for you.
input: {
entityUrn: "<urnofentitybeingmonitored>",
type: "My Custom Category", # This is how your assertion will appear categorized in DataHub.
description: "The description of my external assertion for my dataset",
platform: {
urn: "urn:li:dataPlatform:great-expectations", # OR you can provide name: "My Custom Platform" if you do not have an URN for the platform.
}
fieldPath: "field_foo", # Optional: if you want to associated with a specific field,
externalUrl: "https://my-monitoring-tool.com/result-for-this-assertion" # Optional: if you want to provide a link to the monitoring tool
# Optional: If you want to provide a custom SQL query for the assertion. This will be rendered as a query in the UI.
# logic: "SELECT * FROM X WHERE Y"
}
) {
urn
}
}
```
Note that you can either provide a unique `urn` for the assertion, which will be used to generate the corresponding assertion urn in the following format:
`urn:li:assertion:<your-new-assertion-id>`
or a random urn will be created and returned for you. This id should be stable over time and unique for each assertion.
The upsert API will return the unique identifier (URN) for the the assertion if you were successful:
```json
{
"data": {
"upsertExternalAssertion": {
"urn": "urn:li:assertion:your-new-assertion-id"
}
},
"extensions": {}
}
```
</TabItem>
<TabItemvalue="python"label="Python">
To upsert an assertion in Python, simply use the `upsert_external_assertion` method on the DataHub Client object.