Skip to content
LogoLogo

Lead schema

See Management API schema for every domain, the endpoint and authentication.

Queries

lead

Reads a lead. Scope: ORGANIZATION_LEADS_READ.

lead(input: LeadInput!): Lead @auth

Mutations

leadCreate

Creates a lead and sets its labels, then starts the workflows triggered by lead.created. Answers that do not match their fields return userErrors and nothing is written. ORGANIZATION_LEADS_UPDATE is required only with labels. Scope: ORGANIZATION_LEADS_CREATE, ORGANIZATION_LEADS_READ and ORGANIZATION_LEADS_UPDATE.

leadCreate(input: LeadCreateInput!): LeadCreatePayload! @auth

leadUpdate

Merges answers into a lead and sets its labels, then starts the workflows triggered by lead.updated when anything changed. A workflow on lead.updated that calls this mutation starts itself again unless its own conditions stop it. Scope: ORGANIZATION_LEADS_UPDATE and ORGANIZATION_LEADS_READ.

leadUpdate(input: LeadUpdateInput!): LeadUpdatePayload! @auth

leadUpsert

Merges answers into the newest lead of a visitor, or creates a lead when that lead is older than sameLeadWithin. Starts the workflows triggered by lead.created or lead.updated. Scope: ORGANIZATION_LEADS_CREATE, ORGANIZATION_LEADS_UPDATE and ORGANIZATION_LEADS_READ.

leadUpsert(input: LeadUpsertInput!): LeadUpsertPayload! @auth

leadDelete

Deletes a lead and its labels. This cannot be undone. Scope: ORGANIZATION_LEADS_DELETE.

leadDelete(input: LeadDeleteInput!): LeadDeletePayload! @auth

Types

Lead

"""
One set of answers that a visitor gave to a flow. It belongs to the project and stays after a new
version is published.
"""
type Lead {
  """The ID of the lead."""
  id: ID!
  """The ID of the project that captured the lead."""
  projectId: ID!
  """
  The Picked ID of the visitor: the ID the SDK keeps for one browser. Sentry tags and Shopify
  order attributes carry the same value as `picked.id`. Null when the lead was written without
  one.
  """
  pickedId: String
  """The visitor's Picked ID. Null when the lead was written without one."""
  userId: String @deprecated(reason: "Use `pickedId`.")
  """
  The other identifiers of the visitor, which the lead's analytics events carry.
  """
  identifiers: LeadIdentifiers!
  """
  The ID of the version whose fields the lead was last written against. Null when the lead
  references a workspace, or no schema.
  """
  workspaceVersionId: ID
  """
  The version whose fields the lead was last written against. Null when the lead references a
  workspace, or no schema.
  """
  workspaceVersion: WorkspaceVersion
  """
  The ID of the workspace whose fields the lead was last written against. Null when the lead
  references a version, or no schema.
  """
  workspaceId: ID
  """
  The workspace whose fields the lead was last written against. Null when the lead references a
  version, or no schema, or the workspace was deleted.
  Scope: `ORGANIZATION_WORKSPACE_READ`.
  """
  workspace: Workspace @auth
  """
  The answers, each with the label and type of its field in the schema the lead references. An
  answer whose key the schema does not name has the key as its label and `TEXT` as its type.
  """
  responses: [LeadResponse!]!
  """The labels on the lead, ordered by namespace, then key."""
  labels: [Label!]!
  """
  The changes to the lead, newest first: its capture, and each later change, its labels included.
  Scope: `ORGANIZATION_LEADS_READ`.
  """
  operations(first: Int, after: String, sortKey: OperationSortKeys = OCCURRED_AT, reverse: Boolean = true): LeadOperationConnection! @auth
  """
  The workflow runs that created or changed the lead, each once, newest first.
  Scope: `ORGANIZATION_LEADS_READ` and `ORGANIZATION_WORKSPACE_READ`.
  """
  workflowRuns(first: Int, after: String, last: Int, before: String, reverse: Boolean = true): WorkflowRunConnection! @auth
  """
  Every lead with the same `pickedId`, this lead included, newest first. A visitor who passes
  several capture points in one flow leaves a lead at each. For a lead without a `pickedId`, the
  lead alone.
  Scope: `ORGANIZATION_LEADS_READ`.
  """
  sessionLeads(first: Int, after: String, last: Int, before: String, reverse: Boolean = true): LeadConnection! @auth
  """
  The visit in which the visitor gave the lead. Null when the lead has no capture event or no
  `pickedId`, or when analytics holds no event for it yet or the capture happened outside
  production.
  Scope: `ORGANIZATION_SESSIONS_READ`.
  """
  session: AnalyticsSession @auth
  """When the lead was captured."""
  createdAt: DateTime!
  """When the lead last changed."""
  updatedAt: DateTime!
}

