# Compare two questionnaire versions

List what changed between two versions of one questionnaire: added, removed and modified questions and options, with the before and after of each changed field.

`GET /supplier-assessment-templates/{templateId}/versions/{version}/diff/{otherVersion}`

Scope `supplier_template:read` | Plan **Growth+**

List what changed between two versions of one questionnaire: added, removed and modified questions and options, with the before and after of each changed field. For a removed question, `referencedByAssessments` counts the existing assessments that hold an answer to it. As in get-version, `{templateId}` is the questionnaire's `templateKey`. Requires the supplier_template:read scope.

## Path parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `templateId` | string | yes | The questionnaire's `templateKey`, which is shared by all its versions. Not a document `templateId`. |
| `version` | integer | yes | Version number; 0 is an open draft. minimum 0 |
| `otherVersion` | integer | yes | The version to compare with. minimum 0 |

## Returns

The `data` field of the standard `{ data, error, meta }` envelope:

- `templateKey`: string
- `fromVersion`: integer
- `toVersion`: integer
- `rows`: array of object
  - `kind`: string
    - `questionAdded`
    - `questionRemoved`
    - `questionModified`
    - `optionAdded`
    - `optionRemoved`
    - `optionModified`
  - `questionId`: string
  - `sectionId`: string
  - `optionId`: optional string
  - `fields`: optional array of object
    - `field`: string
    - `before`: any Value in the first version.
    - `after`: any Value in the second version.
  - `referencedByAssessments`: optional integer For questionRemoved: existing assessments holding an answer to it.

## Errors

| Status | Code | Retry | Meaning |
|---|---|---|---|
| 400 | `VALIDATION_FAILED` | no | A version in the path is not an integer. code VALIDATION_FAILED. |
| 401 | `INVALID_TOKEN` | no | Missing (UNAUTHORIZED) or invalid, expired or revoked (INVALID_TOKEN) token. |
| 402 | `FEATURE_GATED` | no | The tenant plan does not include supply chain security. code FEATURE_GATED; args.feature, args.minTier, args.minTierName. |
| 403 | `INSUFFICIENT_SCOPE` | no | The token lacks the required scope (INSUFFICIENT_SCOPE), or the request is refused (FORBIDDEN, INSUFFICIENT_ROLE for a draft the caller may not read). |
| 404 | `NOT_FOUND` | no | Unknown or foreign-tenant questionnaire, version or clone source. code NOT_FOUND. |
| 429 | `RATE_LIMITED` | yes | Too many failed authentication attempts from this address. code RATE_LIMITED; wait Retry-After seconds. |
| 500 | `DB_ERROR` | no | Unexpected server error. code DB_ERROR; quote error.id to support. |
| 503 | `BILLING_UNAVAILABLE` | yes | Billing is temporarily unavailable, so the plan could not be checked. code BILLING_UNAVAILABLE. Retry later. |

## Example

### curl

```bash
curl "https://api.autociso.io/api/v1/supplier-assessment-templates/<templateId>/versions/<version>/diff/<otherVersion>" \
  -H "Authorization: Bearer <your-api-token>"
```

### Python

```python
import requests

response = requests.get(
    "https://api.autociso.io/api/v1/supplier-assessment-templates/<templateId>/versions/<version>/diff/<otherVersion>",
    headers={"Authorization": "Bearer <your-api-token>"},
)
print(response.json())
```

### JavaScript

```javascript
const response = await fetch("https://api.autociso.io/api/v1/supplier-assessment-templates/<templateId>/versions/<version>/diff/<otherVersion>", {
  method: "GET",
  headers: { "Authorization": "Bearer <your-api-token>" },
});
console.log(await response.json());
```

## Response (200)

```json
{
  "data": {
    "templateKey": "tpl_1hgyun41rx49",
    "fromVersion": 1,
    "toVersion": 2,
    "rows": [
      {
        "kind": "questionModified",
        "questionId": "saq_1hgyun41rx4d",
        "sectionId": "sect_1hgyun41rx4a",
        "fields": [
          {
            "field": "weight",
            "before": 8,
            "after": 10
          }
        ]
      },
      {
        "kind": "optionAdded",
        "questionId": "saq_1hgyun41rx4d",
        "sectionId": "sect_1hgyun41rx4a",
        "optionId": "saqo_1hgyun41rx4g"
      },
      {
        "kind": "questionRemoved",
        "questionId": "saq_1hgyun41rx4c",
        "sectionId": "sect_1hgyun41rx4a",
        "referencedByAssessments": 3
      }
    ]
  }
}
```
