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

# Suggest Mapping

> Get auto-suggested column mapping from source to template columns

# Suggest Mapping

Request automatic mapping suggestions from your uploaded file's source columns to the template's target columns. The backend uses lexical similarity, semantic matching, and import history to rank candidates.

<Note>
  Suggestions are best-effort. Review the confidence scores and adjust before confirming. History-restored mappings (`restored_from_history: true`) come from a prior successful import and skip value-level scoring.
</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="source_columns" type="array[string]">
  Override the detected source columns. When omitted, uses the columns detected during session creation.
</ParamField>

## Response

<ResponseField name="suggestions" type="object">
  Map of `{target_column: suggestion | null}`. Each key is a template column key; the value is a suggestion object or `null` if no match was found.

  <Expandable title="Suggestion Object">
    <ResponseField name="source_column" type="string | null">
      Name of the source column suggested for this target
    </ResponseField>

    <ResponseField name="column_confidence" type="number">
      Confidence (0.0–1.0) that the source column identity matches the target, based on name similarity
    </ResponseField>

    <ResponseField name="value_confidence" type="number | null">
      For category columns only: confidence (0.0–1.0) that sample values map to the target enum. `null` for non-category columns or history-restored items.
    </ResponseField>

    <ResponseField name="reason" type="string | null">
      Human-readable explanation of why this mapping was suggested
    </ResponseField>

    <ResponseField name="restored_from_history" type="boolean">
      `true` when this suggestion was lifted from a prior successful import rather than re-scored
    </ResponseField>
  </Expandable>
</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/suggest" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{}'
  ```

  ```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/suggest",
      headers=headers,
      json={},
  )

  suggestions = response.json()["suggestions"]
  for target, suggestion in suggestions.items():
      if suggestion:
          src = suggestion["source_column"]
          conf = suggestion["column_confidence"]
          print(f"  {target} ← {src} (confidence: {conf:.2f})")
      else:
          print(f"  {target} ← (no match)")
  ```

  ```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/suggest`, {}, { headers })
    .then(response => {
      const { suggestions } = response.data;
      Object.entries(suggestions).forEach(([target, s]) => {
        if (s) console.log(`${target} ← ${s.source_column} (${s.column_confidence})`);
        else console.log(`${target} ← no match`);
      });
    });
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "suggestions": {
    "origin": {
      "source_column": "origin",
      "column_confidence": 0.98,
      "value_confidence": null,
      "reason": "exact match on column name",
      "restored_from_history": false
    },
    "destination": {
      "source_column": "destination",
      "column_confidence": 0.98,
      "value_confidence": null,
      "reason": "exact match on column name",
      "restored_from_history": false
    },
    "weight": {
      "source_column": "weight_kg",
      "column_confidence": 0.82,
      "value_confidence": null,
      "reason": "semantic similarity",
      "restored_from_history": false
    },
    "vehicle_type": {
      "source_column": "vehicle_type",
      "column_confidence": 0.95,
      "value_confidence": 0.87,
      "reason": null,
      "restored_from_history": true
    },
    "date": {
      "source_column": "date",
      "column_confidence": 0.97,
      "value_confidence": null,
      "reason": "exact match on column name",
      "restored_from_history": false
    }
  }
}
```

## 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"}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Confirm Mapping" icon="check" href="/api-reference/imports/confirm-mapping">
    Persist the chosen mapping
  </Card>

  <Card title="Create Session" icon="upload" href="/api-reference/imports/create-session">
    Upload a file and start an import
  </Card>
</CardGroup>
