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

# Edit Assignment Values

> Submit or update KPI values for a campaign-assignment

# Edit Assignment Values

Submit or update KPI values for a specific campaign-assignment. The current user must either be the data owner or hold the `custom_kpi::manage_config` permission.

## 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="dataset_id" type="string" required>
  UUID of the parent dataset
</ParamField>

<ParamField path="campaign_id" type="string" required>
  UUID of the campaign
</ParamField>

<ParamField path="campaign_assignment_id" type="string" required>
  UUID of the campaign-assignment
</ParamField>

### Body Parameters

<ParamField body="values" type="array[object]" required>
  KPI values to submit (max 100, no duplicate `kpi_id`). Each entry:

  | Field           | Type   | Description                                              |
  | --------------- | ------ | -------------------------------------------------------- |
  | `kpi_id`        | string | UUID of the KPI definition                               |
  | `value_numeric` | number | For `number`/`percentage` types (nullable)               |
  | `value_text`    | string | For `text` type (nullable)                               |
  | `value_date`    | string | For `date` type, ISO date (nullable)                     |
  | `option_id`     | string | For `select` type — UUID of the chosen option (nullable) |

  Only send the value field matching the KPI's `value_type`.
</ParamField>

<ParamField body="attachment_file_ids" type="array[string]">
  UUIDs of evidence files to attach. Replaces the current attachment pool — omit to leave attachments unchanged, send `[]` to clear them.
</ParamField>

## Response

Returns an array of saved KPI value objects (HTTP 200).

<ResponseField name="id" type="string">
  Value UUID.
</ResponseField>

<ResponseField name="assignment_id" type="string">
  Assignment UUID this value belongs to.
</ResponseField>

<ResponseField name="response_set_id" type="string | null">
  Response set UUID (for public form submissions). `null` for admin edits.
</ResponseField>

<ResponseField name="kpi_id" type="string">
  KPI UUID this value answers.
</ResponseField>

<ResponseField name="value_numeric" type="number | null">
  Numeric value (for `number`/`percentage` KPIs).
</ResponseField>

<ResponseField name="value_text" type="string | null">
  Text value (for `text` KPIs).
</ResponseField>

<ResponseField name="value_date" type="string | null">
  Date value (for `date` KPIs, ISO 8601 date).
</ResponseField>

<ResponseField name="option_id" type="string | null">
  Selected option UUID (for `select` KPIs).
</ResponseField>

<ResponseField name="submitted_at" type="string">
  When this value was submitted (ISO 8601).
</ResponseField>

<ResponseField name="submitter_email" type="string">
  Email of the user who submitted the value.
</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -X PATCH "https://api.dcycle.io/v1/custom-kpi-datasets/${DATASET_ID}/campaigns/${CAMPAIGN_ID}/assignments/${CA_ID}/values" \
    -H "x-api-key: ${DCYCLE_API_KEY}" \
    -H "x-organization-id: ${DCYCLE_ORG_ID}" \
    -H "Content-Type: application/json" \
    -d '{
      "values": [
        {"kpi_id": "c3d4e5f6-a7b8-9012-cdef-123456789012", "value_numeric": 1250.5},
        {"kpi_id": "d4e5f6a7-b8c9-0123-defa-234567890123", "option_id": "e5f6a7b8-c9d0-1234-efab-345678901234"}
      ]
    }'
  ```

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

  dataset_id = "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
  campaign_id = "b2c3d4e5-f6a7-8901-bcde-f12345678901"
  ca_id = "c3d4e5f6-a7b8-9012-cdef-123456789012"

  response = requests.patch(
      f"https://api.dcycle.io/v1/custom-kpi-datasets/{dataset_id}/campaigns/{campaign_id}/assignments/{ca_id}/values",
      headers=headers,
      json={
          "values": [
              {"kpi_id": "c3d4e5f6-a7b8-9012-cdef-123456789012", "value_numeric": 1250.5},
          ],
      },
  )

  print(f"Saved {len(response.json())} values")
  ```

  ```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 datasetId = 'a1b2c3d4-e5f6-7890-abcd-ef1234567890';
  const campaignId = 'b2c3d4e5-f6a7-8901-bcde-f12345678901';
  const caId = 'c3d4e5f6-a7b8-9012-cdef-123456789012';

  axios.patch(
    `https://api.dcycle.io/v1/custom-kpi-datasets/${datasetId}/campaigns/${campaignId}/assignments/${caId}/values`,
    {
      values: [
        { kpi_id: 'c3d4e5f6-a7b8-9012-cdef-123456789012', value_numeric: 1250.5 },
      ],
    },
    { headers }
  )
  .then(response => console.log(`Saved ${response.data.length} values`));
  ```
</CodeGroup>

### Successful Response

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
[
  {
    "id": "e1f2a3b4-c5d6-7890-abcd-ef1234567890",
    "assignment_id": "d4e5f6a7-b8c9-0123-defa-234567890123",
    "response_set_id": null,
    "kpi_id": "c3d4e5f6-a7b8-9012-cdef-123456789012",
    "value_numeric": 1250.5,
    "value_text": null,
    "value_date": null,
    "option_id": null,
    "submitted_at": "2025-06-20T14:30:00Z",
    "submitter_email": "admin@company.com",
    "submitter_user_id": "b9f1e2d3-0000-0000-0000-000000000001",
    "created_at": "2025-06-20T14:30:00Z"
  }
]
```

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

### 422 Validation Error

**Cause:** Duplicate `kpi_id` entries

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "values"],
      "msg": "Duplicate kpi_id entries are not allowed in a single submission",
      "type": "value_error"
    }
  ]
}
```

**Cause:** No values or attachments provided

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "detail": [
    {
      "loc": ["body", "__root__"],
      "msg": "Provide at least one value or attachment to update.",
      "type": "value_error"
    }
  ]
}
```

## Related Endpoints

<CardGroup cols={2}>
  <Card title="Get Values" icon="list" href="/api-reference/custom-kpi/get-assignment-values">
    View submission history
  </Card>

  <Card title="Campaign Values" icon="table" href="/api-reference/custom-kpi/list-campaign-values">
    View all values across recipients
  </Card>
</CardGroup>
