Alteration package chains

Build several alteration packages into a chain, review the combined price, and apply them in order, now or on a scheduled date.

Overview

An alteration package chain is an ordered list of pending alteration packages for one policy. Each member is quoted on top of the members before it, so you can build several changes, review the combined price, and then apply them together in order.

Use a chain when the changes depend on each other. For example, add a spouse and then increase cover: the cover increase is priced against the policy that already includes the spouse. With standalone packages, both would be quoted against the policy as it stands, and applying one would leave the other out of date.

The dashboard calls a chain a sequence.

Applications have chains too. They work the same way, with the differences listed in application chains.

Each step below links to its page in the API reference. Endpoints lists every chain endpoint, for policies and applications.

Chains and standalone packages

Standalone alteration packageChain member
Quoted againstThe policy as it standsThe policy with every earlier member laid over it
AppliedOn its own, with the apply endpointOnly by applying the chain, in order
ArchivedOn its own, with the archive endpointOnly by archiving the chain, or by removing it from the chain
Re-quoted before applyOnly when refresh is enabledAlways
Extra fieldsNonechain_id, chain_position and, after the first member, based_on_alteration_package_id

A chain member can't be applied, refreshed or archived on its own. Those endpoints return 400 and name the chain. Apply, refresh or archive the chain instead.

How members are quoted

The first member is quoted against the policy as it stands. From the second member on, the product module quotes against a virtual policy: the saved policy with the earlier members' quotes laid over it. The virtual policy is never saved.

The virtual policy takes monthly_premium, billing_amount, sum_assured, billing_frequency and module from the earlier members. Every other field keeps the saved policy's value. So a quote after the first member is an estimate, and the price that is applied can differ from it.

The platform catches that difference. Just before each member is applied, it is quoted again against the real policy, which by then includes every earlier member. If monthly_premium, sum_assured, billing_frequency or currency differs from the quote you reviewed, the apply stops at that member. See when an apply stops.

Chain statuses

StatusMeaningWhat you can do
buildingThe chain is being built. No member is applied.Append, reorder, detach, refresh, duplicate, apply, schedule, archive
applyingAn apply has started, or has stopped part way. apply_error is set when it stopped.Apply again to resume a stopped run, or archive
appliedEvery member was applied.Nothing. The chain is final.
archivedThe chain was archived. Members that were still pending were archived with it.Nothing. The chain is final.

A policy can have many building chains, but only one chain per policy can be applying at a time.

Build a chain

Create a chain

Create a chain with its first member. The request body is the same as for a standalone alteration package: the alteration hook key and its data.

POST /v1/insurance/policies/{policy_id}/alteration-package-chains
{
  "key": "increase_cover",
  "data": {
    "increase": 100000
  }
}

The response is the chain with its members in alteration_packages. The alteration hook must return exactly one package. A hook that returns none, or several, gives 400.

You can also give the chain a name, so you can tell chains on the same policy apart. It is optional: 1 to 100 characters, on a single line. A chain can't be renamed after it is created.

Start a chain from a standalone package

If a pending standalone package already exists, start a chain from it instead of quoting it again by hand.

POST /v1/insurance/policies/{policy_id}/alteration-package-chains/from-package
{
  "alteration_package_id": "7c1e9a52-3f4b-4d8a-b6e0-1a2c3d4e5f60",
  "name": "Add spouse, then increase cover"
}

The platform quotes the package's alteration hook again and makes the result the chain's first member. In the same transaction it archives the standalone package and cancels any scheduled apply on it. name is optional, as for create. This endpoint needs both the create and the archive alteration packages permissions.

Add a member

Append to the chain with another key and data. The new member goes to the end and is quoted against the policy with every earlier member laid over it.

POST /v1/insurance/alteration-package-chains/{alteration_package_chain_id}/items

By default, a chain holds at most 20 members. Appending to a full chain, or moving a package into it, returns 400. The error message states the limit:

Alteration package chain '{alteration_package_chain_id}' can't be appended to: it already holds the maximum of 20 alteration packages

Move a standalone package into a chain

If a pending standalone package already exists, move it into the chain instead of quoting it again by hand.

POST /v1/insurance/alteration-package-chains/{alteration_package_chain_id}/items/from-package
{
  "alteration_package_id": "7c1e9a52-3f4b-4d8a-b6e0-1a2c3d4e5f60"
}

The platform quotes the package's alteration hook again, on top of the chain, and adds the result as a new member. In the same transaction it archives the standalone package and cancels any scheduled apply on it, so the change is never pending twice. This endpoint needs both the create and the archive alteration packages permissions.

Reorder or remove members

Reorder the chain by sending every member to keep, in the new order. A member you leave out is removed from the chain and archived.