LeadOperation

"""
A change to a lead, made by a workflow run task, a person or an integration.
"""
type LeadOperation implements Operation {
  """The ID of the operation."""
  id: ID!
  """What the operation did to the lead."""
  type: OperationType!
  """When the operation happened."""
  occurredAt: DateTime!
  """
  The workflow run task that made the change. Null when a workflow did not make it.
  """
  task: WorkflowTask
  """The ID of the lead, which stays after the lead is deleted."""
  leadId: ID!
  """The lead. Null when the lead was deleted."""
  lead: Lead
}

LeadOperationConnection

"""A page of lead operations."""
type LeadOperationConnection {
  """The edges in this page."""
  edges: [LeadOperationEdge!]!
  """The operations in this page."""
  nodes: [LeadOperation!]!
  """Where this page sits in the list."""
  pageInfo: PageInfo!
  """The total number of operations on the lead."""
  totalCount: Int!
}

LeadOperationEdge

"""A lead operation in a page of results."""
type LeadOperationEdge {
  """The cursor of this edge."""
  cursor: String!
  """The operation."""
  node: LeadOperation!
}

LeadResponse

"""
One answer in a lead, held under the key of the field that asked for it.
"""
type LeadResponse {
  """The key of the field."""
  key: String!
  """The label of the field. For a preview capture, the key."""
  label: String!
  """The type of the field. For a preview capture, `TEXT`."""
  type: FieldType!
  """The answer, shaped by `type`."""
  value: JSON
}

LeadSearchSuggestion

"""A leads search suggested for what was typed into a leads search box."""
type LeadSearchSuggestion {
  """The leads search query."""
  query: String!
  """What the query finds, in plain English."""
  description: String!
  """
  How many leads the query matches within the window. Null when a `session.` clause leaves the
  query without a total.
  """
  count: Int
}

LeadConnection

"""A page of leads."""
type LeadConnection {
  """The edges in this page."""
  edges: [LeadEdge!]!
  """The leads in this page."""
  nodes: [Lead!]!
  """Where this page sits in the list."""
  pageInfo: PageInfo!
  """
  The total number of leads the query matches. Fails for a query with a `session.` clause.
  """
  totalCount: Int! @deprecated(reason: "Use matchCount, which is null for a query with a session. clause.")
  """
  The number of leads the query matches across all pages. Null when the query has a `session.`
  clause.
  """
  matchCount: Int
  """Metrics over every lead the query matches, across all pages."""
  metrics: LeadMetrics!
}

LeadMetrics

"""
Metrics over the leads a `LeadConnection` matches. They ignore the page window and `sort`, so
`first: 0` reads them without a page.
"""
type LeadMetrics {
  """
  The number of matching leads by capture time.
  
  `groupBy` splits the count by a path in the lead query language: a label (`labels.aia.status`
  or `aia.status`) or a response (`responses.state` or `state`). Leads with no value at the path
  group under an empty key. Under a `session.` clause, the count reads the visit of each capture
  event.
  """
  count(groupBy: String): CountMetric!
}

LeadCollapse

"""
How `Project.leads` treats several leads with the same `Lead.pickedId`.
"""
enum LeadCollapse {
  """Every lead the query matches."""
  NONE
  """
  One lead per `pickedId`: the newest the query matches, which `matchCount` and `metrics` count once.
  Each lead without a `pickedId` counts on its own. Not allowed with a `session.` clause.
  """
  SESSION
}

LeadEdge

"""A lead in a page of results."""
type LeadEdge {
  """The cursor of this edge."""
  cursor: String!
  """The lead."""
  node: Lead!
}

LeadInput

"""The input of `lead`."""
input LeadInput {
  """The ID of the lead."""
  id: ID!
}

LeadDeleteInput

