Pipelines and their stages for deals, tickets, and other pipeline-backed objects. Deal and ticket dealstage/hs_pipeline_stage values are stage ids ("appointmentscheduled", or numeric ids in custom pipelines), not the labels users see, so resolve labels here before writing them.

Functions

find-stage

fn (object-type: Str, pipeline: Str, stage: Str): Any
fn (object-type: Str, pipeline: Str, stage: Str, opts: Map): Any

Look up a stage by pipeline and stage id or label, e.g. find-stage("deals", "Sales Pipeline", "Contract Sent"). Returns {pipeline_id, stage_id, stage} or null.

Example

found ::hubspot::pipelines/find-stage("deals", "default", "Contract Sent")
if(is-some(found),
  ::hubspot::deals/update-deal("12345", {pipeline: found.pipeline_id, dealstage: found.stage_id}),
  null)

find-stage-in

fn (pipelines: Map, pipeline: Str, stage: Str): Map?

Resolve a stage from a list-pipelines response. pipeline and stage each match an id or a label (case-insensitive). Returns {pipeline_id, stage_id, stage} or null. Exposed for testing; find-stage calls the API.

Example

pipelines {results: [{id: "default", label: "Sales", stages: [{id: "won", label: "Closed Won"}]}]}
::hubspot::pipelines/find-stage-in(pipelines, "sales", "closed won").stage_id  // "won"
::hubspot::pipelines/find-stage-in(pipelines, "sales", "lost")  // null

get-pipeline

fn (object-type: Str, pipeline-id: Str): Map
fn (object-type: Str, pipeline-id: Str, opts: Map): Map

GET /crm/pipelines/{version}/{objectType}/{pipelineId} - One pipeline with its stages. The default deal pipeline's id is "default".

Example

pipeline ::hubspot::pipelines/get-pipeline("deals", "default")
map(pipeline.stages, %.label)

get-stage

fn (object-type: Str, pipeline-id: Str, stage-id: Str): Map
fn (object-type: Str, pipeline-id: Str, stage-id: Str, opts: Map): Map

GET /crm/pipelines/{version}/{objectType}/{pipelineId}/stages/{stageId}

  • One stage.

Example

stage ::hubspot::pipelines/get-stage("deals", "default", "appointmentscheduled")
stage.metadata.probability

list-pipelines

fn (object-type: Str): Map
fn (object-type: Str, opts: Map): Map

GET /crm/pipelines/{version}/{objectType} - Every pipeline for an object type ("deals", "tickets", ...) with its stages: {results: [{id, label, displayOrder, stages: [{id, label, displayOrder, metadata}]}]}. Deal stage metadata.probability is the win probability; metadata.isClosed marks closed stages.

Example

out ::hubspot::pipelines/list-pipelines("deals")
map(out.results, %.label)

list-stages

fn (object-type: Str, pipeline-id: Str): Map
fn (object-type: Str, pipeline-id: Str, opts: Map): Map

GET /crm/pipelines/{version}/{objectType}/{pipelineId}/stages - The stages of one pipeline: {results: [{id, label, displayOrder, metadata}]}.

Example

out ::hubspot::pipelines/list-stages("deals", "default")
map(out.results, %.id)