# Enrichment Run

## Enrich a record

`client.EnrichmentRun.Enrich(ctx, entityID, params) (*EnrichmentRunEnrichResponse, error)`

**post** `/v1/enrichmentRun/{entitySlug}/{entityId}`

Looks up missing information for a record from Lightfield's enrichment providers and writes it back to it. Accepts `contacts` and `accounts`.

Enrichment runs in the background: this returns as soon as the run is created. Poll `GET /v1/enrichmentRun/{runId}` for its status. A record can only have one enrichment run at a time — if one is already in flight, this returns that run rather than starting a second.

Which fields are enriched, and whether a provider answer overwrites an existing value or is raised as a suggestion, come from the workspace's enrichment settings. Naming fields explicitly overrides which fields are enriched, but not the write policy.

**[Required scopes](/using-the-api/scopes/):** `contacts:update` to enrich a contact, `accounts:update` to enrich an account

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

### Parameters

- `entityID string`

  The ID of the record to enrich.

- `params EnrichmentRunEnrichParams`

  - `EntitySlug param.Field[EnrichmentRunEnrichParamsEntitySlug]`

    Path param: The type of record to enrich.

    - `const EnrichmentRunEnrichParamsEntitySlugContacts EnrichmentRunEnrichParamsEntitySlug = "contacts"`

    - `const EnrichmentRunEnrichParamsEntitySlugAccounts EnrichmentRunEnrichParamsEntitySlug = "accounts"`

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

    Body param: Fields to enrich, e.g. `["email", "title"]`. Named fields are refreshed even when they already hold a value, so this is how a stale value is replaced. Omit to fill only the fields the record is missing. Naming a field the workspace's settings turn off enriches it anyway, and its answer is raised as a suggestion rather than written over a value the record already holds. `profilePhotoUrl` has no suggestion form, so it stays rejected while it is turned off. A named field is not used to look the record up — the run derives it fresh from the record's other identifiers — so naming every identifier (a contact's name and email together) leaves nothing to search by and is skipped with `no_operations`. `phone` is filled only when another field's lookup happens to return it, so requesting it on its own is skipped the same way.

### Returns

- `type EnrichmentRunEnrichResponse struct{…}`

  - `EnrichmentRun EnrichmentRunEnrichResponseEnrichmentRun`

    The run, or null when the request was skipped.

    - `ID string`

      The enrichment run ID.

    - `CompletedAt string`

      When the run finished, or null while it is still open.

    - `CreatedAt string`

    - `EntityID string`

      The ID of the record being enriched.

    - `EntityType string`

      The type of record being enriched.

      - `const EnrichmentRunEnrichResponseEnrichmentRunEntityTypeContact EnrichmentRunEnrichResponseEnrichmentRunEntityType = "contact"`

      - `const EnrichmentRunEnrichResponseEnrichmentRunEntityTypeAccount EnrichmentRunEnrichResponseEnrichmentRunEntityType = "account"`

    - `StartedAt string`

      When the run began executing, or null while it is queued.

    - `Status string`

      Where the run is: `queued` and `running` are in flight; `completed`, `failed` and `timed_out` are final.

      - `const EnrichmentRunEnrichResponseEnrichmentRunStatusQueued EnrichmentRunEnrichResponseEnrichmentRunStatus = "queued"`

      - `const EnrichmentRunEnrichResponseEnrichmentRunStatusRunning EnrichmentRunEnrichResponseEnrichmentRunStatus = "running"`

      - `const EnrichmentRunEnrichResponseEnrichmentRunStatusCompleted EnrichmentRunEnrichResponseEnrichmentRunStatus = "completed"`

      - `const EnrichmentRunEnrichResponseEnrichmentRunStatusFailed EnrichmentRunEnrichResponseEnrichmentRunStatus = "failed"`

      - `const EnrichmentRunEnrichResponseEnrichmentRunStatusTimedOut EnrichmentRunEnrichResponseEnrichmentRunStatus = "timed_out"`

    - `TargetFields []string`

      The fields this run set out to fill.

    - `Trigger string`

      What started the run: `creation` when the record was created, `manual` when requested through the API.

      - `const EnrichmentRunEnrichResponseEnrichmentRunTriggerCreation EnrichmentRunEnrichResponseEnrichmentRunTrigger = "creation"`

      - `const EnrichmentRunEnrichResponseEnrichmentRunTriggerManual EnrichmentRunEnrichResponseEnrichmentRunTrigger = "manual"`

    - `UpdatedAt string`

  - `Reason EnrichmentRunEnrichResponseReason`

    Why the request was skipped: `no_targets` when the workspace enriches nothing this record is missing, `no_operations` when no provider can be scheduled for the targeted fields — because none looks them up on request, or because the record lacks the inputs (such as an email or domain) a lookup would need. Null otherwise.

    - `const EnrichmentRunEnrichResponseReasonNoTargets EnrichmentRunEnrichResponseReason = "no_targets"`

    - `const EnrichmentRunEnrichResponseReasonNoOperations EnrichmentRunEnrichResponseReason = "no_operations"`

  - `Status EnrichmentRunEnrichResponseStatus`

    `started` when this request began a run, `already_running` when one was already enriching the record, `skipped` when there was nothing to enrich.

    - `const EnrichmentRunEnrichResponseStatusStarted EnrichmentRunEnrichResponseStatus = "started"`

    - `const EnrichmentRunEnrichResponseStatusAlreadyRunning EnrichmentRunEnrichResponseStatus = "already_running"`

    - `const EnrichmentRunEnrichResponseStatusSkipped EnrichmentRunEnrichResponseStatus = "skipped"`

### 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"),
  )
  enrichmentRunEnrichResponse, err := client.EnrichmentRun.Enrich(
    context.TODO(),
    "entityId",
    githubcomlightfldlightfieldgo.EnrichmentRunEnrichParams{
      EntitySlug: githubcomlightfldlightfieldgo.EnrichmentRunEnrichParamsEntitySlugContacts,
    },
  )
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", enrichmentRunEnrichResponse.EnrichmentRun)
}
```

#### Response

```json
{
  "enrichmentRun": {
    "id": "id",
    "completedAt": "completedAt",
    "createdAt": "createdAt",
    "entityId": "entityId",
    "entityType": "contact",
    "startedAt": "startedAt",
    "status": "queued",
    "targetFields": [
      "string"
    ],
    "trigger": "creation",
    "updatedAt": "updatedAt"
  },
  "reason": "no_targets",
  "status": "started"
}
```

## Get enrichment run status

`client.EnrichmentRun.GetEnrichmentRun(ctx, runID) (*EnrichmentRunGetEnrichmentRunResponse, error)`

**get** `/v1/enrichmentRun/{runId}`

Returns the status of an enrichment run by its ID.

**[Required scopes](/using-the-api/scopes/):** `contacts:read` for a contact run, `accounts:read` for an account run

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

### Parameters

- `runID string`

  The enrichment run ID.

### Returns

- `type EnrichmentRunGetEnrichmentRunResponse struct{…}`

  - `ID string`

    The enrichment run ID.

  - `CompletedAt string`

    When the run finished, or null while it is still open.

  - `CreatedAt string`

  - `EntityID string`

    The ID of the record being enriched.

  - `EntityType EnrichmentRunGetEnrichmentRunResponseEntityType`

    The type of record being enriched.

    - `const EnrichmentRunGetEnrichmentRunResponseEntityTypeContact EnrichmentRunGetEnrichmentRunResponseEntityType = "contact"`

    - `const EnrichmentRunGetEnrichmentRunResponseEntityTypeAccount EnrichmentRunGetEnrichmentRunResponseEntityType = "account"`

  - `StartedAt string`

    When the run began executing, or null while it is queued.

  - `Status EnrichmentRunGetEnrichmentRunResponseStatus`

    Where the run is: `queued` and `running` are in flight; `completed`, `failed` and `timed_out` are final.

    - `const EnrichmentRunGetEnrichmentRunResponseStatusQueued EnrichmentRunGetEnrichmentRunResponseStatus = "queued"`

    - `const EnrichmentRunGetEnrichmentRunResponseStatusRunning EnrichmentRunGetEnrichmentRunResponseStatus = "running"`

    - `const EnrichmentRunGetEnrichmentRunResponseStatusCompleted EnrichmentRunGetEnrichmentRunResponseStatus = "completed"`

    - `const EnrichmentRunGetEnrichmentRunResponseStatusFailed EnrichmentRunGetEnrichmentRunResponseStatus = "failed"`

    - `const EnrichmentRunGetEnrichmentRunResponseStatusTimedOut EnrichmentRunGetEnrichmentRunResponseStatus = "timed_out"`

  - `TargetFields []string`

    The fields this run set out to fill.

  - `Trigger EnrichmentRunGetEnrichmentRunResponseTrigger`

    What started the run: `creation` when the record was created, `manual` when requested through the API.

    - `const EnrichmentRunGetEnrichmentRunResponseTriggerCreation EnrichmentRunGetEnrichmentRunResponseTrigger = "creation"`

    - `const EnrichmentRunGetEnrichmentRunResponseTriggerManual EnrichmentRunGetEnrichmentRunResponseTrigger = "manual"`

  - `UpdatedAt string`

### 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"),
  )
  enrichmentRunGetEnrichmentRunResponse, err := client.EnrichmentRun.GetEnrichmentRun(context.TODO(), "runId")
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", enrichmentRunGetEnrichmentRunResponse.ID)
}
```

