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 package | Chain member | |
|---|---|---|
| Quoted against | The policy as it stands | The policy with every earlier member laid over it |
| Applied | On its own, with the apply endpoint | Only by applying the chain, in order |
| Archived | On its own, with the archive endpoint | Only by archiving the chain, or by removing it from the chain |
| Re-quoted before apply | Only when refresh is enabled | Always |
| Extra fields | None | chain_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
| Status | Meaning | What you can do |
|---|---|---|
building | The chain is being built. No member is applied. | Append, reorder, detach, refresh, duplicate, apply, schedule, archive |
applying | An apply has started, or has stopped part way. apply_error is set when it stopped. | Apply again to resume a stopped run, or archive |
applied | Every member was applied. | Nothing. The chain is final. |
archived | The 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}/itemsBy 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 packagesMove 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 changeReorder, 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_idand 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}/detachThe 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}/refreshIf 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}/duplicateEvery 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_countcounts the members that aren't archived,estimated_monthly_premiumis the last of those members' premium,stalesays whether the chain needs a refresh, andscheduled_apply_atsays when it is scheduled to apply. - Retrieve a chain for its members in order, with each member's
apply_outcome, and for the chain'sstale,changed_fieldsandscheduled_apply_at. - List a policy's alteration packages with
?chained=falsefor standalone packages only, or?chained=truefor 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}/applyThe 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:
statusisapplied: every member was applied, orapply_erroris set: the run stopped. See when an apply stops.
For each member, in order, the platform:
- Checks that the policy has not changed outside the chain.
- Quotes the member again against the policy as it now stands, and compares the quote with the one you reviewed.
- Applies the member, with the
moduleandchange_descriptionfrom that new quote. - Runs the member's
afterAlterationPackageAppliedhook 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
appliedorarchived. - 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, ornullwhen 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.outcome | Why the run stopped | Extra fields |
|---|---|---|
stale | The policy changed outside the chain. | changed_fields |
quote_changed | The 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_failed | Applying the member failed. | |
after_hook_failed | The 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.
- Refresh the chain. Every member is quoted again against the policy as it stands now.
- Review the new quotes.
- 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 againA resumed run still quotes each remaining member again before applying it. If the member stopped as
quote_changedand 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-inScheduling needs the
scheduled_alteration_applyfeature flag for your organization. Without it, the schedule endpoint returns403. 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
buildingchain can be scheduled. Scheduling any other chain returns400. - 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.
- 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.
- If the chain is not stale, every member is quoted again, but nothing is saved.
- If any member's quote changed, so its
monthly_premium,sum_assured,billing_frequencyorcurrencydiffers from the one scheduled, nothing is applied. The chain staysbuildingand 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. - 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:
| Task | When |
|---|---|
Scheduled alteration package chain not applied | Nothing was applied. The task names the chain and the first member whose quote changed, or the error. |
Scheduled alteration package chain stopped | The 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}/scheduleThe 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: trueand the changed fields inchanged_fields.changed_fieldsis empty when the chain only needs a refresh after a stopped apply. - Append, move a package into the chain, and apply return
409withchanged_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
afterAlterationPackageCreatedThe 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
afterAlterationPackageAppliedIn 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-chainsto 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 isalteration_package_application_id. - Fewer fields make a chain stale:
status,sum_assured,monthly_premium,base_premium,billing_frequencyandmodule. - 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 appliedandScheduled 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
| Action | Policy | Application |
|---|---|---|
| Create | Create a chain | Create a chain |
| Start from a package | Create from a package | Create from a package |
| List | List chains | List chains |
| Retrieve | Retrieve a chain | Retrieve a chain |
| Append | Append | Append |
| Move a package in | Append from a package | Append from a package |
| Move a member out | Detach | Detach |
| Reorder or remove | Reorder | Reorder |
| Refresh | Refresh | Refresh |
| Duplicate | Duplicate | Duplicate |
| Apply | Apply | Apply |
| Schedule | Schedule | Schedule |
| Cancel a schedule | Cancel the schedule | Cancel the schedule |
| Archive | Archive | Archive |
Updated about 2 hours ago