Prerequisites
- An API token with an
admingrant onattribute_derivations. Reading rules needs onlyread. See Permissions. - The ids of the source and target attributes.
mapaccess on the target attribute for your company.
sha256_hashed_email from normalized_email. The attribute ids, company id, and dataset id are placeholders. Replace them with your own.
Check what already exists
Only one of your company’s rules can connect a given source and target, and a rule shared with you may already do the job. List the rules between the two attributes before creating one:records array means no rule you can use connects them.
Write the transformation
The transformation is a mapping whose expressions read the source attribute through$source. Which form you write depends on the types of the two attributes. Fetch both to see their shapes:
A
value_mapping for two string attributes:
$sourcemust come first in a reference.$source.valueis valid; an identifier with$sourceanywhere after the first position is rejected.- An
object_mappingmust cover every required property of the target and must not name properties the target does not have. cached_mappingis not accepted.- You can use any transformation function, including
CURRENT_DATEandCURRENT_TIMESTAMP. The expression runs each time a query uses the rule.
Create the rule
Send the rule toPOST /derivations. Set lossy when the transformation discards information and imprecise when it is approximate, and use fidelity_note to explain either flag to people deciding whether to accept derived data.
company_id must be your own company. A 201 response returns the rule with its id.
The transformation is validated before the rule is written. A 400 lists every problem found, so you can fix them in one pass. A 409 means your company already has a rule with that name or between those two attributes. See the Derivations API reference for the full list.
If the response includes a cyclic_derivation warning, the rule was still created. The warning tells you the new rule closes a loop with existing rules, which is allowed. See Why cycles are allowed.
Share the rule
A new rule with"type": "none" applies only to your own company’s queries. To let other companies use it, update collaborators with their ids:
Confirm the rule works
Check that the rule appears where you expect in the derivation graph:nodes with "relationship": "descendant", and your rule should appear in edges.
Then check that a dataset mapped to the source attribute gains a derived mapping. Ask for the dataset with only its derived mappings:
mappings for a row whose attribute_id is the target attribute and your rule’s id in provenance.derivation_path. Its mapping.expression shows the dataset’s own expression substituted for $source.
Finally, query the target attribute:
If no derived mapping appears
Change a rule
PATCH /derivations/{derivation_id} changes only the fields you send. A changed mapping is validated the same way as on create. You cannot change source_attribute_id or target_attribute_id. Create a new rule instead.
Because derived mappings are computed when they are needed, a change applies to every query that runs after it. There are no stored mappings to rebuild.
Retire a rule
To stop a rule being applied while keeping it, set it inactive:Related content
Attribute Derivations
How rules become mappings and which mapping wins
Derivations API
Every field, permission, and error response
Mapping Schemas
Create the stored mappings that rules build on
Transformation Functions
Functions available inside rule expressions

