Webhooks
|
This page only applies to self-hosted installations of Timefold Platform. On Timefold Cloud Platform, you set up webhooks with Notifications instead. |
Timefold Platform sends a webhook to your application when a dataset reaches a status such as completed or failed.
Self-hosted installations don’t include a UI, so you manage webhooks through the admin API. Authenticate each request with a token issued by your OIDC provider.
When webhooks trigger
Timefold Platform sends a webhook when a dataset reaches one of these statuses:
-
DATASET_COMPUTED -
DATASET_INVALID -
SOLVING_COMPLETED, including when solving the dataset is canceled -
SOLVING_INCOMPLETE -
SOLVING_FAILED
By default, datasets that are part of an experiment don’t trigger webhooks, even when the webhook has no filter.
To include datasets in experiments, set the filter’s experimentScope.
For more about these statuses, see Dataset lifecycle.
Managing webhooks
All endpoints are relative to /api/admin/v1/tenants/{tenantId}:
| Method | Path | Description |
|---|---|---|
|
|
Lists the tenant’s webhooks. |
|
|
Creates a webhook. |
|
|
Retrieves a webhook. |
|
|
Replaces a webhook. |
|
|
Deletes a webhook. |
|
|
Lists one webhook’s delivery logs. See Logs. |
|
|
Lists the delivery logs of all the tenant’s webhooks. See Logs. |
For example, a POST request to /notifications/webhooks with the following body creates a webhook that only triggers for failed datasets that have the production tag:
{
"name": "Failed production datasets",
"url": "https://my-app.example.com/timefold/webhook",
"headers": {
"X-Api-Key": "{secret.3f1c2b9e-5d7a-4c1e-9a0b-6e2f8d4c1a7b}"
},
"filter": {
"status": "SOLVING_FAILED",
"tags": ["production"]
}
}
-
name: required (at most 60 characters). -
url: required (must be an allowed URL). -
enabled: optional (defaults totrue). Timefold Platform only sends enabled webhooks. -
headers: optional. Static HTTP headers that Timefold Platform sends with each request. Header values can reference a secret with{secret.<id>}. -
filter: optional. Timefold Platform only sends the webhook for datasets that match all the filter’s conditions:-
status: one of the statuses in When webhooks trigger. -
name: a regular expression that must match the full dataset name. -
tags: a list of tags (a dataset must have all the listed tags). -
experimentScope:NON_EXPERIMENTS_ONLY(default) only matches datasets outside experiments,EXPERIMENTS_ONLYonly matches datasets in experiments, andALLmatches both.
-
-
authentication: optional. See HMAC authorization.
The response contains the webhook’s id, which you use as {webhookId} in the other endpoints.
Secrets
Webhook headers and the HMAC key reference secrets by ID.
Secrets require an AES key, set as secrets.data.aesKey in your values file.
For how to generate the key, see the upgrade instructions for 1.12.0.
Create a secret through the admin API with POST /api/admin/v1/tenants/{tenantId}/secrets:
{
"name": "webhook-api-key",
"description": "API key of my application's webhook endpoint",
"value": "my-api-key",
"shared": true
}
name, value, and shared are required.
The response contains the secret’s id, which you reference as {secret.<id>} in the webhook’s headers or authentication.hmacKey.
Webhook payload
Timefold Platform sends the payload as JSON in a POST request with a Content-Type: application/json header:
{
"id": "c66fd396-f34f-4320-b702-4adc02ebdf1b",
"parentId": "4d440919-84dd-4be5-88c3-0ece129dd26d",
"originId": "4d440919-84dd-4be5-88c3-0ece129dd26d",
"name": "My dataset",
"model": "employee-scheduling",
"modelVersion": "v1",
"tags": ["system.type:from-input"],
"status": "SOLVING_COMPLETED",
"runLink": "https://timefold.example.com/api/models/employee-scheduling/v1/schedules/c66fd396-f34f-4320-b702-4adc02ebdf1b/metadata",
"outputLink": "https://timefold.example.com/api/models/employee-scheduling/v1/schedules/c66fd396-f34f-4320-b702-4adc02ebdf1b"
}
-
runLink: the API endpoint for the dataset’s metadata. -
outputLink: the API endpoint for the dataset’s output.
Retry strategy
Timefold Platform expects the webhook URL to return an HTTP status code between 200 and 299. Timefold Platform doesn’t follow redirects: a redirect response is a failed delivery, so point the webhook at its final URL. If the response code is different, or the connection can’t be established, Timefold Platform tries again ten seconds later, up to ten times. Timefold Platform only keeps pending retries in memory. Pending retries are lost when Timefold Platform restarts.
After the last failed retry, Timefold Platform emails the tenant administrators. The tenant administrators receive at most one of these emails every two hours per webhook. Timefold Platform only sends these emails when the installation has an SMTP server configured.
Timeouts
Timefold Platform applies a five-second connect timeout and a five-second read timeout:
-
Connect timeout: your endpoint didn’t accept the connection in time. Timefold Platform retries connect timeouts using the retry strategy above.
-
Read timeout: your endpoint accepted the connection but didn’t respond in time. Timefold Platform doesn’t retry read timeouts, to avoid delivering the same webhook request more than once.
To change the timeouts, set them in your values file:
notifications:
webhook:
connectTimeout: PT5S
readTimeout: PT5S
| Timefold Platform doesn’t use the webhook response body, only the HTTP status code. When a webhook request arrives, your endpoint should put the event in a queue and return HTTP 200 immediately. A background worker that consumes from that queue then does the actual work, such as fetching the output. |
HMAC authorization
HMAC authorization lets your application verify that a webhook request comes from your Timefold Platform installation.
To enable HMAC authorization, add authentication to the webhook:
{
"authentication": {
"type": "HMAC",
"hmacMethod": "BODY",
"hmacKey": "{secret.8a2d4f60-1b3c-4e5f-9d7a-2c6b0e1f3a95}"
}
}
-
type:HMACenables HMAC authorization, andNONE(default) disables it. -
hmacMethod:BODY(default) signs the payload.PATHsignsPOST+<path>+<timestamp>, where<path>is the lowercased URL path without the query string. -
hmacKey: a reference to the secret that holds the HMAC key.
Timefold Platform then includes the following headers in each webhook request:
-
X-Timefold-Signature: thebase64encodedHMAC_SHA_256signature. -
X-Timefold-Timestamp: the time of the request, in ISO-8601 formatyyyy-mm-ddThh:mm:ssZ.
To also send the signature and timestamp under other header names, or with a prefix or postfix, use {hmac_signature} and {hmac_timestamp} in the headers values.
For how to verify the signature, see the verification examples for Timefold Cloud Platform.
Logs
Timefold Platform keeps the webhook configuration in your remote data store, but only keeps delivery logs in memory. The delivery logs are lost when Timefold Platform restarts.
To read the delivery logs, use the logs endpoints in Managing webhooks. Both logs endpoints accept these query parameters:
-
status: optional (COMPLETED,FAILED,INTERRUPTED, orIGNORED, and repeat the parameter for more than one status). -
page: optional (the page index, defaults to0). -
size: optional (the number of logs per page, defaults to100).
The /notifications/webhooks/logs endpoint also accepts datasetId, modelName, and modelVersion to filter the logs by dataset, model, and model version.
Timefold Platform also writes webhook activity to the platform logs, with the dataset ID and the tenant ID:
-
INFO: successful deliveries, and datasets that a webhook’s filter skipped. -
WARN: failed deliveries.
Allowed URLs
By default, Timefold Platform only accepts webhook URLs that:
-
use
https -
have a host made of letters, digits, dots, and hyphens (which excludes IPv6 addresses)
-
don’t have a host that starts with
localhost,127.0.,192.168., or172. -
have a host that resolves only to public addresses, so not to private, loopback, link-local (such as the
169.254.169.254cloud metadata address), shared (100.64.0.0/10), multicast, or reserved addresses
Timefold Platform checks the URL when you create or update a webhook. Webhooks created before this check aren’t checked again.
To accept other URLs, such as URLs of internal hosts, set a regular expression in your values file:
notifications:
webhook:
allowedUrls: "^https://[a-zA-Z0-9.-]+\\.internal\\.example\\.com(/.*)?$"
The regular expression replaces the default check instead of adding to it, so Timefold Platform no longer checks the addresses the host resolves to.
Make sure your regular expression also requires https and excludes any hosts that you don’t want Timefold Platform to call.