"""The input of `leadDelete`."""
input LeadDeleteInput {
  """The ID of the lead."""
  id: ID!
}

LeadDeletePayload

"""The result of `leadDelete`."""
type LeadDeletePayload {
  """The ID of the deleted lead."""
  deletedLeadId: ID
}

LeadIdentifiers

"""The identifiers of a lead's visitor beside the Picked ID."""
type LeadIdentifiers {
  """
  The Google Analytics client ID of the visitor. Null when none was given.
  """
  gaid: String
  """The Shopify client ID of the visitor. Null when none was given."""
  shopifyClientId: String
  """The Google Ads click ID of the visit. Null when none was given."""
  gclid: String
  """
  The site's own ID for the visitor, such as a hashed customer ID. Null when none was given.
  """
  userId: String
}

LeadIdentifiersInput

"""
The identifiers of a lead's visitor to set. Each is 1 to 255 characters. Omit one to keep its
value.
"""
input LeadIdentifiersInput {
  """The Google Analytics client ID of the visitor."""
  gaid: String
  """The Shopify client ID of the visitor."""
  shopifyClientId: String
  """The Google Ads click ID of the visit."""
  gclid: String
  """
  The site's own ID for the visitor, such as a hashed customer ID, stored and sent as given.
  Picked recognises the same visitor wherever the same value is sent, so send it in the form the
  Google Tag Manager template sends it: `sha256:` and the hex SHA-256 of `<projectId>:<id>`.
  """
  userId: String
}

LeadMergePreference

"""
Which value a lead keeps for a response key that both the lead and the write hold.
"""
enum LeadMergePreference {
  """The value the write gives."""
  NEWER
  """The value the lead holds, unless it is blank."""
  OLDER
}

LeadCreateInput

"""The input of `leadCreate`."""
input LeadCreateInput {
  """The ID of the project the lead belongs to."""
  projectId: ID!
  """The Picked ID of the visitor. Omit it to give the lead a new one."""
  pickedId: String
  """The other identifiers of the visitor."""
  identifiers: LeadIdentifiersInput
  """Whether the `lead_created` analytics event is tracked."""
  trackLeadCreatedEvent: Boolean = false
  """
  The answers, as a JSON object keyed by field key. A null, an empty string, an empty list or an
  empty object is left out.
  """
  responses: JSON!
  """The labels to set on the lead."""
  labels: [LabelInput!]
  """
  The ID of the workspace whose current fields the answers are checked against. Omit both this
  and `workspaceVersionId` to check against the version the project serves.
  """
  workspaceId: ID
  """The ID of the version whose fields the answers are checked against."""
  workspaceVersionId: ID
}

LeadCreatePayload

"""The result of `leadCreate`."""
type LeadCreatePayload {
  """The created lead. Null when the lead was not created."""
  lead: Lead
  """
  The errors that stopped the lead being created, or a label that could not be written.
  """
  userErrors: [LeadUserError!]!
}

LeadUpdateInput

"""The input of `leadUpdate`. Omit a field to keep its value."""
input LeadUpdateInput {
  """The ID of the lead."""
  id: ID!
  """
  Which value the lead keeps for a key that both the lead and `responses` hold.
  """
  prefer: LeadMergePreference!
  """
  The answers to merge into the lead, as a JSON object keyed by field key. A null, an empty
  string, an empty list or an empty object changes nothing.
  """
  responses: JSON
  """The labels to set on the lead."""
  labels: [LabelInput!]
  """The identifiers of the visitor to set on the lead."""
  identifiers: LeadIdentifiersInput
  """
  Whether the `lead_updated` analytics event is tracked when the answers change.
  """
  trackLeadUpdatedEvent: Boolean = false
  """
  The ID of the workspace whose current fields the answers are checked against. Omit both this
  and `workspaceVersionId` to check against the version the project serves.
  """
  workspaceId: ID
  """The ID of the version whose fields the answers are checked against."""
  workspaceVersionId: ID
}

LeadUpdatePayload

"""The result of `leadUpdate`."""
type LeadUpdatePayload {
  """The lead. Null when the update was refused."""
  lead: Lead
  """
  Whether the answers, the labels or the identifiers of the lead changed.
  """
  updated: Boolean!
  """The response keys whose value changed, in key order."""
  changedKeys: [String!]!
  """
  The errors that stopped the update, or a label that could not be written.
  """
  userErrors: [LeadUserError!]!
}

