> ## Documentation Index
> Fetch the complete documentation index at: https://betterdatainc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Demand History Field Mapping

> Map source demand history fields to Better Data demand history fields.

## Overview

Demand history import stores weekly actual and forecast values used by planning workflows.
Records are grouped by SKU, location, week start, and channel.

## Quick Start

1. Build `records[]` with weekly demand rows.
2. POST to `/api/import/demand-history`.
3. Poll `/api/import/status/[jobId]`.

## Field Reference

| Better Data Field  | Type   | Required | Example      | Description                                 |
| ------------------ | ------ | -------- | ------------ | ------------------------------------------- |
| `skuId`            | string | YES      | `SKU-001`    | SKU identifier.                             |
| `locationId`       | string | YES      | `DC-WEST`    | Location code.                              |
| `weekStarting`     | string | YES      | `2026-03-02` | ISO date representing week bucket.          |
| `channel`          | string | No       | `ALL`        | Channel segment, default `ALL`.             |
| `actualDemand`     | number | No       | `320`        | Actual units sold/consumed, default `0`.    |
| `forecastedDemand` | number | No       | `300`        | Forecast units, defaults to `actualDemand`. |

## Validation Rules

* `records[]` must be present and non-empty.
* Each row must include `skuId`, `locationId`, and `weekStarting`.
* Existing forecast rows are updated for matching model key (`weekStarting` + `channel`).

## Common Errors

| Error                     | Meaning                                | How to fix                     |
| ------------------------- | -------------------------------------- | ------------------------------ |
| `records[] is required`   | Missing demand history rows.           | Send `{ "records": [ ... ] }`. |
| `required fields missing` | Missing one of required keys in a row. | Include all required row keys. |