#### Response

```json
{
  "id": "id",
  "completedAt": "completedAt",
  "createdAt": "createdAt",
  "entityId": "entityId",
  "entityType": "contact",
  "startedAt": "startedAt",
  "status": "queued",
  "targetFields": [
    "string"
  ],
  "trigger": "creation",
  "updatedAt": "updatedAt"
}
```

## Domain Types

### Enrichment Run Enrich Response

- `type EnrichmentRunEnrichResponse struct{…}`

  - `EnrichmentRun EnrichmentRunEnrichResponseEnrichmentRun`

    The run, or null when the request was skipped.

    - `ID string`

      The enrichment run ID.

    - `CompletedAt string`

      When the run finished, or null while it is still open.

    - `CreatedAt string`

    - `EntityID string`

      The ID of the record being enriched.

    - `EntityType string`

      The type of record being enriched.

      - `const EnrichmentRunEnrichResponseEnrichmentRunEntityTypeContact EnrichmentRunEnrichResponseEnrichmentRunEntityType = "contact"`

      - `const EnrichmentRunEnrichResponseEnrichmentRunEntityTypeAccount EnrichmentRunEnrichResponseEnrichmentRunEntityType = "account"`

    - `StartedAt string`

      When the run began executing, or null while it is queued.

    - `Status string`

      Where the run is: `queued` and `running` are in flight; `completed`, `failed` and `timed_out` are final.

      - `const EnrichmentRunEnrichResponseEnrichmentRunStatusQueued EnrichmentRunEnrichResponseEnrichmentRunStatus = "queued"`

      - `const EnrichmentRunEnrichResponseEnrichmentRunStatusRunning EnrichmentRunEnrichResponseEnrichmentRunStatus = "running"`

      - `const EnrichmentRunEnrichResponseEnrichmentRunStatusCompleted EnrichmentRunEnrichResponseEnrichmentRunStatus = "completed"`

      - `const EnrichmentRunEnrichResponseEnrichmentRunStatusFailed EnrichmentRunEnrichResponseEnrichmentRunStatus = "failed"`

      - `const EnrichmentRunEnrichResponseEnrichmentRunStatusTimedOut EnrichmentRunEnrichResponseEnrichmentRunStatus = "timed_out"`

    - `TargetFields []string`

      The fields this run set out to fill.

    - `Trigger string`

      What started the run: `creation` when the record was created, `manual` when requested through the API.

      - `const EnrichmentRunEnrichResponseEnrichmentRunTriggerCreation EnrichmentRunEnrichResponseEnrichmentRunTrigger = "creation"`

      - `const EnrichmentRunEnrichResponseEnrichmentRunTriggerManual EnrichmentRunEnrichResponseEnrichmentRunTrigger = "manual"`

    - `UpdatedAt string`

  - `Reason EnrichmentRunEnrichResponseReason`

    Why the request was skipped: `no_targets` when the workspace enriches nothing this record is missing, `no_operations` when no provider can be scheduled for the targeted fields — because none looks them up on request, or because the record lacks the inputs (such as an email or domain) a lookup would need. Null otherwise.

    - `const EnrichmentRunEnrichResponseReasonNoTargets EnrichmentRunEnrichResponseReason = "no_targets"`

    - `const EnrichmentRunEnrichResponseReasonNoOperations EnrichmentRunEnrichResponseReason = "no_operations"`

  - `Status EnrichmentRunEnrichResponseStatus`

    `started` when this request began a run, `already_running` when one was already enriching the record, `skipped` when there was nothing to enrich.

    - `const EnrichmentRunEnrichResponseStatusStarted EnrichmentRunEnrichResponseStatus = "started"`

    - `const EnrichmentRunEnrichResponseStatusAlreadyRunning EnrichmentRunEnrichResponseStatus = "already_running"`

    - `const EnrichmentRunEnrichResponseStatusSkipped EnrichmentRunEnrichResponseStatus = "skipped"`

