> For the complete documentation index, see [llms.txt](https://docs.tryterra.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tryterra.co/faq/help-topics/data-api-sdk/extra-features-scores-graphs-teams-nutrition-cgm/nutrition-meals-upsert-no-stable-id.md).

# How do I dedup updated vs new meals across nutrition webhooks?

**Treat meals within a nutrition payload like samples, not ID-dependent records.** Each payload is a full-day snapshot keyed to the calendar date of `metadata.start_time`, so **upsert (overwrite) the entire `meals` array per (`user_id`, date) on each receipt**.

Why:

* Each meal object carries `id`, `timestamp` (ISO 8601, microsecond precision), `name`, `type`, `quantity` and `micros`, but `meal.id` is not reliably stable across webhooks and some providers omit it, so do not rely on it as a universal key.
* For incremental processing, key meals on a composite of `timestamp` + `name` + `type`, and hash the content to detect new/updated/unchanged/deleted entries.

{% hint style="info" %}
Meals are populated per entry (with their own timestamps), including for Apple Health, so dedup on the per-meal fields rather than assuming a single daily blob.
{% endhint %}

For a [historical backfill](https://docs.tryterra.co/health-and-fitness-api/managing-user-health-data/requesting-historical-data), large REST responses are split into chunks (at most 10MB or 10 objects per chunk, whichever hits first), all sharing one `terra-reference` header. To capture edits to past dates the polling cycle may miss, do an explicit `GET /v2/nutrition` pull for that date range.
