## Enroll and cancel contacts

`client.Sequence.UpdateEnrollments(ctx, id, body) (*SequenceUpdateEnrollmentsResponse, error)`

**post** `/v1/sequences/{id}/enrollments`

Enrolls the contacts in `add` and cancels the open enrollments of the contacts in `remove`, in one request: if any addition is invalid, nothing changes. Send add, remove or both, with at most 25 contact IDs in total; duplicate IDs are ignored, and an ID cannot be in both lists. The response has one result per contact: `enrolled`, `already_enrolled`, `unenrolled`, or `no_active_enrollment` for a removal with nothing open.

A contact already enrolled, paused included, is left as is; one whose earlier enrollment ended is enrolled again. Cancelling stops the contact’s remaining steps and leaves the enrollment readable with status `CANCELLED`. A paused sequence accepts enrollments and sends to them once it is activated; sending starts asynchronously.

Returns 400 `sequence_not_published` for a sequence that has never been published, and 400 `invalid_configuration` with `invalidContacts` naming each contact that cannot be enrolled and why. See <u>[Sequence errors](/using-the-api/errors/#sequence-errors)</u>.

**[Required scope](/using-the-api/scopes/):** `sequences:update`

**[Rate limit category](/using-the-api/rate-limits/):** Write

### Parameters

- `id string`

  Unique identifier of the sequence.

- `body SequenceUpdateEnrollmentsParams`

  - `Add param.Field[[]string]`

    Contact IDs to enroll. Open enrollments are unchanged; contacts whose prior enrollment ended are enrolled again.

  - `Remove param.Field[[]string]`

    Contact IDs to unenroll. Cancels open enrollments and preserves their history.

### Returns

- `type SequenceUpdateEnrollmentsResponse struct{…}`

  - `Results []SequenceUpdateEnrollmentsResponseResultUnion`

    One result per distinct contact, additions first, then removals.

    - `type SequenceUpdateEnrollmentsResponseResultEnrollmentChanged struct{…}`

      - `ContactID string`

        ID of the contact.

      - `EnrollmentID string`

        ID of the enrollment the outcome applies to.

      - `Outcome string`

        `enrolled` created the enrollment, `already_enrolled` left an open one as is, `unenrolled` cancelled it.

        - `const SequenceUpdateEnrollmentsResponseResultEnrollmentChangedOutcomeEnrolled SequenceUpdateEnrollmentsResponseResultEnrollmentChangedOutcome = "enrolled"`

        - `const SequenceUpdateEnrollmentsResponseResultEnrollmentChangedOutcomeAlreadyEnrolled SequenceUpdateEnrollmentsResponseResultEnrollmentChangedOutcome = "already_enrolled"`

        - `const SequenceUpdateEnrollmentsResponseResultEnrollmentChangedOutcomeUnenrolled SequenceUpdateEnrollmentsResponseResultEnrollmentChangedOutcome = "unenrolled"`

    - `type SequenceUpdateEnrollmentsResponseResultNothingToCancel struct{…}`

      - `ContactID string`

        ID of the contact.

      - `EnrollmentID any`

        Always null.

      - `Outcome string`

        The contact had no open enrollment to cancel.

        - `const SequenceUpdateEnrollmentsResponseResultNothingToCancelOutcomeNoActiveEnrollment SequenceUpdateEnrollmentsResponseResultNothingToCancelOutcome = "no_active_enrollment"`

### Example

```go
package main

import (
  "context"
  "fmt"

  "github.com/Lightfld/lightfield-go"
  "github.com/Lightfld/lightfield-go/option"
)

func main() {
  client := githubcomlightfldlightfieldgo.NewClient(
    option.WithAPIKey("My API Key"),
  )
  sequenceUpdateEnrollmentsResponse, err := client.Sequence.UpdateEnrollments(
    context.TODO(),
    "id",
    githubcomlightfldlightfieldgo.SequenceUpdateEnrollmentsParams{

    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", sequenceUpdateEnrollmentsResponse.Results)
}
```

#### Response

```json
{
  "results": [
    {
      "contactId": "contactId",
      "enrollmentId": "enrollmentId",
      "outcome": "enrolled"
    }
  ]
}
```
