Skip to main content

Triggers

TypeBase PathTrigger Name
REST resource~{realm}/users/{user-id}/triggers/triggers

This resource holds the user's triggers. A trigger is a condition and action that can fire whenever a entity in a resource is updated.

See also Event Streams for more an alternative way to receive notifications when entities are updates.

Endpoints

NameMethodRelative PathPayloadResponseDescription
addTriggerPOST~{realm}/users/{user-id}/triggers/TriggerStored_TriggerAdds a new trigger to the list.
listTriggersGET~{realm}/users/{user-id}/triggers/N/AStored_Trigger[]Retrieves a list of triggers.
getTriggerGET~{realm}/users/{user-id}/triggers/{id}N/AStored_TriggerRetrieves a trigger.
putTriggerPUT~{realm}/users/{user-id}/triggers/{id}TriggerStored_TriggerReplaces a trigger.
updateTriggerPATCH~{realm}/users/{user-id}/triggers/{id}Partial_TriggerStored_TriggerUpdates specified trigger fields.
removeTriggerDELETE~{realm}/users/{user-id}/triggers/{id}N/AN/ADeletes a trigger.

Permissions

PermissionDescription
edit-triggersClient is allowed to add new triggers and to modify or delete existing triggers (for any user).
show-triggersClient is allowed to query the trigger list and to fetch individual triggers (for any user).
use-triggersClient is allowed to use and modify the user's own triggers.

Note that in addition to the permissions above, for query triggers, you also need read access to the actual resource the trigger refers to.

Entities

Interface Trigger

namespace Trigger {
type Type = 'cron' | 'query';
}

interface Trigger {
'type': Trigger.Type;
'user': number;
'start-date'?: DateTime;
'schedules'?: string[];
'end-date'?: DateTime;
'query'?: QueryTrigger;
'action': TriggerAction;
'id'?: number;
'created'?: DateTime;
'updated'?: DateTime;
'deleted'?: DateTime;
'updated-by'?: number;
'updated-from'?: number;
'tags'?: string[];
'labels'?: number[];
}
PropertyData TypeDescription
typeTrigger.Type?Type of trigger.
userInt64The ID of the user that owns this trigger.
start-dateDateTime?A starting date when this trigger becomes active.
schedulesCronExpr[]?A schedule that specifies at what time this trigger is active (applicable only between start-date and end-date). Required for cron triggers and optional for query triggers.
end-dateDateTime?An ending date when this trigger becomes inactive.
queryQueryTrigger?If type is query, an object that specifies the trigger conditions.
actionTriggerActionThe action that should happen when the trigger fires.
idInt64?The resource ID of this entity.
createdDateTime?Date and time when this entity was first created.
updatedDateTime?Date and time when this entity was last modified.
deletedDateTime?Date and time when this entity was deleted.
updated-byInt64?ID of User who last modified this entity.
updated-fromInt64?ID of Till (trusted device) which last modified this entity.
labelsInt64[]?A list of Label IDs associated with this entity.

Interface QueryTrigger

interface QueryTrigger {
'resource': string;
'query': string;
'operations'?: DataObjectOperation.Operation[];
}
PropertyData TypeDescription
resourceStringThe resource the query should be evaluated against. The value of this property is documented as Trigger Name for each resource in this chapter.
queryStringThe query to check entities that are being modified against. See Query Language.
operationsDataObjectOperation.Operation[]?An optional list of operations that must match the current op. Defaults to all operations (i.e. create, update, and delete).

Interface TriggerAction

namespace TriggerAction {
type LogLevel = 'errors' | 'warnings' | 'results' | 'progress' | 'all';
type Type = 'auto-close-batch' | 'erp-integration' | 'report' | 'webhook' | 'digital-receipt' | 'dm-campaign' | 'email';
}

interface TriggerAction {
'type': TriggerAction.Type;
'name': string;
'description'?: string;
'log-level'?: TriggerAction.LogLevel;
'notification-uri'?: string;
'auto-close-batch'?: AutoCloseBatchAction;
'erp-integration'?: ERPAction;
'report'?: ReportAction;
'webhook'?: WebhookAction;
'digital-receipt-action'?: DigitalReceiptAction;
'dm-campaign'?: DMCampaignAction;
'send-email-action'?: SendEmailAction;
}
PropertyData TypeDescription
typeTypeTrigger action type. Should be set to webhook.
nameStringThe name of the trigger action.
descriptionString?An optional description of the trigger action.
log-levelLogLevel?If present, events with higher or equal log level will be stored in the trigger event log.
notification-uriURI?A notification URI. If present, and the trigger action produces a result, the result will be sent/uploaded to this URI.
auto-close-batchAutoCloseBatchAction?Auto-close batch parameters. Only applicable if type is auto-close-batch.
erp-integrationERPAction?ERP integration parameters. Only applicable if type is erp-integration.
reportReportAction?Report parameters. Only applicable if type is report.
webhookWebhookAction?Web hook parameters. Only applicable if type is webhook.
digital-receipt-actionDigitalReceiptAction?Digital receipt parameters. Only applicable if type is digital-receipt.
dm-campaignDMCampaignAction?Direct marketing campaign parameters. Only applicable if type is dm-campaign.
send-email-actionSendEmailAction?E-mail parameters. Only applicable if type is send-email.