PUT /v1/insurance/alteration-package-chains/{alteration_package_chain_id}/order
{
  "alteration_package_ids": [
    "7a1c3e5f-9b2d-4f6a-8c0e-1d3f5b7a9c2e",
    "0b4b6c1e-6f0f-4b8a-9d2c-5f1c3a6e7d21"
  ]
}

Every member from the first changed position onward is quoted again, because what it builds on has changed. Each one is replaced by a new alteration package, with refreshed_from_alteration_package_id set to the package it replaces. Members before the first change keep their IDs, unless the chain is stale: then every member is quoted again, from the first.

Sending the order the chain already has changes nothing. No member is quoted again, so a stale chain stays stale. Refresh it instead.

🚧

Member IDs change

Reorder, refresh and detach replace members with new alteration packages, and so does a scheduled apply that refreshes a stale chain. Don't store a member's alteration_package_id and expect it to stay valid. Read the chain again after each change. A duplicate gets new members of its own, and the source chain's member IDs stay valid.

Move a member out of the chain

Detach a member to turn it back into a pending standalone package.

POST /v1/insurance/alteration-package-chains/{alteration_package_chain_id}/items/{alteration_package_id}/detach

The member is quoted again against the policy as it stands, as a new standalone package, which the response returns in alteration_package. Every later member in the chain is quoted again, as with a reorder. You can't detach the only member: archive the chain instead. If an identical standalone package is already pending on the policy, the endpoint returns 409 and names it. This endpoint needs both the create and the archive alteration packages permissions.

Refresh a chain

Refresh the chain to quote every member again against the policy as it stands. Each member is replaced by a new alteration package, and the chain is no longer stale. Refresh after the policy has changed outside the chain, or after an apply that stopped before anything was applied. See staleness.

POST /v1/insurance/alteration-package-chains/{alteration_package_chain_id}/refresh

If a member no longer quotes, for example because the product module now rejects its input, the refresh fails and the chain is left as it was. The error keeps the status code of the failed quote, and its message names the member:

Alteration package chain position 2 (alteration package '{alteration_package_id}') failed: {quote error}

Duplicate a chain

Duplicate the chain to build a variant beside it and compare the two. The copy is a new building chain, and its duplicated_from_alteration_package_chain_id is the source chain. The source chain is not changed.

POST /v1/insurance/alteration-package-chains/{alteration_package_chain_id}/duplicate

Every member is quoted again, in order, against the policy as it stands, so a copy of a stale chain starts current. Only a building chain can be duplicated. The copy is named after the source with (copy) added, and a copy of an unnamed chain has no name. A copy of a scheduled chain is not scheduled.

Read chains

  • List a policy's chains, newest first, up to 100. Filter with ?status=building,applying. Each chain in the list comes without its members: item_count counts the members that aren't archived, estimated_monthly_premium is the last of those members' premium, stale says whether the chain needs a refresh, and scheduled_apply_at says when it is scheduled to apply.
  • Retrieve a chain for its members in order, with each member's apply_outcome, and for the chain's stale, changed_fields and scheduled_apply_at.
  • List a policy's alteration packages with ?chained=false for standalone packages only, or ?chained=true for chain members only. Without it, both are listed.

Retries and concurrent changes

Every POST and PUT endpoint that changes a chain accepts the idempotency_key query parameter, so a retried request is not applied twice. The two DELETE endpoints, archive and cancel a schedule, don't take it. Cancelling a schedule twice is harmless, but a retried archive of a chain that is now archived returns 400.

If two requests change the same chain at once, the second gets 409. Retrieve the chain and try again.

Apply a chain

Apply the chain to apply its members in order. To apply it on a later date instead, schedule it. Applying a scheduled chain yourself cancels its schedule.

POST /v1/insurance/alteration-package-chains/{alteration_package_chain_id}/apply

The apply is asynchronous. The endpoint returns 202 Accepted at once with the chain in status applying, and the members are applied in the background. Retrieve the chain to follow it, until:

  • status is applied: every member was applied, or
  • apply_error is set: the run stopped. See when an apply stops.

For each member, in order, the platform:

  1. Checks that the policy has not changed outside the chain.
  2. Quotes the member again against the policy as it now stands, and compares the quote with the one you reviewed.
  3. Applies the member, with the module and change_description from that new quote.
  4. Runs the member's afterAlterationPackageApplied hook and waits for it to finish. See lifecycle hooks.

Each member's apply_outcome shows how far the run got: applied, not_attempted, or the reason the run stopped at that member.

Policy documents are regenerated once at the end of an apply run, not once for each member.

The apply endpoint returns 409 when:

  • the chain is stale. The error has changed_fields.
  • the chain is applied or archived.
  • the chain is already applying and has not stopped.
  • another chain is applying to the same policy. The error has applying_alteration_package_chain_id, the chain that is applying, or null when it can't be named.

