CorvidReference

workflows

The wix-crm-backend module contains functionality for working with your site's workflows from backend code.

A workflow consists of a number of phases, also known as steps. The final phase in the workflow, the phase that indicates the workflow has been completed, is know as the win phase. Each phase can contain cards that move between the phases, indicating the card's progression through the workflow.

To use the Workflows API, import wixCrm from the wix-crm-backend module:

   import wixCrm from 'wix-crm-backend';

Table of Contents

FUNCTIONS

?
Perform actions on an object.
archiveCard( )Archives a workflow card.
createCard( )Creates a new workflow card.
createPhase( )Creates a new workflow phase.
deleteCard( )Deletes a workflow card by ID.
deletePhase( )Deletes a workflow phase by ID.
getCard( )Gets a workflow card by ID.
getPhase( )Gets a phase by ID.
getWorkflow( )Gets a workflow by ID.
moveCard( )Moves a card to a new position within a workflow.
movePhase( )Moves a phase to a new position with a workflow.
restoreCard( )Restores an archived workflow card.
updateCardFields( )Updates an existing workflow card.
updatePhaseFields( )Updates an existing workflow phase.
updateWorkflowFields( )Updates an existing workflow.

OBJECTS

?
Objects used when setting, getting, or calling the properties and methods listed above.
CardAn object containing card information.
MoveCardOptionsAn object containing information used when moving a card.
MovePhaseOptionsAn object containing information used when moving a phase.
PhaseAn object containing phase information.
WorkflowAn object containing information about a workflow.

archiveCard( )

Archives a workflow card.

Description

The archiveCard() function returns a Promise that resolves when the card has been archived.

Syntax

function archiveCard(id: string): Promise<void>
PARAMETERS
?
Values that you pass to a function.
id
string
ID of the card to archive.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the card has been archived.

Examples

Archive a card

import wixCrm from 'wix-crm-backend';

export function archiveCard(id){
  return wixCrm.workflows.archiveCard(id);
}

// Returns a promise that resolves to void.

createCard( )

Creates a new workflow card.

Description

The createCard() function returns a Promise that resolves to the created card's ID when the card is created in the specified workflow phase.

Pass a value for the position parameter to specify the newly created card's position within the specified phase. Positions are zero-based, meaning the first position is0. When omitted, the newly created card is added to the specified phase as the top card within the phase.

Syntax

function createCard(workflowId: string, phaseId: string, card: Card, [position: number]): Promise<string>
PARAMETERS
?
Values that you pass to a function.
workflowId
string
ID of the workflow to create the card in.
phaseId
string
ID of the phase to create the card in.
card
The data to use when creating the card.
position(Optional)
number
The created card's position within the workflow.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<string>
Fulfilled - ID of the newly created card.

Examples

Create a card

import wixCrm from 'wix-crm-backend';

export function createCard(workflowId, phaseId, contactId, position = undefined){
  return wixCrm.workflows.createCard(
    workflowId,
    phaseId,
    {
      "name": "Card Name",
      "contactId": contactId
    },
    position
  );
}

// Returns a promise that resolves to:
// "3c9683ea-f6cc-470b-b0d1-2eb6b8cea912"

createPhase( )

Creates a new workflow phase.

Description

The createPhase() function returns a Promise that resolves to the created phase ID when the phase is created in the specified workflow.

Pass a value for the position parameter to specify the newly created phase's position within the specified workflow. Positions are zero-based, meaning the first position is 0. When omitted, the newly created phase is added as the last non-win phase.

Syntax

function createPhase(workflowId: string, phase: Phase, [position: number]): Promise<string>
PARAMETERS
?
Values that you pass to a function.
workflowId
string
ID of the workflow to add the new phase to.
phase
The data required for phase creation.
position(Optional)
number
The created phase's position within the workflow.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<string>
Fulfilled - ID of the newly created phase.

Examples

Create a phase

import wixCrm from 'wix-crm-backend';

