# Update transaction

> Updates an existing transaction. Every field is optional: send only what you want to change.

Página: https://doc.rapidchargeback.com/en/canais/transactions/atualizar-transacao/

Updates an existing transaction. Every field is optional: send only what you want to change.

When child records are sent (`items`, `addresses`, `payments`, `refunds`, `customer`), they **fully replace** the existing records.

## Endpoint

```
PATCH https://api.rapidchargeback.com/api/v1/transactions/:id
```

## Authentication

```
Authorization: Basic base64(client_id:client_secret)
Content-Type: application/json
```

---

## URL parameter

| Parameter | Type | Description |
|---|---|---|
| `id` | string (UUID) | Transaction ID (returned in the `id` field of the creation response) |

Did not keep the `id`? Find the transaction [by your system's ID](https://doc.rapidchargeback.com/en/canais/transactions/consultar-transacao/#by-your-systems-id).

---

## Accepted fields

Every field accepted by [Create transaction](https://doc.rapidchargeback.com/en/canais/transactions/criar-transacao/) can be sent here, all optional:

- Fields sent replace the current value
- Fields omitted keep the current value
- Child records sent (`items`, `addresses`, etc.) fully replace the existing ones

---

## Validations

- If `merchant_id` is changed, the new merchant must belong to your company
- If `external_id` or `external_source` are changed, the combination cannot duplicate another existing transaction
- If the transaction was already used by a solution (e.g. queried by **Prevention**), the update is blocked with `409 Conflict`

---

## Request example

### Update only the ARN and auth_code

```bash
curl -X PATCH https://api.rapidchargeback.com/api/v1/transactions/00000000-0000-0000-0000-000000000042 \
  -H "Authorization: Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=" \
  -H "Content-Type: application/json" \
  -d '{
    "arn": "74537119547024600128228",
    "auth_code": "AUTH999"
  }'
```

### Update items (replaces all existing items)

```bash
curl -X PATCH https://api.rapidchargeback.com/api/v1/transactions/00000000-0000-0000-0000-000000000042 \
  -H "Authorization: Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 300.00,
    "items": [
      { "product_description": "Plano Premium", "unit_price": 150.00 },
      { "product_description": "Taxa de Setup", "unit_price": 150.00 }
    ]
  }'
```

---

## Response examples

### Success

```json
{
  "data": {
    "id": "00000000-0000-0000-0000-000000000042",
    "merchant_id": "00000000-0000-0000-0000-000000000001",
    "amount": 300.00,
    "transaction_items": [
      { "product_description": "Plano Premium", "unit_price": 150.00 },
      { "product_description": "Taxa de Setup", "unit_price": 150.00 }
    ]
  }
}
```

### Transaction not found

```json
{
  "error": {
    "code": "TRANSACTION_NOT_FOUND",
    "message": "Transaction not found"
  }
}
```

### Immutable transaction (already used by a solution)

```json
{
  "error": {
    "code": "TRANSACTION_IMMUTABLE",
    "message": "Transaction cannot be modified: it has been used by a network event"
  }
}
```

### Duplicate external_id

```json
{
  "error": {
    "code": "TRANSACTION_DUPLICATE",
    "message": "Another transaction with this external_source/external_id already exists"
  }
}
```