When an apply stops

When a run stops, the chain records why in apply_error, and names the member it stopped at in apply_failed_alteration_package_id. Members already applied stay applied: an applied alteration can't be undone.

apply_error.outcomeWhy the run stoppedExtra fields
staleThe policy changed outside the chain.changed_fields
quote_changedThe member quotes differently now, no longer quotes, or the policy's product module definition changed since it was quoted.diff, when the member quotes differently
apply_failedApplying the member failed.
after_hook_failedThe member was applied, but its afterAlterationPackageApplied hook failed.

Every apply_error has a message. diff lists each quote field that differs, with its path, before and after values. When the re-quote itself fails, or the product module definition changed, there is no diff, and message says why.

What happens next depends on the outcome and on whether any member was applied.

Stale or quote changed, and nothing applied

If the run stopped as stale or quote_changed before any member was applied, the chain goes back to building and refresh_required_at is set. apply_error stays, so you can see why.

  1. Refresh the chain. Every member is quoted again against the policy as it stands now.
  2. Review the new quotes.
  3. Apply the chain again.

Applying without refreshing first returns 409.

Any other stop

In every other case, the chain stays applying with apply_error set. That covers a run that stopped after a member was applied, and one that stopped as apply_failed at the first member, before anything was applied. You can't refresh it, because refresh only works on a building chain. Fix the cause, then either:

  • Resume. Apply the chain again. The run carries on from the member it stopped at, against the policy as it now stands. Members already applied, if any, are skipped. After after_hook_failed, the failed hook runs again before the next member is applied.
  • Stop. Archive the chain. Any members that were applied stay applied, and the rest are archived. Create a new chain for the changes that are left.
🚧

A resume can stop again

A resumed run still quotes each remaining member again before applying it. If the member stopped as quote_changed and still quotes differently, the run stops at it again. Archive the chain, and build a new chain for the remaining changes.

Schedule a chain

Instead of applying a chain now, you can schedule it to apply on a later date. Application chains can be scheduled too: see application chains.

📘

Scheduling is opt-in

Scheduling needs the scheduled_alteration_apply feature flag for your organization. Without it, the schedule endpoint returns 403. Cancelling a schedule works whether or not the flag is on.

PUT /v1/insurance/alteration-package-chains/{alteration_package_chain_id}/schedule
{
  "apply_on": "2026-12-01"
}

apply_on is a date in your organization's timezone, and must be today or later:

  • A later date applies at the start of that day: 00:00, or 00:15 or 00:45 in a timezone whose UTC offset ends in :15 or :45. Scheduled applies run on the hour and half hour in UTC.
  • Today applies at the next of those times that is at least 15 minutes away. If no such time is left today, the endpoint returns 400. Choose a later date.

The response is the chain with scheduled_apply_at, the exact time it will apply. Retrieve or list chains to see it later. scheduled_apply_at is null when the chain is not scheduled, or once its scheduled apply has started.

Rules

  • Only a building chain can be scheduled. Scheduling any other chain returns 400.
  • A policy has at most one scheduled chain. Scheduling a second chain on the same policy returns 409, and the message names the chain that is scheduled.
  • Scheduling a chain that is already scheduled replaces its schedule.
  • Appending to the chain, moving a package in, reordering, detaching and refreshing all keep the schedule.
  • Applying the chain yourself, or archiving it, cancels the schedule.
  • A duplicate of a scheduled chain is not scheduled.

What happens at the scheduled time

The scheduled apply runs as the user or API key that scheduled it. It applies only if every member still quotes what was scheduled.

  1. If the chain is stale, it is refreshed first. Every member is quoted again against the policy as it stands, and replaced by a new alteration package.
  2. If the chain is not stale, every member is quoted again, but nothing is saved.
  3. If any member's quote changed, so its monthly_premium, sum_assured, billing_frequency or currency differs from the one scheduled, nothing is applied. The chain stays building and is no longer scheduled. If it was refreshed in step 1, it keeps the refreshed members, so you can review the new quotes. If not, its members are unchanged.
  4. Otherwise, the chain starts applying, as described in apply a chain.

The platform raises a task on the policy when a scheduled apply doesn't finish, whatever your task management settings:

TaskWhen
Scheduled alteration package chain not appliedNothing was applied. The task names the chain and the first member whose quote changed, or the error.
Scheduled alteration package chain stoppedThe apply started but stopped. The task names the member it stopped at and the apply_error.outcome.

When the apply stopped, recover as in when an apply stops. Either way, the chain is no longer scheduled. Review it, then apply it or schedule it again.

Cancel a schedule

Cancel the schedule to keep the chain without applying it.