The following log levels are defined. If no log level is set, no entry in the trigger event log will ever be created by this action.

Log levelDescription
errorsOnly final failures will be logged. All retries failed and the system will no longer try to process the action.
warningsAll failures will be logged, even if the action will be automatically by the system retried later.
resultsIf an action produces a result, an event will be created and the result will be attached to the event.
progressAll action progress will be logged; however, results will not be attached to the event in the trigger event log.
allAll action progress will be logged, and results, if there are any, will be attached to the event.

Only actions with log level results or all will store results in the trigger event log. Note that results may still be sent/uploaded via the notification-uri mechanism, regardless of the log level. For instance, a report action that is used to send reports by e-mail could use log-level warnings or progress if the report should not also be stored in the system, but results or all if it should.

Interface WebhookAction

This interface describes the web-hook (endpoint URI, message content-type and, optionally, authentication).

interface WebhookAction {
'endpoint-uri': string;
'content-type': string;
'access-token'?: number;
}
PropertyData TypeDescription
endpoint-uriURIThe (HTTP/HTTPS/FTP/MAILTO) endpoint where the web hook payload will be posted.
content-typeStringWhat format the web hook payload will be delivered in. Supported content types are application/json, application/xml or text/csv.
access-tokenInt64?An optional reference to an access-token to be used for request authentication.

Webhook authentication is supported in two ways. First, it's possible to include username/password credentials within the endpoint URI itself (example: https://username:password@hostname/path), which will be used if the remote server requests Basic or Digest authentication.

Another way to provide the credentials is to add an access-token reference. All three access token types are supported.

Access Token TypeDescription
access-tokenThe key property holds an UTF-8-encoded password, which will be used in the same way as an URI-embedded password (i.e., for Basic and Digest authentication).
hawk-keyThe key will be used to calculate a Hawk signature. Both internal and external AccessTokens are allowed, so it's possible to reuse an API key, if desired.
pkcs12The PKCS #12 archive in key should include a certificate (and private key) with alias cert, that will be used for client TLS authentication.

When using an access token as credential source, the username or Hawk ID will be set to {user-alias}+{token-alias}@{realm}, unless a custom username is provided in the endpoint URI (example: https://username@hostname/path).

Referencing an API access token (i.e., a hawk-key token) in the webhook is the preferred way to provide authentication, since you most probably already have such a token, and there is no way for the secret to leak. Client TLS authentication is an equally good authentication method, but it requires extra setup steps.

However, using URI-embedded credentials or an access-token of type access-token implies that the secret is not really a secret anymore: the URI itself is fully visible and even if the access tokens key property is never revealed by the server, it will still be transmitted in the clear to any webhook endpoint the account owner wishes.

Interface WebhookMessage

When the server executes a web hook, this is the payload that will be POSTed to the endpoint-uri.

interface WebhookMessage {
'service-endpoint-uri': string;
'company-alias': string;
'user-alias': string;
'trigger': number;
'trigger-event'?: number;
'data-object'?: DataObjectOperation;
}
PropertyData TypeDescription
service-endpoint-uriURIAn API URI where the Onslip 360 server is available. Use this URI if you need to fetch more data or perform server operations as part of the web hook processing.
company-aliasStringThe realm where the firing trigger is defined.
user-aliasStringThe user alias that owns the firing trigger.
triggerInt64The ID of the firing trigger.
trigger-eventInt64The ID, if present, of the trigger event that tracks the progress of this trigger execution.
data-objectDataObjectOperationA description of the data operation that caused the trigger to fire.

service-endpoint-uri is provided so you can easily recognize what Onslip 360 environment (staging, production etc.) the web hook comes from. company-alias, user-alias and trigger uniquely identifies the trigger that fired within this environment.

Interface DataObjectOperation

namespace DataObjectOperation {
type Operation = 'create' | 'update' | 'delete';
}

interface DataObjectOperation {
'operation': DataObjectOperation.Operation;
'resource': string;
'payload': DomainObject;
}
PropertyData TypeDescription
operationDataObjectOperation.OperationWhat operation caused the trigger to fire.
resourceStringThe resource where the entity is located.
payloadObjectThe entity itself.