export function createPhase(workflowId, position){
  return wixCrm.workflows.createPhase(
    workflowId,
    {
      "name": "Phase Name"
    },
    position
  );
}

// Returns a promise that resolves to:
// "3c9683ea-f6cc-470b-b0d1-2eb6b8cea912"

deleteCard( )

Deletes a workflow card by ID.

Description

The deleteCard() function returns a Promise when the specified card has been deleted.

Syntax

function deleteCard(id: string): Promise<void>
PARAMETERS
?
Values that you pass to a function.
id
string
ID of the card to delete.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the card has been deleted.

Examples

Delete a card

import wixCrm from 'wix-crm-backend';

export function deleteCard(id){
  return wixCrm.workflows.deleteCard(id);
}

// Returns a promise that resolves to void.

deletePhase( )

Deletes a workflow phase by ID.

Description

The deletePhase() function returns a Promise when the specified phase has been deleted.

Syntax

function deletePhase(id: string): Promise<void>
PARAMETERS
?
Values that you pass to a function.
id
string
ID of the phase to delete.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the phase has been deleted.

Examples

Delete a phase

import wixCrm from 'wix-crm-backend';

export function deletePhase(id){
  return wixCrm.workflows.deletePhase(id);
}

// Returns a promise that resolves to void.

getCard( )

Gets a workflow card by ID.

Description

The getCard() function returns a Promise that resolves to the card with the specified ID.

Syntax

function getCard(id: string): Promise<Card>
PARAMETERS
?
Values that you pass to a function.
id
string
ID of the card to get.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<Card>
Fulfilled - The card with the given ID.

Examples

Get a card

import wixCrm from 'wix-crm-backend';

export function getCard(id){
  return wixCrm.workflows.getCard(id);
}

// Returns a promise that resolves to 
// {
//    "name": "Card Name",
//    "id": "63c83c38-f504-4eb8-a48c-1d77c436a678",
//    "contactId": "95bc7a80-5500-4445-9c90-adc0ff1b25ac",
//    "createdDate": "2019-05-05T12:23:43Z",
//    "updatedDate": "2019-05-05T12:23:43Z"
//   
// }

getPhase( )

Gets a phase by ID.

Description

The getPhase() function returns a Promise that resolves to the phase with the specified ID.

Syntax

function getPhase(id: string): Promise<Phase>
PARAMETERS
?
Values that you pass to a function.
id
string
ID of the phase to get.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<Phase>
Fulfilled - The phase with the specified ID.

Examples

Get a phase

import wixCrm from 'wix-crm-backend';

export function getPhase(id){
  return wixCrm.workflows.getPhase(id);
}

// Returns a promise that resolves to:
// {
//    name: "Phase Name",
//    id: "66f6443c-884f-4b12-beae-ab864fb489db"
// }

getWorkflow( )

Gets a workflow by ID.

Description

The getWorkflow() function returns a Promise that resolves to the workflow with the specified ID.

Syntax

function getWorkflow(id: string): Promise<Workflow>
PARAMETERS
?
Values that you pass to a function.
id
string
ID of the workflow to get.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<Workflow>
Fulfilled - The workflow with the specified ID.

Examples

Get a workflow

import wixCrm from 'wix-crm-backend';

export function getWorkflow(id){
  return wixCrm.workflows.getWorkflow(id);
}

/* Returns a promise that resolves to:
 *
 *  {  
 *    "name": "My Workflow",
 *    "id": "27cb0001-a464-4e1b-91c2-83d666577b75",
 *    "createdDate": "2019-05-19T12:35:55.408Z",
 *    "description": "Workflow description"
 *  }
 */

moveCard( )

Moves a card to a new position within a workflow.

Description

The moveCard() function returns a Promise when the specified card has been moved to the new position.

Use the options parameter to specify the phase and position within that phase to move the card to. Positions are zero-based, meaning the first position is 0.

Syntax