DELETE /v1/insurance/alteration-package-chains/{alteration_package_chain_id}/schedule

The endpoint returns 204 No Content, whether or not the chain was scheduled. While the scheduled run is still checking the quotes or refreshing the chain, cancelling stops it before it applies anything. Once the chain is applying, the schedule can't be cancelled, and the endpoint returns 409. To stop a scheduled apply that is running, archive the chain.

Staleness

A chain's quotes are only valid for the policy they were made against. When the chain is quoted, the platform records the policy fields it depends on. If any of them changes outside the chain, the chain is stale.

For a policy, these fields are watched: status, sum_assured, monthly_premium, base_premium, billing_frequency, module, start_date, end_date, charges and covered_items.

Changes that make a chain stale include a standalone alteration package being applied, a policy update, or another chain being applied to the same policy. So after one chain is applied, the policy's other building chains are stale and need a refresh.

When a chain is stale:

  • Retrieve the chain returns stale: true and the changed fields in changed_fields. changed_fields is empty when the chain only needs a refresh after a stopped apply.
  • Append, move a package into the chain, and apply return 409 with changed_fields.
  • Refresh, reorder and detach quote every remaining member again, which clears the staleness.
  • Duplicate creates a chain that is not stale.

stale is always false for a chain that is not building.

Policy writes from the chain's own afterAlterationPackageCreated hooks don't count as a change from outside.

During an apply, the platform checks staleness again before each member. A change made by the chain's own members, or by their afterAlterationPackageApplied hooks, does not count as a change from outside.

Lifecycle hooks

Chain members use the same alteration package lifecycle hooks as standalone packages. Each hook receives the member, including chain_id, chain_position and based_on_alteration_package_id.

afterAlterationPackageCreated

The chain runs this hook itself for each new member, in the background after the request returns. Creating a chain, appending, moving a package in, reordering, detaching, refreshing and duplicating all create new members, so the hook runs for each of them. The alteration_package_created webhook is sent for each new member too.

  • It runs as the requester. The hook runs as the user or API key whose request created the members, so its policy writes are attributed to them.
  • Its writes don't make the chain stale. When the hooks finish, the chain records the policy as the hooks left it. A change from outside the chain that landed before the hooks ran still makes the chain stale.
  • It finishes before the apply starts. The hooks and the apply run in order for each policy. If you apply the chain straight after changing it, the apply waits for the new members' hooks.
  • A member replaced before its hook runs is skipped. If a reorder or refresh replaces the member first, the hook runs for the replacement instead.

If the hook fails with a product module error, it is not retried. If it fails for another reason, it is retried later, outside the chain. Policy writes from that retry can make the chain stale.

When you detach a member, the new standalone package is not in a chain. Its hook runs as it does for any standalone package. The later members that the detach quotes again are chain members, so the chain runs their hooks.

afterAlterationPackageApplied

In a chain, this hook runs in order. The hook for a member, and the actions it returns, finish before the next member is quoted again and applied. The next member is quoted against the policy the hook leaves behind.

So if the hook changes a field the next member is priced from, the next member's quote differs, and the run stops at it as quote_changed.

If the hook fails, the run stops as after_hook_failed. The member stays applied and later members are not attempted. When you resume, the hook runs again before the next member.

Outside a chain, afterAlterationPackageApplied runs asynchronously after the package is applied.

For product module authors, see Alteration hooks.

Archive a chain

Archive the chain to stop it. Every member that is still pending is archived with it. The endpoint returns 204 No Content.

DELETE /v1/insurance/alteration-package-chains/{alteration_package_chain_id}

You can archive a chain that is building or applying. When it is applying, members already applied stay applied, and a running apply stops before its next member. You can't archive a chain that is applied or archived: the endpoint returns 400. Archiving a scheduled chain cancels its schedule.

Application chains

Applications have their own chains. They work like policy chains, with these differences:

  • The routes start from the application: /applications/{application_id}/alteration-package-chains to create and list, and /application-alteration-package-chains/{alteration_package_chain_id} for the rest. See endpoints.
  • The chain ID is application_alteration_package_chain_id, and each member's ID is alteration_package_application_id.
  • Fewer fields make a chain stale: status, sum_assured, monthly_premium, base_premium, billing_frequency and module.
  • An application that is issued or cancelled can't take a chain, and its chains can't be applied.
  • No lifecycle hooks run for application alteration packages, so an application chain never stops as after_hook_failed.
  • An application has at most one scheduled chain. Issuing, cancelling or archiving the application cancels the schedule. The tasks are raised on the application, and are called Scheduled application alteration package chain not applied and Scheduled application alteration package chain stopped.
  • List an application's alteration packages takes the same ?chained= filter.
  • The endpoints need the application alteration packages permissions.

Endpoints


Did this page help you?