LeadUpsertInput

"""The input of `leadUpsert`."""
input LeadUpsertInput {
  """The ID of the project the lead belongs to."""
  projectId: ID!
  """The Picked ID of the visitor."""
  pickedId: String!
  """
  How recently, in seconds, the visitor's newest lead must have changed to be updated, from 1 to
  31536000 (365 days).
  """
  sameLeadWithin: Int!
  """
  Which value the lead keeps for a key that both the lead and `responses` hold.
  """
  prefer: LeadMergePreference!
  """
  The answers, as a JSON object keyed by field key. A null, an empty string, an empty list or an
  empty object is left out.
  """
  responses: JSON
  """The labels to set on the lead."""
  labels: [LabelInput!]
  """The identifiers of the visitor to set on the lead."""
  identifiers: LeadIdentifiersInput
  """
  Whether the `lead_created` analytics event is tracked when the upsert creates a lead.
  """
  trackLeadCreatedEvent: Boolean = false
  """
  Whether the `lead_updated` analytics event is tracked when the upsert changes a lead's answers.
  """
  trackLeadUpdatedEvent: Boolean = false
  """
  The ID of the workspace whose current fields the answers are checked against. Omit both this
  and `workspaceVersionId` to check against the version the project serves.
  """
  workspaceId: ID
  """The ID of the version whose fields the answers are checked against."""
  workspaceVersionId: ID
}

LeadUpsertPayload

"""The result of `leadUpsert`."""
type LeadUpsertPayload {
  """The lead. Null when the upsert was refused."""
  lead: Lead
  """Whether a lead was created."""
  created: Boolean!
  """
  Whether the answers, the labels or the identifiers of an existing lead changed.
  """
  updated: Boolean!
  """
  The response keys whose value changed, in key order. Every key of a created lead.
  """
  changedKeys: [String!]!
  """
  The errors that stopped the upsert, or a label that could not be written.
  """
  userErrors: [LeadUserError!]!
}

LeadUserErrorCode

"""The codes of a lead write's user errors."""
enum LeadUserErrorCode {
  """No lead with that ID can be read."""
  LEAD_NOT_FOUND
  """Both `workspaceId` and `workspaceVersionId` were given."""
  WORKSPACE_REFERENCE_CONFLICT
  """The project has no workspace with that ID."""
  WORKSPACE_NOT_FOUND
  """The project has no workspace version with that ID."""
  WORKSPACE_VERSION_NOT_FOUND
  """
  The project serves no version, and neither `workspaceId` nor `workspaceVersionId` was given.
  """
  NO_LIVE_VERSION
  """A response key names no field."""
  RESPONSE_KEY_UNKNOWN
  """
  A response value does not match the type, list setting or options of its field.
  """
  RESPONSE_VALUE_INVALID
  """A label cannot be written. The message says why."""
  LABEL_INVALID
}

LeadUserError

"""An error in a lead write that the caller can correct."""
type LeadUserError {
  """
  The path to the input field that caused the error, such as `["input", "responses", "email"]`.
  Null when no single field is at fault.
  """
  field: [String!]
  """A message that describes the error."""
  message: String!
  """The error code."""
  code: LeadUserErrorCode!
}

LeadReport

"""
An embedded analytics report on the leads of one project. Its date range is a filter inside the
embed.
"""
type LeadReport {
  """The kind of report."""
  kind: LeadReportKind!
  """
  The URL of a signed embed of the report, for an iframe. The signature expires 3 hours after the
  field is read.
  """
  embedUrl: String!
  """
  The id of the analytics dashboard of this kind that the Embedded Analytics SDK renders, in the
  project's data residency.
  """
  analyticsDashboardId: Int!
}

LeadReportKind

"""The kinds of lead report."""
enum LeadReportKind {
  """
  How leads arrive: volume, channel, referrer, campaign, landing page, device, place and time.
  """
  ACQUISITION
  """
  The paths to leads: first touch, step sequences, visits and time to capture.
  """
  JOURNEYS
  """
  How visits convert to leads: the funnel, the lead rate by week and segment, and what leads did.
  """
  CONVERSION
}