function moveCard(cardId: string, options: MoveCardOptions): Promise<void>
PARAMETERS
?
Values that you pass to a function.
cardId
string
ID of the card to move.
options
Information about where to move the card.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the card has moved.

Examples

Move a card

import wixCrm from 'wix-crm-backend';

export async function moveCard(cardId, phaseId){
  return await wixCrm.workflows.moveCard(
    cardId,
    {
      "newPhaseId": phaseId,
      "newPosition": 0
    }
  );
}

// Returns a promise that resolves to void.

movePhase( )

Moves a phase to a new position with a workflow.

Description

The movePhase() function returns a Promise when the specified phase has been moved to the new position.

Use the options parameter to specify the new phase position within the workflow. Any non-win phase can be moved to any non-win position. The win phase cannot be moved. Positions are zero-based, meaning the first position is 0.

Syntax

function movePhase(id: string, options: MovePhaseOptions): Promise<void>
PARAMETERS
?
Values that you pass to a function.
id
string
ID of the phase to move.
options
Information about where to move the phase.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the phase has moved.

Examples

Move a phase

import wixCrm from 'wix-crm-backend';

export async function movePhase(phaseId, workflowId){
  return await wixCrm.workflows.movePhase(
    phaseId,
    {
      "workflowId": workflowId,
      "newPosition": 0
    }
  );
}

// Returns a promise that resolves to void.

restoreCard( )

Restores an archived workflow card.

Description

The restoreCard() function returns a Promise that resolves when the archived card has been restored.

Syntax

function restoreCard(id: string, options: MoveCardOptions): Promise<void>
PARAMETERS
?
Values that you pass to a function.
id
string
ID of the card to restore.
options
Information about where to restore the card to.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the card has been restored.

Examples

Restore a card

import wixCrm from 'wix-crm-backend';

export async function restoreCard(cardId, phaseId){
  return await wixCrm.workflows.restoreCard(
    cardId,
    {
      "newPhaseId": phaseId,
      "newPosition": 0
    }
  );
}

// Returns a promise that resolves to void.

updateCardFields( )

Updates an existing workflow card.

Description

The updateCardFields() function returns a Promise that resolves when the card has been updated with the specified values.

Only the properties passed in the Card object will be updated. All other properties will remain the same.

Syntax

function updateCardFields(id: string, card: Card): Promise<void>
PARAMETERS
?
Values that you pass to a function.
id
string
ID of the card to update.
card
The information to update the card with.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the card has been updated.

Examples

Update a card

import wixCrm from 'wix-crm-backend';

export function updateCardFields(id){
  return wixCrm.workflows.updateCardFields(
    id, 
    {
      "name": "New Name"
    }
  );
}

// Returns a promise that resolves to void

updatePhaseFields( )

Updates an existing workflow phase.

Description

The updatePhaseFields() function returns a Promise that resolves when the phase has been updated with the specified values.

Only the properties passed in the Phase object will be updated. All other properties will remain the same.

Syntax

function updatePhaseFields(id: string, phase: Phase): Promise<void>
PARAMETERS
?
Values that you pass to a function.
id
string
ID of the phase to update.
phase
The information to update the workflow phase with.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the phase has been updated.

Examples

Update a phase

import wixCrm from 'wix-crm-backend';

export function updatePhaseFields(id){
  return wixCrm.workflows.updatePhaseFields(
    id,
    {
      "name": "New Name"
    }
  );
}

// Returns a promise that resolves to void.

updateWorkflowFields( )

Updates an existing workflow.

Description

The updateWorkflowFields() function returns a Promise that resolves when the workflow has been updated with the specified values.

Only the properties passed in the Workflow object will be updated. All other properties will remain the same.

Syntax

function updateWorkflowFields(id: string, workflow: Workflow): Promise<void>
PARAMETERS
?
Values that you pass to a function.
id
string
ID of the workflow to update.
workflow
The information to update the workflow with.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the workflow has been updated.

Examples

Update a workflow

import wixCrm from 'wix-crm-backend';

