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

# Confirm Mapping

> Persist the user-chosen column mapping on the import session

# Confirm Mapping

Persist the column mapping the user accepted (or adjusted) after reviewing suggestions. This transitions the session status from `parsed` to `mapped` and makes the session resumable.

<Note>
  Confirming is optional — the [Validate](/api-reference/imports/validate) endpoint also accepts a mapping in the request body. However, confirming has two benefits: the mapping is persisted on the session (visible via [List Sessions](/api-reference/imports/list)), and downstream calls behave consistently with what the user saw.
</Note>

## Request

### Headers

<ParamField header="x-api-key" type="string" required>
  Your API key for authentication

  **Example:** `sk_live_1234567890abcdef`
</ParamField>

<ParamField header="x-organization-id" type="string" required>
  Your organization UUID

  **Example:** `a8315ef3-dd50-43f8-b7ce-d839e68d51fa`
</ParamField>

### Path Parameters

<ParamField path="import_id" type="string" required>
  UUID of the import session

  **Example:** `"11111111-1111-1111-1111-111111111111"`
</ParamField>

### Body Parameters

<ParamField body="mapping" type="object" required>
  Map of `{target_column: source_column | suggestion_object | null}`. Each key is a template column key. The value can be:

  * A string (source column name)
  * A suggestion object from [Suggest Mapping](/api-reference/imports/suggest-mapping) (the `source_column` is extracted automatically)
  * `null` to leave the target unmapped

  **Example:** `{"origin": "origin", "destination": "destination", "weight": "weight_kg", "date": "date"}`
</ParamField>

## Response

<ResponseField name="import_id" type="string">
  UUID of the import session
</ResponseField>

<ResponseField name="mapping" type="object">
  The normalized flat mapping persisted on the session (`{target: source_column | null}`)
</ResponseField>

<ResponseField name="status" type="string">
  Updated session status (typically `mapped`)
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X POST "https://api.dcycle.io/v2/imports/11111111-1111-1111-1111-111111111111/mapping" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "mapping": {
        "origin": "origin",
        "destination": "destination",
        "weight": "weight_kg",
        "vehicle_type": "vehicle_type",
        "date": "date"
      }
    }'
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import requests
  import os

  headers = {
      "x-api-key": os.getenv("DCYCLE_API_KEY"),
      "x-organization-id": os.getenv("DCYCLE_ORG_ID"),
      "Content-Type": "application/json",
  }

  import_id = "11111111-1111-1111-1111-111111111111"

  response = requests.post(
      f"https://api.dcycle.io/v2/imports/{import_id}/mapping",
      headers=headers,
      json={
          "mapping": {
              "origin": "origin",
              "destination": "destination",
              "weight": "weight_kg",
              "vehicle_type": "vehicle_type",
              "date": "date",
          }
      },
  )

  result = response.json()
  print(f"Status: {result['status']}")
  print(f"Mapping: {result['mapping']}")
  ```

  ```javascript JavaScript theme={"theme":{"light":"github-light","dark":"github-dark"}}
  const axios = require('axios');

  const headers = {
    'x-api-key': process.env.DCYCLE_API_KEY,
    'x-organization-id': process.env.DCYCLE_ORG_ID,
    'Content-Type': 'application/json',
  };

  const importId = '11111111-1111-1111-1111-111111111111';

  axios.post(`https://api.dcycle.io/v2/imports/${importId}/mapping`, {
    mapping: {
      origin: 'origin',
      destination: 'destination',
      weight: 'weight_kg',
      vehicle_type: 'vehicle_type',
      date: 'date',
    },
  }, { headers })
  .then(response => {
    console.log(`Status: ${response.data.status}`);
  });
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "import_id": "11111111-1111-1111-1111-111111111111",
  "mapping": {
    "origin": "origin",
    "destination": "destination",
    "weight": "weight_kg",
    "vehicle_type": "vehicle_type",
    "date": "date"
  },
  "status": "mapped"
}
```

## Common Errors

### 401 Unauthorized

**Cause:** Missing or invalid API key

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Invalid API key for organization", "code": "INVALID_API_KEY"}
```

### 403 Forbidden

**Cause:** The authenticated user is not a member of the organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Logged User is not Member of Organization", "code": "LOGGED_USER_NOT_MEMBER"}
```

### 404 Not Found

**Cause:** The import session does not exist or belongs to another organization

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"detail": "Not Found"}
```

### 422 Unprocessable Entity

**Cause:** Invalid or missing mapping object

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "mapping"],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Suggest Mapping" icon="wand-magic-sparkles" href="/api-reference/imports/suggest-mapping">
    Get auto-suggested mappings first
  </Card>

  <Card title="Validate Import" icon="circle-check" href="/api-reference/imports/validate">
    Validate rows with the chosen mapping
  </Card>
</CardGroup>
