Skip to main content

Writeback API

The writeback router manages pushing computed scores back to external systems (e.g., Salesforce custom fields). Admins configure which score fields map to target fields, then trigger writeback operations that run as asynchronous Temporal workflows.

Router namespace: writeback

Source: src/server/trpc/routers/writeback.ts

Access: All procedures require admin role.

Procedures

ProcedureTypeAccessDescription
getConfigqueryadminGet writeback configurations for a connector
saveConfigmutationadminSave or update writeback field mappings
triggerWritebackmutationadminTrigger an asynchronous writeback operation
getWritebackStatusqueryadminGet writeback status for a connector
listWriteableFieldsqueryadminList writeable fields in the target system

Canonical Score Fields

Writeback supports mapping these canonical score fields to target system fields:

Canonical FieldTypeDescription
fitScorenumberICP match score (0-100)
engagementScorenumberBehavioral engagement score (0-100)
combinedScorenumberWeighted combination of fit + engagement
tierstringScore tier (hot, warm, cool, cold)
scoredAtdatetimeTimestamp of last scoring run

getConfig

Retrieves all writeback configurations for a connector, including field mappings and status.

writeback.getConfig.queryOptions(input)

Input

FieldTypeRequiredDescription
connectorIdstringYesDatabase ID of the connector

Response

[
{
"entityType": "account",
"fieldMap": [
{ "canonicalField": "combinedScore", "targetField": "GTM_Score__c" },
{ "canonicalField": "tier", "targetField": "GTM_Tier__c" },
{ "canonicalField": "scoredAt", "targetField": "GTM_Scored_At__c" }
],
"enabled": true,
"lastWritebackAt": "2026-03-05T09:00:00.000Z",
"lastWritebackError": null
}
]

saveConfig

Saves or updates writeback configuration for a specific entity type. Uses upsert semantics -- creates a new config or updates the existing one.

writeback.saveConfig.mutationOptions(options)

Input

FieldTypeRequiredDescription
connectorIdstringYesDatabase ID of the connector
entityTypestringYesEntity type (e.g., "account", "person")
fieldMapWritebackFieldMap[]YesScore-to-target field mappings
enabledbooleanYesWhether writeback is active for this entity type

WritebackFieldMap schema:

FieldTypeRequiredDescription
canonicalField"fitScore" | "engagementScore" | "combinedScore" | "tier" | "scoredAt"YesScore field to write
targetFieldstringYesTarget system field name (e.g., Salesforce custom field API name)

Response

{
"success": true
}
Connector Validation

Throws NOT_FOUND if the specified connector does not exist or does not belong to the current tenant.

Example

const trpc = useTRPC();

const mutation = useMutation(
trpc.writeback.saveConfig.mutationOptions()
);

mutation.mutate({
connectorId: "conn_456",
entityType: "account",
fieldMap: [
{ canonicalField: "combinedScore", targetField: "GTM_Score__c" },
{ canonicalField: "tier", targetField: "GTM_Tier__c" },
{ canonicalField: "scoredAt", targetField: "GTM_Scored_At__c" },
],
enabled: true,
});

triggerWriteback

Triggers an asynchronous writeback operation via Temporal workflows. Scores are pushed to the target system for the configured entity types.

writeback.triggerWriteback.mutationOptions(options)

Input

FieldTypeRequiredDefaultDescription
connectorIdstringYes--Database ID of the connector
entityTypesstring[]Noall configured typesLimit writeback to specific entity types

Response

{
"workflowId": "writeback-tenant_789-conn_456-1709625600000",
"queued": true
}
Asynchronous Operation

Writeback runs as a Temporal workflow. The response confirms the operation is queued. Use getWritebackStatus to monitor progress.


getWritebackStatus

Returns the current writeback status for all entity types configured on a connector.

writeback.getWritebackStatus.queryOptions(input)

Input

FieldTypeRequiredDescription
connectorIdstringYesDatabase ID of the connector

Response

[
{
"entityType": "account",
"lastWritebackAt": "2026-03-05T09:00:00.000Z",
"lastWritebackError": null,
"enabled": true
},
{
"entityType": "person",
"lastWritebackAt": null,
"lastWritebackError": "FIELD_NOT_WRITABLE: GTM_Score__c",
"enabled": true
}
]

listWriteableFields

Lists fields in the target system that can be written to for a given entity type. Requires an active connector connection.

writeback.listWriteableFields.queryOptions(input)

Input

FieldTypeRequiredDescription
connectorIdstringYesDatabase ID of the connector
entityTypestringYesEntity type

Response

[
{ "name": "GTM_Score__c", "label": "GTM Score", "type": "number", "custom": true },
{ "name": "GTM_Tier__c", "label": "GTM Tier", "type": "picklist", "custom": true },
{ "name": "Description", "label": "Description", "type": "textarea", "custom": false }
]
warning

Throws NOT_FOUND if the connector is not connected. An active connection to the target system is required to describe available fields.