> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

# GetDynamicSchema

# Package: triggers

# Namespace: TriggerProviderService

# Method link: https://dev.wix.com/docs/api-reference/business-management/automations/triggers/trigger-provider-service-plugin/get-dynamic-schema.md

## Introduction

This endpoint returns a [JSON schema](https://json-schema.org/) object
that's used to dynamically update the fields available to a Wix user
when they configure an [automation](https://www.wix.com/my-account/site-selector/?buttonText=Select%20Site&title=Select%20a%20Site&autoSelectOnSingleSite=true&actionUrl=https:%2F%2Fwww.wix.com%2Fdashboard%2F%7B%7BmetaSiteId%7D%7D%2Ftriggers/site-automations).

Wix calls this endpoint when a user selects an option from an
[item selection filter](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/automations/triggers/filter-fields.md#item-selection)
configured for a trigger.
Wix appends the returned schema to the
[payload schema](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/automations/triggers/payload-schema.md)
you defined for the trigger and makes the fields available to the Wix user's automation.

---

## REST API

### Schema

```
 Method: getDynamicSchema
 Description: This endpoint returns a [JSON schema](https://json-schema.org/) object that's used to dynamically update the fields available to a Wix user when they configure an [automation](https://www.wix.com/my-account/site-selector/?buttonText=Select%20Site&title=Select%20a%20Site&autoSelectOnSingleSite=true&actionUrl=https:%2F%2Fwww.wix.com%2Fdashboard%2F%7B%7BmetaSiteId%7D%7D%2Ftriggers/site-automations).  Wix calls this endpoint when a user selects an option from an [item selection filter](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/automations/triggers/filter-fields.md#item-selection) configured for a trigger. Wix appends the returned schema to the [payload schema](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/automations/triggers/payload-schema.md) you defined for the trigger and makes the fields available to the Wix user's automation.
 URL: {DEPLOYMENT-URI}/dynamic-schema
 Method: POST
 # Note: If the parameter `a.b` is listed under required parameters, `b` is only required if `a` is also present.
 Required parameters:  triggerKey
 Method parameters: 
   param name: selectedFilterOptions | type: array<selectedFilterOptions> | description: Current selection state of the trigger's filters.  | validation: maxItems 5
              - name: fieldKey | type: string | description: Key representing a field from the trigger's [payload schema](https://dev.wix.com/docs/rest/business-management/automations/triggers/the-trigger-payload-schema.md) that has been configured as an [item selection filter](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/automations/triggers/filter-fields.md#item-selection). For example `formId`.  | validation: minLength 1, maxLength 110
              - name: values | type: array<string> | description: Values selected for the filter field.  | validation: maxItems 100
   param name: triggerKey | type: triggerKey | description: Trigger key as defined in your app's trigger configuration in the app dashboard. For example, `form_submitted` or `invoice_due`. | required: true | validation: minLength 1, maxLength 100
 Return type: GetDynamicSchemaResponse
  - name: dynamicSchema | type: object | description: A [JSON schema](https://json-schema.org/) corresponding to the filter selection sent in the request.  

 Possible Errors:
   HTTP Code: 404 | Status Code: NOT_FOUND | Application Code: PROVIDER_NOT_FOUND | Description: Service provider not found.


```

### Examples

### Dynamic schema request sent by Wix
Dynamic schema request with a sample response body

```curl
curl -X POST \
'https://www.<your-deployment-uri>.com/dynamic-schema' \
-H 'user-agent: Wix' \
-H 'accept-encoding: gzip, deflate' \
-H 'content-type: application/json' \
-d '{
  "triggerKey" : "form_submitted",
  "selectedFilterOptions" : [
    {
      "fieldKey" : "form_id",
      "values" : ["1dd34d-gg567"]
    }
  ]
}'
```

---

## JavaScript SDK

### Schema

```
 Method: wixClientAdmin.automations.triggerProvider.getDynamicSchema(request, metadata)
 Description: This endpoint returns a [JSON schema](https://json-schema.org/) object that's used to dynamically update the fields available to a Wix user when they configure an [automation](https://www.wix.com/my-account/site-selector/?buttonText=Select%20Site&title=Select%20a%20Site&autoSelectOnSingleSite=true&actionUrl=https:%2F%2Fwww.wix.com%2Fdashboard%2F%7B%7BmetaSiteId%7D%7D%2Ftriggers/site-automations).  Wix calls this endpoint when a user selects an option from an [item selection filter](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/automations/triggers/filter-fields.md#item-selection) configured for a trigger. Wix appends the returned schema to the [payload schema](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/automations/triggers/payload-schema.md) you defined for the trigger and makes the fields available to the Wix user's automation.
 Method parameters:
   param name: request | type: GetDynamicSchemaRequest    
        - name: triggerKey | type: string | description: Trigger key as defined in your app's trigger configuration in the app dashboard. For example, `form_submitted` or `invoice_due`.  | validation: minLength 1, maxLength 100
        - name: selectedFilterOptions | type: array<SelectedFilterOptions> | description: Current selection state of the trigger's filters.  | validation: maxItems 5
           - name: fieldKey | type: string | description: Key representing a field from the trigger's [payload schema](https://dev.wix.com/docs/rest/business-management/automations/triggers/the-trigger-payload-schema.md) that has been configured as an [item selection filter](https://dev.wix.com/docs/build-apps/develop-your-app/extensions/backend-extensions/automations/triggers/filter-fields.md#item-selection). For example `formId`.  | validation: minLength 1, maxLength 110
           - name: values | type: array<string> | description: Values selected for the filter field.  | validation: maxItems 100
   param name: metadata | type: Context | description: this message is not directly used by any service, it exists to describe the expected parameters that SHOULD be provided to invoked Velo methods as part of open-platform. e.g. SPIs, event-handlers, etc.. NOTE: this context object MUST be provided as the last argument in each Velo method signature.  Example: ```typescript export function wixStores_onOrderCanceled({ event, metadata }: OrderCanceledEvent) { ... } ```  
        - name: requestId | type: string | description: A unique identifier of the request. You may print this GUID to your logs to help with future debugging and easier correlation with Wix's logs.  
        - name: currency | type: string | description: [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) 3-letter currency code.  | validation: format CURRENCY
        - name: identity | type: IdentificationData | description: An object that describes the identity that triggered this request.  
           - ONE-OF: 
              - name: anonymousVisitorId | type: string | description: GUID of a site visitor that has not logged in to the site.  | validation: format GUID
              - name: memberId | type: string | description: GUID of a site visitor that has logged in to the site.  | validation: format GUID
              - name: wixUserId | type: string | description: GUID of a Wix user (site owner, contributor, etc.).  | validation: format GUID
              - name: appId | type: string | description: GUID of an app.  | validation: format GUID
        - name: languages | type: array<string> | description: A string representing a language and region in the format of `"xx-XX"`. First 2 letters represent the language code according to ISO 639-1. This is followed by a dash "-", and then a by 2 capital letters representing the region according to ISO 3166-2. For example, `"en-US"`.  
        - name: instanceId | type: string | description: The service provider app's instance GUID.  | validation: format GUID
 Return type: PROMISE<GetDynamicSchemaResponse>
  - name: dynamicSchema | type: object | description: A [JSON schema](https://json-schema.org/) corresponding to the filter selection sent in the request.  

 Possible Errors:
   HTTP Code: 404 | Status Code: NOT_FOUND | Application Code: PROVIDER_NOT_FOUND | Description: Service provider not found.


```

### Examples

### Self-hosted: Update form based on selected options @description:
```javascript
import { createClient } from '@wix/sdk';
import { triggerProvider } from "@wix/automations/service-plugins";

const wixClient = createClient({
  auth: {
    appId: <YOUR_APP_ID>,
    publicKey: <YOUR_APP_PUBLIC_KEY>
  },
  modules: { triggerProvider }
});

wixClient.triggerProvider.provideHandlers({
  getDynamicSchema: async (payload) => {
    const { request, metadata } = payload;
    // Use the `request` and `metadata` received from Wix and
    // apply custom logic.
    return {
      // Return your response exactly as documented to integrate with Wix.
      // Return value example:
      $schema: "https://json-schema.org/draft/2019-09/schema",
      type: "object",
      title: "Forms dynamic schema example",
      default: {},
      examples: [
        {
          email: "email@email.com",
          message: "I completed your form."
        }
      ],
      properties: {
        email: {
          $id: "#/properties/formId",
          type: "string",
          format: "email",
          title: "Email",
          default: "",
          examples: [
            "email@email.com"
          ]
        },
        message: {
          $id: "#/properties/formName",
          type: "string",
          title: "Message",
          default: "",
          examples: [
            "Hey, nice form!"
          ]
        }
      },
      required: [
        "email",
        "message"
      ],
      additionalProperties: false
    }
  }    
});

// Implement a router to process all requests
express.post('/plugins-and-webhooks/*', (req, res) => {
  wixClient.process(req);
});
```

### getDynamicSchema (self-managed)
Self-managed SDK calls require you to [create a client](https://dev.wix.com/docs/sdk/articles/work-with-the-sdk/about-the-wix-client.md).

```javascript
import { createClient } from '@wix/sdk';
import { triggerProvider } from '@wix/automations/service-plugins';
// Import the auth strategy for the relevant access type
// Import the relevant host module if needed

const myWixClient = createClient ({
  modules: { triggerProvider },
  // Include the auth strategy and host as relevant
});


async function getDynamicSchema(request,metadata) {
  const response = await myWixClient.triggerProvider.getDynamicSchema(request,metadata);
};
```

---