# Context API

All of these properties are available via [advanced logic](https://docs.feathery.io/platform/build-forms/advanced-logic), [event handlers](https://docs.feathery.io/develop/react/api-guide/form/event-handlers), and the [contextRef](https://docs.feathery.io/develop/react/api-guide/form/contextref) object. Specific events may also have additional properties unique to them. To see these properties, check out the documentation for the corresponding [event handler](https://docs.feathery.io/develop/react/api-guide/form/event-handlers).

|           Key           |                                                                                     Type                                                                                    | Description                                                                                                                                                                                                                                                                                                              |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
| :---------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- | -------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|        `formName`       |                                                                                   `string`                                                                                  | The name of the form                                                                                                                                                                                                                                                                                                     |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|         `formId`        |                                                                                   `string`                                                                                  | The ID of the form                                                                                                                                                                                                                                                                                                       |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|         `userId`        |                                                                                   `string`                                                                                  | The ID of the user in the current form session                                                                                                                                                                                                                                                                           |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|         `fields`        |                                                                       `{ [fieldKey: string]: Field }`                                                                       | A mapping that contains all fields on any of your forms. Its key is the field ID and value is a [Field](https://docs.feathery.io/develop/context-api/field-object) object. Use the Field object to read/write a field value, options, error message, etc.                                                                |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|   `getStepProperties`   | `() => { totalSteps: number, stepName: string, previousStepName: string, backgroundColor: hex string, language?: string, hideRules: { elementType: string; rules: {}[] } }` | <p>Returns useful information about the current step of the form:</p><ul><li>Name of current step</li><li>Name of previous step</li><li>Background color of step</li><li>Total steps in form</li><li>Language code of form if set</li><li>Conditional hide/show rules on step</li></ul>                                  |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|        `goToStep`       |                                                                                  `function`                                                                                 | If you want to reroute the user to a different step, pass `goToStep` the ID of the new step to route to. For example, `goToStep('new-step')`                                                                                                                                                                             |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|      `setProgress`      |                                                        `(number \| { progress?: number; segments ?: number }) => {}`                                                        | <p>Set the amount of the progress bar on the current step.</p><p></p><p>Pass in either a number from 0 - 100 or if you want a segmented progress bar, you can pass in both the progress amount and the number of segments you want the progress bar to be broken into.</p>                                               |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|   `setFormCompletion`   |                                                                                  `function`                                                                                 | Pass in a boolean flag to set the user's completion status for this form.                                                                                                                                                                                                                                                |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|      `validateStep`     |                                                     `(showErrors = true) => { [fieldKey: string]: string \| string[] }`                                                     | <p>Runs default form validation on the current step. Triggers built-in field validation along with custom validation rules specified from the dashboard. Errors will be shown unless false is passed for showErrors. </p><p><br>Returns an error message per field, or an empty string if the field is valid.</p>        |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|       `isLastStep`      |                                                                               `() => boolean`                                                                               | Returns `True` when the current step is the last step the user needs to complete.                                                                                                                                                                                                                                        |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|       `isTestForm`      |                                                                               `() => boolean`                                                                               | Returns `True` when the current form is in test mode (and not live).                                                                                                                                                                                                                                                     |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|      `collaborator`     |                         [`Collaborator`](https://docs.feathery.io/platform/collaborative-workflows/collaboration#collaborator-object-in-logic-rules)                        | Information about the active collaborator.                                                                                                                                                                                                                                                                               |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
| `runIntegrationActions` |                                                                    <p></p><p><code>(actionIds: string\[]                                                                    | string,</code><br><code>options: {waitForCompletion?: boolean;multiple?: boolean}) => Promise<{ ok: boolean; error?: string; payload?: any}></code></p>                                                                                                                                                                  | <p>Trigger integration actions that have been set up with the <code>Custom Logic</code> trigger. If multiple actions are passed, they will be run in order.</p><p></p><p>If <code>waitForCompletion</code> is true (the default), the returned Promise will resolve with data from the last action once it completes. Otherwise, it will return immediately with no data.<br><br>If <code>multiple</code> is true (defaults to false), you may trigger the same action multiple times for a single submission.</p>                                                                    |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|    `runAIExtraction`    |                           <p><code>(extractionId: string,</code><br><code>options: {waitForCompletion?: boolean,</code><br><code>pages?: number\[]                          | number\[]\[],</code><br><code>variantId?: string})</code></p>                                                                                                                                                                                                                                                            | <p>Trigger an AI document extraction. <br><br>If <code>waitForCompletion</code> is true, the returned Promise will resolve with data from the last action once it completes. Otherwise, it will return immediately with no data.<br><br>If <code>variantId</code> is specified, the extraction will run with that variant applied.<br><br>If <code>pages</code> is an array of page numbers, the extraction will run on the page numbers specified once. If <code>pages</code> is an array of arrays of page numbers, the extraction will run once on each array of page numbers.</p> |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|   `generateDocuments`   |                              <p><code>({documentIds: string\[],</code><br><code>download: boolean,</code><br><code>merge: boolean})</code></p>                              | <p>Trigger document/s to generate envelopes.<br><br>If <code>download</code> is true, after the envelopes are generated the user will be prompted to download them.<br><br>If <code>merge</code> is true, all the pdf documents will be merged into one pdf file in the order specified in <code>documentIds</code>.</p> |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|      `updateUserId`     |                                                                 `(userId: string, merge?: boolean) => void`                                                                 | Update the user ID of the current session. [Full reference](https://docs.feathery.io/develop/react/api-guide/updateuserid)                                                                                                                                                                                               |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|      `updateTheme`      |                                                                          `(theme: string) => void`                                                                          | Update the theme of all embedded forms dynamically                                                                                                                                                                                                                                                                       |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|        `openUrl`        |                                                                `async (url: string, target?: string) => void`                                                               | Flush any pending field updates and then opens up a URL. If target isn't specified, it defaults to `_blank` and opens in a new tab. To open in the same tab, specify `_self` for the target.                                                                                                                             |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|     `setCalendlyUrl`    |                                                                           `(url: string) => void`                                                                           | If a [Calendly](https://feathery.io/integrations/calendly) scheduling flow is embedded in your form, you can dynamically update the calendar by calling this function and passing in a new Calendly URL.                                                                                                                 |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|          `cart`         |                                    [`Cart`](https://docs.feathery.io/guides/payment-flow/select-products-or-plans#logic-rule-cart-access)                                   | If the Stripe connector is configured and connected, then the purchase cart is available with a number of properties about the cart and items within it.  See [here](https://docs.feathery.io/guides/payment-flow/select-products-or-plans#logic-rule-cart-access) for details.                                          |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|        `products`       |            { \[product\_id: string]: [`Products`](https://docs.feathery.io/guides/payment-flow/select-products-or-plans#logic-rule-stripe-purchasable-products) }           | If the Stripe connector is configured and connected, then the purchasable products are available as a hash.  See [here](https://docs.feathery.io/guides/payment-flow/select-products-or-plans#logic-rule-stripe-purchasable-products) for details.                                                                       |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |                                                                     |          |                  |                                                                                                                                                                                                                                                                                                                                                                             |
|     `dataHubAction`     |                                                                 <p><code>(hubId: string, operation: "create"                                                                | "get"                                                                                                                                                                                                                                                                                                                    | "update</code><br> <code>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | "delete", entryId?: string, data?: Record\<string, string>) => void | Entry\[] | Entry</code></p> | <p>If Data Hubs are enabled for your organization, and your form has authentication enabled, you can perform data hub actions.<br><br>If <code>entryId</code> is not specified when using <code>get</code>, every data hub entry will be returned.<br><br>You must specify an <code>entryId</code> when using the <code>update</code> or <code>delete</code> operation.</p> |

#### [Deprecated Context API](https://docs.feathery.io/develop/context-api/deprecated-context-api)
