> For the complete documentation index, see [llms.txt](https://docs.sudoplatform.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sudoplatform.com/guides/digital-account-protection/actions.md).

# Actions

An action represents a privacy request the user can take against a data holder relationship. Available actions are generated when a data holder is scanned and analyzed.

Once a data holder has been scanned and analyzed, the system will derive a set of privacy requests, or actions, that the user can undertake to improve their privacy, or digital account protection. Common examples are \
&#x20;\- unsubscribing from marketing communications\
&#x20;\- requesting a copy of their data\
&#x20;\- asking for their data to be deleted. \
An **available action** is a derived suggestion of something the user *could* do against a data holder; an **action** is the instance that is created once the user chooses to proceed.

### Listing Available Actions <a href="#listing-available-actions" id="listing-available-actions"></a>

Before initiating anything, use the `listAvailableActions` method to discover what actions are currently possible for a given data holder relationship. Available actions are derived from multiple sources; some are always possible for the virtual presence type, while others are surfaced from analysis of the organization or from what was found during a discovery scan.

A call to `listAvailableActions` returns a `ListOutput` object containing a list of matching `items` and a `nextToken` to support pagination. If no results are found, the result will contain empty items. Always check the value of the returned `nextToken`—there are no more results to retrieve when `nextToken` is undefined.

By default, `listAvailableActions` omits actions the user has already completed (those whose latest status is `COMPLETED_UNVERIFIED` or `COMPLETED_VERIFIED`). Actions that are in progress, or have never been initiated, are always returned. Set `includeCompleted` to `true` to include completed actions as well.

{% tabs %}
{% tab title="Typescript" %}

```typescript
try {
  let nextToken: string | undefined = undefined
  do {
    const listOutput = await privacyInteractionClient.listAvailableActions({
      dataHolderId,
      includeCompleted: true
    })
    for (const action of listOutput.items) {
      // Handle each available action
    }
    nextToken = listOutput.nextToken
  } while (nextToken !== undefined)
} catch (error) {
  // Handle/notify user of errors
}
```

{% endtab %}

{% tab title="Swift" %}

```swift
do {
    var nextToken: String?
    repeat {
        let listOutput = try await privacyInteractionClient.listAvailableActions(
            forDataHolderId: dataHolderId,
            includeCompleted: true
        )
        for action in listOutput.items {
            // Handle each available action.
        }
        nextToken = listOutput.nextToken
    } while nextToken != nil
} catch {
    // Handle/notify user of errors
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kt
launch {
    try {
        var nextToken: String? = null
        do {
            val listOutput = withContext(Dispatchers.IO) {
                privacyInteractionClient.listAvailableActions(
                    ListAvailableActionsInput(
                        dataHolderId = dataHolderId,
                        includeCompleted = true,
                        nextToken = nextToken,
                    ),
                )
            }
            for (action in listOutput.items) {
                // Handle each available action
            }
            nextToken = listOutput.nextToken
        } while (nextToken != null)
    } catch (e: ActionException) {
        // Handle/notify user of errors
    }
}
```

{% endtab %}
{% endtabs %}

**Input Parameters:**

| Parameter          | Type      | Required | Description                                                                            |
| ------------------ | --------- | -------- | -------------------------------------------------------------------------------------- |
| `dataHolderId`     | `string`  | Yes      | The data holder relationship to list available actions for.                            |
| `includeCompleted` | `boolean` | No       | When `true`, actions the user has already completed are included. Defaults to `false`. |

\| `includeCompleted` | `boolean` | No | When `true`, actions the user has already completed are included. Defaults to `false`. |

Each `AvailableAction` describes what the action does and how it would be fulfilled. Use the `intent`, `title`, and `description` to present the action to the user, and note the `fulfilmentMethod` ; you must pass the same method back when initiating the action.

**Available Action Fields:**

| Field              | Type                     | Description                                                                                                                                                                                                         |
| ------------------ | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `intent`           | `ActionIntent`           | The user-facing intent of the action (e.g. `STOP_CONTACT`, `DELETE_MY_DATA`).                                                                                                                                       |
| `additionalInfo`   | `string`                 | Additional info, populated when `intent` is `OTHER`.                                                                                                                                                                |
| `fulfilmentMethod` | `ActionFulfilmentMethod` | How the action would be fulfilled — `ASSISTED` or `DELEGATED`.                                                                                                                                                      |
| `origin`           | `ActionOrigin`           | Which source contributed this action — `STATIC`, `ANALYSIS`, or `DISCOVERY`.                                                                                                                                        |
| `title`            | `string`                 | Short presentation hint for the action's title.                                                                                                                                                                     |
| `description`      | `string`                 | Short presentation hint describing the action.                                                                                                                                                                      |
| `status`           | `ActionStatus`           | The status of the most recent persisted action for this intent on the data holder. Undefined when the user has never initiated the action, which distinguishes "not yet started" from "in progress" or "completed". |

#### Action Intents <a href="#action-intents" id="action-intents"></a>

Every action carries an `intent` describing what the user wants to achieve, or what protective step they have taken."

| Intent                | Description                                                                                                                                                 |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `STOP_CONTACT`        | Unsubscribe from or opt out of marketing communications.                                                                                                    |
| `ACCESS_MY_DATA`      | Data subject access or portability request.                                                                                                                 |
| `DELETE_MY_DATA`      | Account deletion or data erasure.                                                                                                                           |
| `LIMIT_DATA_USE`      | Opt out of sale or tracking, and manage consent.                                                                                                            |
| `SWAP_EMAIL`          | The user has replaced the account's email address with a private email address. Always available for an email virtual presence.                             |
| `SWAP_PHONE`          | The user has replaced the account's phone number with a private number. Offered only when analysis indicates the data holder holds the user's phone number. |
| `SWAP_VIRTUAL_CARD`   | The user has replaced the account's payment card with a virtual card. Offered only when the data holder is identified as collecting credit card data.       |
| `SAVE_IN_PASSWORD`    | The user has saved this account in a password manager. Offered only when the data holder supports account creation.                                         |
| `USE_TWO_FACTOR_AUTH` | The user has turned on two-factor authentication for this account. Offered only when the data holder supports two-factor authentication.                    |
| `USE_PASSKEY`         | The user has set up a passkey for this account. Offered only when the data holder supports passkeys.                                                        |
| `USE_STRONG_PASSWORD` | The user has set a strong, unique password on this account. Offered whenever the data holder supports account creation.                                     |
| `OTHER`               | Anything unmapped; carries `additionalInfo`.                                                                                                                |

New intents may be introduced over time. Your application should tolerate unknown values — an unrecognized intent is represented as `OTHER` rather than failing, so newly added intents do not break existing clients.

#### Fulfilment Methods <a href="#fulfilment-methods" id="fulfilment-methods"></a>

An action is fulfilled in one of two ways, described by its `fulfilmentMethod`:

* **Assisted** — The service returns structured materials (contact points, an unsubscribe URL, or a prepared email template) for your application to complete the action. The service supplies the organization's contact details and any source-provided instructions, but never the user's own data. Any placeholders in a returned email template (e.g. `{{fullName}}`) are for fields your application supplies client-side.
* **Delegated** — The service performs the action on the user's behalf. No further materials are returned to the client.

The `fulfilmentMethod` you pass when initiating an action must match the method offered on the corresponding `AvailableAction`. Initiation fails if the server re-resolves a different method.

### Initiating an Action <a href="#initiating-an-action" id="initiating-an-action"></a>

To start an action, call `initiateAction` with the data holder relationship, the `intent` the user chose, and the `fulfilmentMethod` that was offered for that intent on the corresponding available action.

For a **delegated** action, the service begins performing the action on the user's behalf. For an **assisted** action, the returned `Action` carries an `assistedPayload` containing the materials your application needs to complete the action.

{% tabs %}
{% tab title="Typescript" %}

```typescript
const input = {
  dataHolderId,
  intent: ActionIntent.StopContact,
  fulfilmentMethod: ActionFulfilmentMethod.Assisted,
}
try {
  const action = await privacyInteractionClient.initiateAction(input)
  // The action is now initiated.
  // `action.status` will typically be `PENDING` or `IN_PROGRESS`.
  // For an assisted action, inspect `action.assistedPayload` for the materials
  // needed to complete it.
} catch (error) {
  // Handle/notify user of errors
}
```

{% endtab %}

{% tab title="Swift" %}

```swift
let input = InitiateActionInput(
    dataHolderId: dataHolderId,
    intent: .stopContact,
    fulfilmentMethod: .assisted
)
do {
    let action = try await privacyInteractionClient.initiateAction(withInput: input)
    // The action is now initiated.
    // `action.status` will typically be `.pending` or `.inProgress`.
    // For an assisted action, inspect `action.assistedPayload` for the materials
    // needed to complete it.
} catch {
    // Handle/notify user of errors
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kt
val input = InitiateActionInput(
    dataHolderId = dataHolderId,
    intent = ActionIntent.STOP_CONTACT,
    fulfilmentMethod = ActionFulfilmentMethod.ASSISTED,
)
try {
    val action = privacyInteractionClient.initiateAction(input)
    // The action is now initiated.
    // `action.status` will typically be `PENDING` or `IN_PROGRESS`.
    // For an assisted action, inspect `action.assistedPayload` for the
    // materials needed to complete it.
} catch (e: ActionException) {
    // Handle/notify user of errors
}
```

{% endtab %}
{% endtabs %}

**Input Parameters:**

| Parameter          | Type                     | Required | Description                                                                                                                  |
| ------------------ | ------------------------ | -------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `dataHolderId`     | `string`                 | Yes      | The data holder relationship to scope the action to.                                                                         |
| `intent`           | `ActionIntent`           | Yes      | The intent of the action to initiate.                                                                                        |
| `fulfilmentMethod` | `ActionFulfilmentMethod` | Yes      | The fulfilment method the client was offered for this intent. Initiation fails if the server re-resolves a different method. |

### Confirming an Action Outcome <a href="#confirming-an-action-outcome" id="confirming-an-action-outcome"></a>

When an assisted or delegated action has been completed, call `confirmActionOutcome` with the action's unique identifier to confirm the outcome. This transitions the action from `COMPLETED_UNVERIFIED` to `COMPLETED_VERIFIED`.

{% tabs %}
{% tab title="Typescript" %}

```typescript
try {
  const action = await privacyInteractionClient.confirmActionOutcome(actionId)
  // `action.status` will be `COMPLETED_VERIFIED`.
} catch (error) {
  // Handle/notify user of errors
}
```

{% endtab %}

{% tab title="Swift" %}

```swift
do {
    let action = try await privacyInteractionClient.confirmActionOutcome(withId: actionId)
    // `action.status` will be `.completedVerified`.
} catch {
    // Handle/notify user of errors
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kt
launch {
    try {
        val action = withContext(Dispatchers.IO) {
            privacyInteractionClient.confirmActionOutcome(actionId)
        }
        // `action.status` will be COMPLETED_VERIFIED.
    } catch (e: ActionException) {
        // Handle/notify user of errors
    }
}
```

{% endtab %}
{% endtabs %}

#### Action States <a href="#action-states" id="action-states"></a>

An action transitions through the following states:

| State                  | Description                                              |
| ---------------------- | -------------------------------------------------------- |
| `PENDING`              | The action has been created but not yet started.         |
| `IN_PROGRESS`          | The action is being performed.                           |
| `COMPLETED_UNVERIFIED` | The action completed but has not been verified.          |
| `COMPLETED_VERIFIED`   | The action completed and has been verified.              |
| `FAILED`               | The action failed to complete.                           |
| `REQUIRES_USER_INPUT`  | The action requires further input from the user.         |
| `CONTRADICTED`         | Subsequent evidence contradicts the action's completion. |

When an action enters the `COMPLETED_UNVERIFIED` state, your application can call `confirmActionOutcome` to transition it to `COMPLETED_VERIFIED`. When an action enters the `REQUIRES_USER_INPUT` state, your application should gather the required input from the user before the action can proceed.

#### Action Fields <a href="#action-fields" id="action-fields"></a>

A persisted `Action` returned by `initiateAction` and `confirmActionOutcome` contains the following fields:

| Field               | Type                     | Description                                                         |
| ------------------- | ------------------------ | ------------------------------------------------------------------- |
| `id`                | `string`                 | Unique identifier associated with the action.                       |
| `virtualPresenceId` | `string`                 | The virtual presence this action belongs to.                        |
| `dataHolderId`      | `string`                 | The data holder relationship this action is scoped to.              |
| `intent`            | `ActionIntent`           | The user-facing intent of the action.                               |
| `additionalInfo`    | `string`                 | Additional info, populated when `intent` is `OTHER`.                |
| `fulfilmentMethod`  | `ActionFulfilmentMethod` | How the action is fulfilled.                                        |
| `status`            | `ActionStatus`           | Current lifecycle status of the action.                             |
| `assistedPayload`   | `AssistedPayload`        | Materials for an assisted action. Undefined for a delegated action. |
| `initiatedAt`       | `Date`                   | When the action was initiated.                                      |
| `completedAt`       | `Date`                   | When the action completed.                                          |

### **Assisted Payload**

For an assisted action, the `assistedPayload` on the returned `Action` contains the materials your application needs to complete it. The service supplies the organization's contact points and any source-provided instructions. It never supplies the user's own personal data. All fields are optional, and which ones are present depends on the intent and what is known about the data holder.

| Field               | Type                    | Description                                                  |
| ------------------- | ----------------------- | ------------------------------------------------------------ |
| `toAddress`         | `string`                | Recipient address for an assisted email action.              |
| `unsubscribeUrl`    | `string`                | A web page where the user can unsubscribe.                   |
| `unsubscribeMailto` | `string`                | A `mailto:` address that can be used to unsubscribe.         |
| `contact`           | `ActionContact`         | The organization's contact points.                           |
| `jurisdiction`      | `string`                | The jurisdiction relevant to the action.                     |
| `instructions`      | `string`                | Free-text instructions describing how to perform the action. |
| `emailTemplate`     | `AssistedEmailTemplate` | A prepared email for the action.                             |

**ActionContact:**

| Field     | Type     | Description                             |
| --------- | -------- | --------------------------------------- |
| `email`   | `string` | Contact email address, when available.  |
| `phone`   | `string` | Contact phone number, when available.   |
| `address` | `string` | Contact postal address, when available. |

**AssistedEmailTemplate:**

| Field                                                                                          | Type     | Description                                                                                                                                         |
| ---------------------------------------------------------------------------------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| `subject`                                                                                      | `string` | Subject line for the email, when available.                                                                                                         |
| `body`                                                                                         | `string` | Body of the email. May contain `{{placeholder}}` fields (for example `{{fullName}}`) that your application replaces with details the user supplies. |
| `instructions` may also contain `{{placeholder}}` fields for values your application supplies. |          |                                                                                                                                                     |

### Listing Action History

`listAvailableActions` describes what a user could do. To retrieve what they have already done, use `listActionsForDataHolder`. It returns every action that has been initiated against a data holder, covering all intents, all statuses and every attempt, ordered newest first. Results are paginated: check the returned `nextToken` and continue until it is undefined.

{% tabs %}
{% tab title="Typescript" %}

```typescript
try {
  let nextToken: string | undefined = undefined
  do {
    const listOutput = await privacyInteractionClient.listActionsForDataHolder({
      dataHolderId,
      limit: 20,
      nextToken,
    })
    for (const action of listOutput.items) {
      console.log(action.intent, action.status, action.initiatedAt)
    }
    nextToken = listOutput.nextToken
  } while (nextToken !== undefined)
} catch (error) {
  // Handle/notify user of errors
}
```

{% endtab %}

{% tab title="Swift" %}

```swift
do {
    var nextToken: String?
    repeat {
        let listOutput = try await privacyInteractionClient.listActionsForDataHolder(
            withInput: ListActionsForDataHolderInput(
                dataHolderId: dataHolderId,
                limit: 20,
                nextToken: nextToken
            )
        )
        for action in listOutput.items {
            print(action.intent, action.status)
        }
        nextToken = listOutput.nextToken
    } while nextToken != nil
} catch {
    // Handle/notify user of errors
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kt
launch {
    try {
        var nextToken: String? = null
        do {
            val listOutput = withContext(Dispatchers.IO) {
                privacyInteractionClient.listActionsForDataHolder(
                    ListActionsForDataHolderInput(
                        dataHolderId = dataHolderId,
                        limit = 20,
                        nextToken = nextToken,
                    ),
                )
            }
            for (action in listOutput.items) {
                println("${action.intent} ${action.status}")
            }
            nextToken = listOutput.nextToken
        } while (nextToken != null)
    } catch (e: ActionException) {
        // Handle/notify user of exception
    }
}
```

{% endtab %}
{% endtabs %}

**Input Parameters:**

| Parameter      | Type     | Required | Description                                                      |
| -------------- | -------- | -------- | ---------------------------------------------------------------- |
| `dataHolderId` | `string` | Yes      | The data holder relationship to list the action history for.     |
| `limit`        | `number` | No       | Maximum number of items to return. Will be defaulted if omitted. |
| `nextToken`    | `string` | No       | A pagination token from a previous call.                         |

### Retrieving an Action

To read a single action by its unique identifier, call `getAction`. It returns the action, or undefined if no action with that identifier exists for the user. A missing action is not an error.

Reading an action also resolves a delegated action that is still `IN_PROGRESS`. The service asks the system performing the action for its current outcome:

* If the action succeeded, it is persisted as `COMPLETED_VERIFIED` (when the outcome was directly confirmed) or `COMPLETED_UNVERIFIED`.
* If it failed, it is persisted as `FAILED`.
* If the outcome cannot yet be determined, the action is returned unchanged.
* If an action has been in progress for more than 24 hours without a resolvable outcome, it is marked `FAILED`.

Any status change made this way is published to action subscribers.

{% tabs %}
{% tab title="Typescript" %}

```typescript
try {
  const action = await privacyInteractionClient.getAction(actionId)
  if (action) {
    console.log(action.intent, action.status)
  } else {
    // No action with this ID exists.
  }
} catch (error) {
  // Handle/notify user of errors
}
```

{% endtab %}

{% tab title="Swift" %}

```swift
do {
    if let action = try await privacyInteractionClient.getAction(withId: actionId) {
        print(action.intent, action.status)
    } else {
        // No action with this ID exists.
    }
} catch {
    // Handle/notify user of errors
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kt
launch {
    try {
        val action = withContext(Dispatchers.IO) {
            privacyInteractionClient.getAction(actionId)
        }
        if (action != null) {
            println("${action.intent} ${action.status}")
        } else {
            // No action with this ID exists.
        }
    } catch (e: ActionException) {
        // Handle/notify user of exception
    }
}
```

{% endtab %}
{% endtabs %}

### Subscribing to Action Updates <a href="#subscribing-to-action-updates" id="subscribing-to-action-updates"></a>

To receive real-time notifications when an action changes status, see [Subscriptions](https://docs.sudoplatform.com/guides/digital-account-protection/subscriptions.md).