### Enrichment Run Get Enrichment Run Response

- `type EnrichmentRunGetEnrichmentRunResponse struct{…}`

  - `ID string`

    The enrichment run ID.

  - `CompletedAt string`

    When the run finished, or null while it is still open.

  - `CreatedAt string`

  - `EntityID string`

    The ID of the record being enriched.

  - `EntityType EnrichmentRunGetEnrichmentRunResponseEntityType`

    The type of record being enriched.

    - `const EnrichmentRunGetEnrichmentRunResponseEntityTypeContact EnrichmentRunGetEnrichmentRunResponseEntityType = "contact"`

    - `const EnrichmentRunGetEnrichmentRunResponseEntityTypeAccount EnrichmentRunGetEnrichmentRunResponseEntityType = "account"`

  - `StartedAt string`

    When the run began executing, or null while it is queued.

  - `Status EnrichmentRunGetEnrichmentRunResponseStatus`

    Where the run is: `queued` and `running` are in flight; `completed`, `failed` and `timed_out` are final.

    - `const EnrichmentRunGetEnrichmentRunResponseStatusQueued EnrichmentRunGetEnrichmentRunResponseStatus = "queued"`

    - `const EnrichmentRunGetEnrichmentRunResponseStatusRunning EnrichmentRunGetEnrichmentRunResponseStatus = "running"`

    - `const EnrichmentRunGetEnrichmentRunResponseStatusCompleted EnrichmentRunGetEnrichmentRunResponseStatus = "completed"`

    - `const EnrichmentRunGetEnrichmentRunResponseStatusFailed EnrichmentRunGetEnrichmentRunResponseStatus = "failed"`

    - `const EnrichmentRunGetEnrichmentRunResponseStatusTimedOut EnrichmentRunGetEnrichmentRunResponseStatus = "timed_out"`

  - `TargetFields []string`

    The fields this run set out to fill.

  - `Trigger EnrichmentRunGetEnrichmentRunResponseTrigger`

    What started the run: `creation` when the record was created, `manual` when requested through the API.

    - `const EnrichmentRunGetEnrichmentRunResponseTriggerCreation EnrichmentRunGetEnrichmentRunResponseTrigger = "creation"`

    - `const EnrichmentRunGetEnrichmentRunResponseTriggerManual EnrichmentRunGetEnrichmentRunResponseTrigger = "manual"`

  - `UpdatedAt string`