export function updateWorkflowFields(id){
  return wixCrm.workflows.updateWorkflowFields(
    id,
    {
      "name": "New Name"
    }
  );
}

// Returns a promise that resolves to void.

Card

An object containing card information.

Syntax

type Card = {
  name: string
  id: string
  contactId: string
  createdDate: Date
  updatedDate: Date
  source: string
}
MEMBERS
?
The properties of an object.
name
string
Name of the card.
id
string
Unique card identifier.
contactId
string
ID of the contact associated with the card.
createdDate
Date
Date the card was created.
updatedDate
Date
Date the card was last updated.
source
string

Source that created the card.

One of:

  • "Contacts"
  • "Inbox"
  • "Invoices"
  • "Price Quotes"
  • "Wix Forms"

Examples

Gets a card

import wixCrm from 'wix-crm-backend';

export function getCard(id){
  return wixCrm.workflows.getCard(id);
}

// Returns a promise that resolves to 
// {
//    "name": "Card Name",
//    "id": "63c83c38-f504-4eb8-a48c-1d77c436a678",
//    "contactId": "95bc7a80-5500-4445-9c90-adc0ff1b25ac",
//    "createdDate": "2019-05-05T12:23:43Z",
//    "updatedDate": "2019-05-05T12:23:43Z"
//   
// }

MoveCardOptions

An object containing information used when moving a card.

Syntax

type MoveCardOptions = {
  newPhaseId: string
  newPosition: number
}
MEMBERS
?
The properties of an object.
newPhaseId(Optional)
string
ID of the phase to move the card to. If omitted, the card remains in the same phase.
newPosition(Optional)
number
Position within the phase to move the card to. If omitted, the card is moved to the top of the phase.

Examples

Move a card

import wixCrm from 'wix-crm-backend';

export async function moveCard(cardId, phaseId){
  return await wixCrm.workflows.moveCard(
    cardId,
    {
      "newPhaseId": phaseId,
      "newPosition": 0
    }
  );
}

// Returns a promise that resolves to void.

MovePhaseOptions

An object containing information used when moving a phase.

Syntax

type MovePhaseOptions = {
  workflowId: string
  newPosition: number
}
MEMBERS
?
The properties of an object.
workflowId
string
ID of the workflow to move the phase to.
newPosition
number
Position within the workflow to move the phase to.

Examples

Move a phase

import wixCrm from 'wix-crm-backend';

export async function movePhase(phaseId, workflowId){
  return await wixCrm.workflows.movePhase(
    phaseId,
    {
      "workflowId": workflowId,
      "newPosition": 0
    }
  );
}

// Returns a promise that resolves to void.

Phase

An object containing phase information.

Syntax

type Phase = {
  name: string
  id: string
}
MEMBERS
?
The properties of an object.
name
string
Name of the phase.
id
string
Unique phase identifier.

Examples

Gets a phase

import wixCrm from 'wix-crm-backend';

export function getPhase(id){
  return wixCrm.workflows.getPhase(id);
}

// Returns a promise that resolves to:
// {
//    name: "Phase Name",
//    id: "66f6443c-884f-4b12-beae-ab864fb489db"
// }

Workflow

An object containing information about a workflow.

Syntax

type Workflow = {
  id: string
  name: string
  description: string
  createdDate: Date
}
MEMBERS
?
The properties of an object.
id
string
Unique workflow identifier.
name
string
Name of the workflow.
description
string
Workflow description.
createdDate
Date
Date the workflow was created.

Examples

Gets a workflow

import wixCrm from 'wix-crm-backend';

export function getWorkflow(id){
  return wixCrm.workflows.getWorkflow(id);
}

/* Returns a promise that resolves to:
 *
 *  {  
 *    "name": "My Workflow",
 *    "id": "27cb0001-a464-4e1b-91c2-83d666577b75",
 *    "createdDate": "2019-05-19T12:35:55.408Z",
 *    "description": "Workflow description"
 *  }
 */