> 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.


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tryterra.co/faq/help-topics/data-api-sdk/extra-features-scores-graphs-teams-nutrition-cgm/nutrition-meals-upsert-no-stable-id.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
