# Managed API Extensions

**Intercept and modify commercetools writes before they are persisted.**

A [commercetools API Extension](/api/projects/api-extensions.md) is a synchronous HTTP callback that commercetools makes before it persists a Cart, Order, Customer, or other write. The callback can approve the write, modify it by returning update actions, or block it by returning a validation error.

Managed API Extensions intercept writes for all clients. They are authored in the same bundle and sandbox as schema extensions, and the Commerce Integration Layer registers them automatically. You can use the `cart-sku-blocker` template in the [Commerce Integration Layer extension examples](https://github.com/commercetools/commerce-integration-layer-extensions) repository to get started with Managed API Extensions.

"Managed" refers to the operational model, not the underlying mechanism. These extensions use the standard commercetools API Extensions feature. The Commerce Integration Layer hosts the callback service and handles registration. Handlers receive the resource being written, without access to the shopper's session or request context. See [extension context (`ctx`)](/commerce-integration-layer/development/writing-schema-extensions.md#extension-context-ctx).

To decide whether a requirement belongs in a Managed API Extension or a schema extension, see [Choose an extension type](/commerce-integration-layer/extension-types.md).

## How it works

You export an `apiExtensions` array of handlers from your bundle. When you publish the bundle, the Commerce Integration Layer reads the declared handlers and registers them with commercetools, pointing each callback at the extensions sandbox with an authenticated destination. You never call the commercetools Extensions API yourself.

When a matching write happens, commercetools calls your handler synchronously. The handler inspects the incoming resource and returns a decision. Because the callback runs before the write is saved, a handler that blocks prevents the write entirely.

```mermaid
flowchart LR
	W["commercetools write<br/>(Cart / Order / …)"]
	CT["commercetools"]
	X["Your apiExtensions handler<br/>(extensions sandbox)"]
	W --> CT
	CT -->|"synchronous callback, before save"| X
	X -->|"approve / modify / block"| CT
```

## Further reading

Find guidance in [Write Managed API Extensions](/commerce-integration-layer/development/writing-managed-api-extensions.md) on how to declare handlers, configure triggers and payload options, chain handlers, and test locally.

## Related pages

- [Area overview page with navigation](/commerce-integration-layer.md)
- [Previous page: Schema Extensions](/commerce-integration-layer/schema-extensions.md)
- [Search documentation and API specs](/search.md)