> For the complete documentation index, see [llms.txt](https://apidocs.akinon.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apidocs.akinon.com/commerce-openapis/admin/package-notifications/send-a-package-notification-email.md).

# Send a package notification email

Receives an Omnitron package webhook body and sends the seller (stock location) the email that matches the event type. Nothing is stored: the request is validated, one email is rendered from `payload` and sent, and an empty object is returned.

`event.type` selects the templates — `package.created` sends the package-created mail, `package.status.preparing` sends the offer-accepted mail. Any other value is rejected with `400`.

The whole `payload` object is exposed to the templates as `data`, so send the complete package representation. Two members are required by the server itself: `stock_location.email`, which becomes the primary recipient, and `created_date`, which must be a UTC timestamp matching `YYYY-MM-DDTHH:MM:SS.fffZ` and is shifted forward by `PACKAGE_EXTRA_MINUTES` before rendering. A missing or unparsable `created_date`, or a missing `stock_location` object, fails with `500` rather than `400`.

The email is sent synchronously, but a `200` does not guarantee delivery was attempted: the send is skipped silently when the event's body template is switched off through the `DISABLED_EMAIL_TEMPLATES` dynamic setting, or when the subject or body template is missing or fails to render. If a message is composed and the mail backend rejects it, the request fails with `500` — a retry re-sends the mail. See the **Package Notifications** section for the settings that control recipients, copy addresses and the deadline offset.

```json
{"openapi":"3.1.0","info":{"title":"Admin API","version":"1.0.0"},"tags":[{"name":"Package Notifications","description":"A single administrative endpoint that turns a **package** event into an outbound email to the seller (stock location) the package belongs to. The caller — Omnitron or any integration that observes package events — posts the event and the package it concerns, and the endpoint sends the notification mail that matches the event type.\n\nThe endpoint is **stateless** — no package record is created, read, or stored. Each request renders one email from the payload it carries and hands it to the mail backend, so there is nothing to list, retrieve, update, or delete. `POST /packages/notify/` is the only operation on `/packages/`; no other path or method under that prefix is routed.\n\n## Core Capabilities\n\n**1. Event-driven Seller Notification**\n* Accept a package webhook body (`event` + `payload`) and send the email that corresponds to the event type.\n* The recipient is the email address of the stock location carried in the payload, plus any fixed addresses configured on the installation.\n\n**2. Template Selection by Event Type**\n* The event type selects both the subject template and the body template. The entire `payload` object is exposed to those templates as `data`, so the mail content is fully determined by what the caller sends.\n* Templates are resolved through the Jinja loader configured for the environment (`TEMPLATE_LOADER`). Akinon Cloud deployments use a loader that also serves templates stored in the database, so a project can override the shipped body and subject there without a code change; otherwise the files under `shop_templates/` are used.\n\n## Event Types\n\nOnly the two event types below are accepted; any other value is rejected with `400` before an email is composed.\n\n| `event.type` | Purpose | Body template | Subject template |\n|--------------|---------|---------------|------------------|\n| `package.created` | Tells the seller a new package has been created and is awaiting its confirmation. | `emails/orders/package-created.html` | `emails/orders/package-created-subject.html` |\n| `package.status.preparing` | Tells the seller its offer was accepted and the package has moved to preparing. | `emails/orders/offer-accepted.html` | `emails/orders/offer-accepted-subject.html` |\n\n## Payload Requirements\n\n`payload` is a free-form object — it is handed to the template as `data` — but two members are consulted by the server itself:\n\n| Field | Required | Used for |\n|-------|----------|----------|\n| `stock_location` | Yes | Must be present as an object. Omitting it entirely leaves the server unable to resolve a recipient and the request fails with `500`. |\n| `stock_location.email` | Yes | The primary recipient of the email. A `stock_location` that carries no `email` is rejected with `400` and the body `{\"payload\": [\"stock location requires email\"]}`. |\n| `created_date` | Yes | Required for **both** event types. Parsed as a UTC timestamp that must match `YYYY-MM-DDTHH:MM:SS.fffZ` — date and time separated by `T`, fractional seconds (1–6 digits) and a trailing `Z`, for example `2020-03-23T12:12:12.123Z`. It is converted to the installation's local time zone and then moved forward by `PACKAGE_EXTRA_MINUTES` before being exposed to the template as `data.created_date`, which is how the shipped package-created template shows the seller a confirmation *deadline* rather than the creation instant. The offer-accepted template does not render it, but the value is still parsed for that event. A missing value or a different format cannot be parsed and the request fails with `500`. |\n\nEvery other member is optional as far as validation goes. The shipped templates read the fields below and render them empty when they are absent, so send the full package representation from Omnitron rather than a trimmed object.\n\n| Payload field | Used by |\n|---------------|---------|\n| `number` | Both templates — the package number shown in the mail. |\n| `order_number` | `package.created` — the order the package belongs to. |\n| `stock_location.name` | Both templates — the seller name in the greeting. |\n| `stock_location.address.city.name`, `stock_location.address.township.name` | `package.created` — the pickup address shown to the seller. |\n| `shipping_address.customer.first_name`, `shipping_address.customer.last_name`, `shipping_address.line`, `shipping_address.postcode`, `shipping_address.district.name`, `shipping_address.township.name`, `shipping_address.city.name`, `shipping_address.country.name` | `package.status.preparing` — the delivery address block. |\n| `packageitem_set[].id` | `package.created` — the package item identifier per line. |\n| `packageitem_set[].order_item.product.name`, `packageitem_set[].order_item.product.sku` | Both templates — the product lines of the package. |\n| `packageitem_set[].order_item.price_currency`, `packageitem_set[].order_item.extra_field.price_extra_field.offer_price` | `package.created` — the offered price per line. |\n\nThe shipped package-created template also references `SHOP_NAME`, `LOGO_URL` and `INSTORE_URL`. These are **not** taken from the payload and are not defined by the platform's default Jinja configuration, so they render empty unless the installation supplies them through its own template environment.\n\n## Delivery Semantics\n\nThe email is composed and sent **synchronously**, within the request. A `200` response therefore means the request was valid and processing finished — but it does **not** guarantee a message was handed to the mail backend, because the send is skipped silently in these cases:\n\n* the body template for the event is switched off through `DISABLED_EMAIL_TEMPLATES`;\n* the subject template is missing or raises while rendering;\n* the body template is missing or raises while rendering.\n\nIn all three cases the response is still `200` with an empty object; check the application logs when an expected mail does not arrive.\n\nDelivery is **not** fail-silent, however: when a message is actually composed and the mail backend rejects it or is unreachable, the error propagates and the request fails with `500`. Retrying such a request re-sends the mail, so treat the operation as at-least-once rather than idempotent.\n\n## Dynamic Settings & Environment Variables\n\nBoth dynamic settings below are registered in `omnishop/users/settings/conf.py` and are keyed by **template key** — the template path with its extension removed (`emails/orders/package-created`, `emails/orders/offer-accepted`). They are shared with every other outbound email of the platform; only the two keys used by this endpoint are described here.\n\n| Key | Type | Default | Effect |\n|-----|------|---------|--------|\n| `DISABLED_EMAIL_TEMPLATES` | object — template key → boolean | Every template key `false`, except `emails/orders/preparing` which is `true` | Per-template kill switch, evaluated on the **body** template of the incoming event: `emails/orders/package-created` for `package.created`, `emails/orders/offer-accepted` for `package.status.preparing`. When the relevant key is `true`, `POST /packages/notify/` still validates the request and answers `200`, but no email is sent. Neither of the two keys used here is disabled by default. |\n| `EMAIL_BCC_AND_CC` | object — template key → `{\"cc\": [email], \"bcc\": [email]}` | Every template key mapped to `{\"cc\": [], \"bcc\": []}` | Fixed copy recipients added to the message, looked up by the same body-template key. The addresses in `cc` are visible to the recipient, those in `bcc` are not. Both lists are validated as email addresses when the setting is written. |\n\n**Django settings / environment variables**\n\n| Setting | Type | Default | Effect |\n|---------|------|---------|--------|\n| `PACKAGE_CREATED_MAILS` | list of email addresses | `[]` | Appended to the recipient (`To`) list of **every** notification sent by this endpoint, alongside the stock location's own address. Read with a fallback, so an installation that does not define it simply sends to the stock location only. |\n| `PACKAGE_EXTRA_MINUTES` | integer (minutes) | `180` (3 hours) | Added to `payload.created_date` before it is given to the template, producing the confirmation deadline the seller sees. Read with a fallback. |\n| `NO_REPLY_EMAIL` | string (email) | `noreply@akinon.com` | The `From` address of the message. Set per environment through the `NO_REPLY_EMAIL` environment variable. This endpoint reads the **Django setting**; the same-named dynamic setting registered in `omnishop/cms/settings/conf.py` is used by other flows and has no effect here. |\n\nThe mail backend itself (`EMAIL_BACKEND`, `EMAIL_HOST`, `EMAIL_HOST_USER`, `EMAIL_HOST_PASSWORD`, `EMAIL_PORT`, `EMAIL_USE_TLS`) is configured per environment and applies to all platform email, not only to this endpoint."}],"servers":[{"description":"Omnitron Remote Proxy (external access — recommended)","url":"https://{omnitron_url}/api/v1/remote/{channel_id}","variables":{"omnitron_url":{"default":"sandbox.akinon.com","description":"Omnitron server URL (e.g., {omnitron.akinon.com})"},"channel_id":{"default":"1","description":"The channel identifier the remote request is routed through"}}},{"description":"Commerce API Server (internal / direct access only)","url":"https://{commerce_url}/api/v1","variables":{"commerce_url":{"default":"sandbox.akinon.com","description":"Internal commerce server URL, reachable only from within the Omnitron network"}}}],"security":[{"tokenAuth":[]}],"components":{"securitySchemes":{"tokenAuth":{"type":"apiKey","in":"header","name":"Authorization","description":"Token credential sent in the Authorization header, in the form: `Token <your-token>`. Requires a staff (admin) account."}},"schemas":{"PackageNotifyRequest":{"type":"object","description":"An Omnitron package webhook body — the event that occurred and the package it concerns.","required":["event","payload"],"properties":{"event":{"$ref":"#/components/schemas/PackageNotifyEvent"},"payload":{"$ref":"#/components/schemas/PackageNotifyPayload"}}},"PackageNotifyEvent":{"type":"object","description":"The event descriptor of the package webhook. Only `type` is interpreted; any other member Omnitron sends (for example the event `uuid`) is accepted and ignored.","required":["type"],"properties":{"type":{"type":"string","description":"The package event that occurred. Determines which subject and body template is rendered. Any value other than the two below is rejected with `400`.\n* `package.created` — a new package was created and awaits the seller's confirmation\n* `package.status.preparing` — the seller's offer was accepted and the package moved to preparing","enum":["package.created","package.status.preparing"]}},"additionalProperties":true},"PackageNotifyPayload":{"type":"object","description":"The package representation emitted by Omnitron. Passed to the email templates as `data` in full, so any member the templates reference may be included. `stock_location` and `created_date` are consulted by the server itself and must be present.","required":["stock_location","created_date"],"properties":{"stock_location":{"type":"object","description":"The stock location (seller) the package belongs to, and the recipient of the email.","required":["email"],"properties":{"email":{"type":"string","format":"email","description":"The primary recipient of the notification. Required — a `stock_location` without an `email` is rejected with `400`."},"name":{"type":"string","description":"Display name of the stock location, used in the greeting of both templates."},"address":{"type":"object","description":"Address of the stock location. The package-created template shows its city and township.","additionalProperties":true}},"additionalProperties":true},"created_date":{"type":"string","description":"When the package was created, as a UTC timestamp matching `YYYY-MM-DDTHH:MM:SS.fffZ` — fractional seconds (1–6 digits) and a trailing `Z` are required. Converted to the installation's local time zone and shifted forward by `PACKAGE_EXTRA_MINUTES` before being rendered, so the package-created template can display a confirmation deadline. Required for both event types; another format cannot be parsed."},"number":{"type":"string","description":"The package number shown in both emails."},"order_number":{"type":"string","description":"The order the package belongs to; shown in the package-created email."},"shipping_address":{"type":"object","description":"The customer's delivery address; rendered by the offer-accepted email.","additionalProperties":true},"packageitem_set":{"type":"array","description":"The lines of the package. Both templates list the product name and SKU of each `order_item`; the package-created template additionally shows the item identifier, the currency and the offered price taken from `order_item.extra_field.price_extra_field.offer_price`.","items":{"type":"object","additionalProperties":true}}},"additionalProperties":true},"ValidationError":{"type":"object","description":"Returned when the request contains invalid or missing data. Errors are grouped by the field they apply to: each key is the name of a field from the request and its value is a list of one or more messages describing what is wrong with that field. Messages that do not belong to any single field are grouped under `non_field_errors`.","properties":{"non_field_errors":{"type":"array","description":"Error messages that apply to the request as a whole rather than to a specific field.","items":{"type":"string"}}},"additionalProperties":{"type":"array","description":"The list of error messages for the field named by the key.","items":{"type":"string"}}},"Error":{"type":"object","description":"An error response.","properties":{"detail":{"type":"string","description":"A human-readable description of the error."}},"additionalProperties":true}},"responses":{"Unauthorized":{"description":"Authentication credentials were not provided or are invalid.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"Forbidden":{"description":"The authenticated user does not have administrator privileges.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"paths":{"/packages/notify/":{"post":{"tags":["Package Notifications"],"operationId":"notifyPackage","summary":"Send a package notification email","description":"Receives an Omnitron package webhook body and sends the seller (stock\nlocation) the email that matches the event type. Nothing is stored: the\nrequest is validated, one email is rendered from `payload` and sent, and\nan empty object is returned.\n\n`event.type` selects the templates — `package.created` sends the\npackage-created mail, `package.status.preparing` sends the offer-accepted\nmail. Any other value is rejected with `400`.\n\nThe whole `payload` object is exposed to the templates as `data`, so send\nthe complete package representation. Two members are required by the\nserver itself: `stock_location.email`, which becomes the primary\nrecipient, and `created_date`, which must be a UTC timestamp matching\n`YYYY-MM-DDTHH:MM:SS.fffZ` and is shifted forward by\n`PACKAGE_EXTRA_MINUTES` before rendering. A missing or unparsable\n`created_date`, or a missing `stock_location` object, fails with `500`\nrather than `400`.\n\nThe email is sent synchronously, but a `200` does not guarantee delivery\nwas attempted: the send is skipped silently when the event's body\ntemplate is switched off through the `DISABLED_EMAIL_TEMPLATES` dynamic\nsetting, or when the subject or body template is missing or fails to\nrender. If a message is composed and the mail backend rejects it, the\nrequest fails with `500` — a retry re-sends the mail. See the\n**Package Notifications** section for the settings that control\nrecipients, copy addresses and the deadline offset.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PackageNotifyRequest"}}}},"responses":{"200":{"description":"The request was valid and processed. The body is always an empty object; it carries no information about whether an email was actually sent.","content":{"application/json":{"schema":{"type":"object","description":"Always empty.","additionalProperties":false}}}},"400":{"description":"The request body is invalid. The response body maps the offending\nfield to its error message.\n\n| Cause | Body |\n|-------|------|\n| `event.type` is not one of the two accepted values | `{\"event\": [\"invalid event type\"]}` |\n| `payload.stock_location` is missing or is not an object | `{\"payload\": [\"payload requires stock location\"]}` |\n| `payload.stock_location` carries no `email` | `{\"payload\": [\"stock location requires email\"]}` |\n| `payload.created_date` is missing or does not match `YYYY-MM-DDTHH:MM:SS.fffZ` | `{\"payload\": [\"created date must be in YYYY-MM-DDTHH:MM:SS.fffZ format\"]}` |","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ValidationError"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://apidocs.akinon.com/commerce-openapis/admin/package-notifications/send-a-package-notification-email.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
