> ## Documentation Index
> Fetch the complete documentation index at: https://docs.useautumn.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Preview Sync Webhooks

> Shows what `webhooks.sync` would do with the same body, without changing anything: which webhooks it would create or update, and which existing ones it would leave alone because the body doesn't list them.

export const DynamicResponseExample = ({json, statusCode = "200"}) => {
  const toCamelCase = str => {
    return str.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
  };
  const convertKeysToCamelCase = obj => {
    if (Array.isArray(obj)) {
      return obj.map(item => convertKeysToCamelCase(item));
    }
    if (obj !== null && typeof obj === "object") {
      return Object.keys(obj).reduce((acc, key) => {
        const camelKey = toCamelCase(key);
        acc[camelKey] = convertKeysToCamelCase(obj[key]);
        return acc;
      }, {});
    }
    return obj;
  };
  const [isTypeScript, setIsTypeScript] = useState(() => {
    if (typeof window !== "undefined") {
      try {
        const lang = localStorage.getItem("code");
        return JSON.parse(lang) === "typescript";
      } catch {
        return true;
      }
    }
    return true;
  });
  useEffect(() => {
    const onMintlifyStorage = event => {
      if (event.detail?.key === "code") {
        try {
          const value = JSON.parse(event.detail.value);
          setIsTypeScript(value === "typescript");
        } catch {}
      }
    };
    const pollInterval = setInterval(() => {
      try {
        const lang = localStorage.getItem("code");
        const value = JSON.parse(lang);
        setIsTypeScript(value === "typescript");
      } catch {}
    }, 300);
    document.addEventListener("mintlify-localstorage", onMintlifyStorage);
    return () => {
      document.removeEventListener("mintlify-localstorage", onMintlifyStorage);
      clearInterval(pollInterval);
    };
  }, []);
  const camelCaseJson = useMemo(() => convertKeysToCamelCase(json), [json]);
  const snakeCaseString = JSON.stringify(json, null, 2);
  const camelCaseString = JSON.stringify(camelCaseJson, null, 2);
  return <ResponseExample>
			{isTypeScript ? <CodeBlock language="json" filename={statusCode}>
					{camelCaseString}
				</CodeBlock> : <CodeBlock language="json" filename={statusCode}>
					{snakeCaseString}
				</CodeBlock>}
		</ResponseExample>;
};

export const DynamicResponseField = ({children, name, ...props}) => {
  const convertToCamelCase = str => {
    if (typeof str !== "string") return str;
    return str.replace(/[_-](\w)/g, (_, c) => c.toUpperCase());
  };
  const [lang, setLang] = useState(() => {
    if (typeof window !== "undefined") {
      const stored = localStorage.getItem("code");
      return stored || '"typescript"';
    }
    return '"typescript"';
  });
  useEffect(() => {
    const onMintlifyStorage = event => {
      const key = event.detail?.key;
      if (key === "code") {
        setLang(event.detail.value);
      }
    };
    const pollInterval = setInterval(() => {
      const current = localStorage.getItem("code");
      if (current && current !== lang) {
        setLang(current);
      }
    }, 500);
    document.addEventListener("mintlify-localstorage", onMintlifyStorage);
    return () => {
      document.removeEventListener("mintlify-localstorage", onMintlifyStorage);
      clearInterval(pollInterval);
    };
  }, [lang]);
  const resolvedName = useMemo(() => {
    try {
      const value = JSON.parse(lang);
      const useCamelCase = value === "typescript";
      return useCamelCase ? convertToCamelCase(name) : name;
    } catch {
      return name;
    }
  }, [name, lang]);
  return <ResponseField name={resolvedName} {...props}>
			{children}
		</ResponseField>;
};

export const DynamicParamField = ({children, body, path, ...props}) => {
  const convertToCamelCase = str => {
    if (typeof str !== "string") return str;
    return str.replace(/[_-](\w)/g, (_, c) => c.toUpperCase());
  };
  const [lang, setLang] = useState(() => {
    if (typeof window !== "undefined") {
      const stored = localStorage.getItem("code");
      return stored || '"typescript"';
    }
    return '"typescript"';
  });
  useEffect(() => {
    const onMintlifyStorage = event => {
      const key = event.detail?.key;
      if (key === "code") {
        setLang(event.detail.value);
      }
    };
    const pollInterval = setInterval(() => {
      const current = localStorage.getItem("code");
      if (current && current !== lang) {
        setLang(current);
      }
    }, 500);
    document.addEventListener("mintlify-localstorage", onMintlifyStorage);
    return () => {
      document.removeEventListener("mintlify-localstorage", onMintlifyStorage);
      clearInterval(pollInterval);
    };
  }, [lang]);
  const resolvedBody = useMemo(() => {
    try {
      const value = JSON.parse(lang);
      const useCamelCase = value === "typescript";
      return useCamelCase ? convertToCamelCase(body) : body;
    } catch {
      return body;
    }
  }, [body, lang]);
  const resolvedPath = useMemo(() => {
    try {
      const value = JSON.parse(lang);
      const useCamelCase = value === "typescript";
      return useCamelCase ? convertToCamelCase(path) : path;
    } catch {
      return path;
    }
  }, [path, lang]);
  return <ParamField body={resolvedBody} path={resolvedPath} {...props}>
			{children}
		</ParamField>;
};

### Body Parameters

<DynamicParamField body="webhooks" type="object[]" required>
  The webhooks to create or update. Webhooks not listed are left alone; nothing is deleted.

  <Expandable title="properties">
    <DynamicParamField body="id" type="string" required>
      Your ID for the webhook: letters, digits, `-` and `_`. It can't be changed after creation.
    </DynamicParamField>

    <DynamicParamField body="url" type="string" required>
      The https URL Autumn sends events to. Localhost and private-network addresses are rejected; tunnels such as ngrok work.
    </DynamicParamField>

    <DynamicParamField body="events" type="('customer.products.updated' | 'customer.threshold_reached' | 'balances.usage_alert_triggered' | 'balances.limit_reached' | 'billing.auto_topup_failed' | 'billing.auto_topup_succeeded' | 'billing.updated' | 'invoice.finalized' | 'vercel.resources.deleted' | 'vercel.resources.provisioned' | 'vercel.resources.rotate_secrets' | 'vercel.webhooks.event')[]" required>
      The events sent to this webhook. At least one. `vercel.*` events can't be mixed with other events.
    </DynamicParamField>

    <DynamicParamField body="description" type="string">
      A note for your own reference.
    </DynamicParamField>

    <DynamicParamField body="disabled" type="boolean">
      When true, no events are sent to the webhook.
    </DynamicParamField>
  </Expandable>
</DynamicParamField>

### Response

<DynamicResponseField name="changes" type="object | object | object | object[]">
  What `webhooks.sync` would do. `adopt` takes over a webhook made in the dashboard with the same URL, keeping its signing secret. `unmanaged` webhooks exist but aren't listed, so sync leaves them alone.

  <Expandable title="properties">
    <DynamicResponseField name="action" type="any" />

    <DynamicResponseField name="id" type="string" />

    <DynamicResponseField name="webhook" type="object">
      <Expandable title="properties">
        <DynamicResponseField name="id" type="string">
          The webhook's ID. Webhooks made in the dashboard show their `ep_…` ID.
        </DynamicResponseField>

        <DynamicResponseField name="url" type="string">
          The URL Autumn sends events to.
        </DynamicResponseField>

        <DynamicResponseField name="description" type="string | null">
          A note for your own reference.
        </DynamicResponseField>

        <DynamicResponseField name="events" type="string[]">
          The events sent to this webhook, as `WebhookEventType` names; a type newer than your client is returned as-is. Empty only for a webhook made in the dashboard that receives every event.
        </DynamicResponseField>

        <DynamicResponseField name="disabled" type="boolean">
          When true, no events are sent to the webhook.
        </DynamicResponseField>

        <DynamicResponseField name="created_at" type="number">
          When the webhook was created, ms since epoch.
        </DynamicResponseField>

        <DynamicResponseField name="updated_at" type="number">
          When the webhook was last changed, ms since epoch.
        </DynamicResponseField>
      </Expandable>
    </DynamicResponseField>

    <DynamicResponseField name="before" type="object">
      <Expandable title="properties">
        <DynamicResponseField name="id" type="string">
          The webhook's ID. Webhooks made in the dashboard show their `ep_…` ID.
        </DynamicResponseField>

        <DynamicResponseField name="url" type="string">
          The URL Autumn sends events to.
        </DynamicResponseField>

        <DynamicResponseField name="description" type="string | null">
          A note for your own reference.
        </DynamicResponseField>

        <DynamicResponseField name="events" type="string[]">
          The events sent to this webhook, as `WebhookEventType` names; a type newer than your client is returned as-is. Empty only for a webhook made in the dashboard that receives every event.
        </DynamicResponseField>

        <DynamicResponseField name="disabled" type="boolean">
          When true, no events are sent to the webhook.
        </DynamicResponseField>

        <DynamicResponseField name="created_at" type="number">
          When the webhook was created, ms since epoch.
        </DynamicResponseField>

        <DynamicResponseField name="updated_at" type="number">
          When the webhook was last changed, ms since epoch.
        </DynamicResponseField>
      </Expandable>
    </DynamicResponseField>

    <DynamicResponseField name="after" type="object">
      <Expandable title="properties">
        <DynamicResponseField name="id" type="string">
          The webhook's ID. Webhooks made in the dashboard show their `ep_…` ID.
        </DynamicResponseField>

        <DynamicResponseField name="url" type="string">
          The URL Autumn sends events to.
        </DynamicResponseField>

        <DynamicResponseField name="description" type="string | null">
          A note for your own reference.
        </DynamicResponseField>

        <DynamicResponseField name="events" type="string[]">
          The events sent to this webhook, as `WebhookEventType` names; a type newer than your client is returned as-is. Empty only for a webhook made in the dashboard that receives every event.
        </DynamicResponseField>

        <DynamicResponseField name="disabled" type="boolean">
          When true, no events are sent to the webhook.
        </DynamicResponseField>

        <DynamicResponseField name="created_at" type="number">
          When the webhook was created, ms since epoch.
        </DynamicResponseField>

        <DynamicResponseField name="updated_at" type="number">
          When the webhook was last changed, ms since epoch.
        </DynamicResponseField>
      </Expandable>
    </DynamicResponseField>
  </Expandable>
</DynamicResponseField>

<DynamicResponseField name="errors" type="object[]">
  Listed webhooks `webhooks.sync` would refuse, e.g. when several dashboard webhooks share the URL.

  <Expandable title="properties">
    <DynamicResponseField name="id" type="string" />

    <DynamicResponseField name="message" type="string" />
  </Expandable>
</DynamicResponseField>

<ResponseExample>
  ```json 200 theme={null}
  {
    "changes": [
      {
        "action": "create",
        "id": "billing",
        "webhook": {
          "id": "billing",
          "url": "https://example.com/webhooks/autumn",
          "events": [
            "billing.updated",
            "invoice.finalized"
          ],
          "description": "Plan changes and invoices",
          "disabled": false,
          "created_at": 1781113864000,
          "updated_at": 1781113864000
        }
      }
    ],
    "errors": []
  }
  ```
</ResponseExample>


## OpenAPI

````yaml openapi POST /v1/webhooks.preview_sync
openapi: 3.1.0
info:
  title: Autumn API
  version: 2.4.0
servers:
  - url: https://api.useautumn.com
    description: Production server
security:
  - secretKey: []
paths:
  /v1/webhooks.preview_sync:
    post:
      tags:
        - webhooks
      description: >-
        Shows what `webhooks.sync` would do with the same body, without changing
        anything: which webhooks it would create or update, and which existing
        ones it would leave alone because the body doesn't list them.
      operationId: previewSyncWebhooks
      parameters:
        - name: x-api-version
          in: header
          required: true
          schema:
            type: string
            default: 2.4.0
          x-speakeasy-globals-hidden: true
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                webhooks:
                  type: array
                  items:
                    type: object
                    properties:
                      id:
                        type: string
                        minLength: 1
                        maxLength: 256
                        pattern: ^[a-zA-Z0-9_-]+$
                        description: >-
                          Your ID for the webhook: letters, digits, `-` and `_`.
                          It can't be changed after creation.
                      url:
                        type: string
                        pattern: ^[Hh][Tt][Tt][Pp][Ss]:\/\/
                        description: >-
                          The https URL Autumn sends events to. Localhost and
                          private-network addresses are rejected; tunnels such
                          as ngrok work.
                      events:
                        type: array
                        minItems: 1
                        items:
                          enum:
                            - customer.products.updated
                            - customer.threshold_reached
                            - balances.usage_alert_triggered
                            - balances.limit_reached
                            - billing.auto_topup_failed
                            - billing.auto_topup_succeeded
                            - billing.updated
                            - invoice.finalized
                            - vercel.resources.deleted
                            - vercel.resources.provisioned
                            - vercel.resources.rotate_secrets
                            - vercel.webhooks.event
                          type: string
                          description: An event type the webhook receives.
                        description: >-
                          The events sent to this webhook. At least one.
                          `vercel.*` events can't be mixed with other events.
                      description:
                        type: string
                        description: A note for your own reference.
                      disabled:
                        type: boolean
                        description: When true, no events are sent to the webhook.
                    required:
                      - id
                      - url
                      - events
                  description: >-
                    The webhooks to create or update. Webhooks not listed are
                    left alone; nothing is deleted.
              required:
                - webhooks
              title: SyncWebhooksParams
              examples:
                - webhooks:
                    - id: billing
                      url: https://example.com/webhooks/autumn
                      events:
                        - billing.updated
                        - invoice.finalized
                      description: Plan changes and invoices
            example:
              webhooks:
                - id: billing
                  url: https://example.com/webhooks/autumn
                  events:
                    - billing.updated
                    - invoice.finalized
                  description: Plan changes and invoices
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  changes:
                    type: array
                    items:
                      anyOf:
                        - type: object
                          properties:
                            action:
                              const: create
                            id:
                              type: string
                            webhook:
                              type: object
                              properties:
                                id:
                                  type: string
                                  description: >-
                                    The webhook's ID. Webhooks made in the
                                    dashboard show their `ep_…` ID.
                                url:
                                  type: string
                                  description: The URL Autumn sends events to.
                                description:
                                  anyOf:
                                    - type: string
                                    - type: 'null'
                                  description: A note for your own reference.
                                events:
                                  type: array
                                  items:
                                    type: string
                                  description: >-
                                    The events sent to this webhook, as
                                    `WebhookEventType` names; a type newer than
                                    your client is returned as-is. Empty only
                                    for a webhook made in the dashboard that
                                    receives every event.
                                disabled:
                                  type: boolean
                                  description: >-
                                    When true, no events are sent to the
                                    webhook.
                                created_at:
                                  type: number
                                  description: >-
                                    When the webhook was created, ms since
                                    epoch.
                                updated_at:
                                  type: number
                                  description: >-
                                    When the webhook was last changed, ms since
                                    epoch.
                              required:
                                - id
                                - url
                                - description
                                - events
                                - disabled
                                - created_at
                                - updated_at
                          required:
                            - action
                            - id
                            - webhook
                        - type: object
                          properties:
                            action:
                              const: update
                            id:
                              type: string
                            before:
                              type: object
                              properties:
                                id:
                                  type: string
                                  description: >-
                                    The webhook's ID. Webhooks made in the
                                    dashboard show their `ep_…` ID.
                                url:
                                  type: string
                                  description: The URL Autumn sends events to.
                                description:
                                  anyOf:
                                    - type: string
                                    - type: 'null'
                                  description: A note for your own reference.
                                events:
                                  type: array
                                  items:
                                    type: string
                                  description: >-
                                    The events sent to this webhook, as
                                    `WebhookEventType` names; a type newer than
                                    your client is returned as-is. Empty only
                                    for a webhook made in the dashboard that
                                    receives every event.
                                disabled:
                                  type: boolean
                                  description: >-
                                    When true, no events are sent to the
                                    webhook.
                                created_at:
                                  type: number
                                  description: >-
                                    When the webhook was created, ms since
                                    epoch.
                                updated_at:
                                  type: number
                                  description: >-
                                    When the webhook was last changed, ms since
                                    epoch.
                              required:
                                - id
                                - url
                                - description
                                - events
                                - disabled
                                - created_at
                                - updated_at
                            after:
                              type: object
                              properties:
                                id:
                                  type: string
                                  description: >-
                                    The webhook's ID. Webhooks made in the
                                    dashboard show their `ep_…` ID.
                                url:
                                  type: string
                                  description: The URL Autumn sends events to.
                                description:
                                  anyOf:
                                    - type: string
                                    - type: 'null'
                                  description: A note for your own reference.
                                events:
                                  type: array
                                  items:
                                    type: string
                                  description: >-
                                    The events sent to this webhook, as
                                    `WebhookEventType` names; a type newer than
                                    your client is returned as-is. Empty only
                                    for a webhook made in the dashboard that
                                    receives every event.
                                disabled:
                                  type: boolean
                                  description: >-
                                    When true, no events are sent to the
                                    webhook.
                                created_at:
                                  type: number
                                  description: >-
                                    When the webhook was created, ms since
                                    epoch.
                                updated_at:
                                  type: number
                                  description: >-
                                    When the webhook was last changed, ms since
                                    epoch.
                              required:
                                - id
                                - url
                                - description
                                - events
                                - disabled
                                - created_at
                                - updated_at
                          required:
                            - action
                            - id
                            - before
                            - after
                        - type: object
                          properties:
                            action:
                              const: adopt
                            id:
                              type: string
                            before:
                              type: object
                              properties:
                                id:
                                  type: string
                                  description: >-
                                    The webhook's ID. Webhooks made in the
                                    dashboard show their `ep_…` ID.
                                url:
                                  type: string
                                  description: The URL Autumn sends events to.
                                description:
                                  anyOf:
                                    - type: string
                                    - type: 'null'
                                  description: A note for your own reference.
                                events:
                                  type: array
                                  items:
                                    type: string
                                  description: >-
                                    The events sent to this webhook, as
                                    `WebhookEventType` names; a type newer than
                                    your client is returned as-is. Empty only
                                    for a webhook made in the dashboard that
                                    receives every event.
                                disabled:
                                  type: boolean
                                  description: >-
                                    When true, no events are sent to the
                                    webhook.
                                created_at:
                                  type: number
                                  description: >-
                                    When the webhook was created, ms since
                                    epoch.
                                updated_at:
                                  type: number
                                  description: >-
                                    When the webhook was last changed, ms since
                                    epoch.
                              required:
                                - id
                                - url
                                - description
                                - events
                                - disabled
                                - created_at
                                - updated_at
                            after:
                              type: object
                              properties:
                                id:
                                  type: string
                                  description: >-
                                    The webhook's ID. Webhooks made in the
                                    dashboard show their `ep_…` ID.
                                url:
                                  type: string
                                  description: The URL Autumn sends events to.
                                description:
                                  anyOf:
                                    - type: string
                                    - type: 'null'
                                  description: A note for your own reference.
                                events:
                                  type: array
                                  items:
                                    type: string
                                  description: >-
                                    The events sent to this webhook, as
                                    `WebhookEventType` names; a type newer than
                                    your client is returned as-is. Empty only
                                    for a webhook made in the dashboard that
                                    receives every event.
                                disabled:
                                  type: boolean
                                  description: >-
                                    When true, no events are sent to the
                                    webhook.
                                created_at:
                                  type: number
                                  description: >-
                                    When the webhook was created, ms since
                                    epoch.
                                updated_at:
                                  type: number
                                  description: >-
                                    When the webhook was last changed, ms since
                                    epoch.
                              required:
                                - id
                                - url
                                - description
                                - events
                                - disabled
                                - created_at
                                - updated_at
                          required:
                            - action
                            - id
                            - before
                            - after
                        - type: object
                          properties:
                            action:
                              const: unmanaged
                            id:
                              type: string
                            webhook:
                              type: object
                              properties:
                                id:
                                  type: string
                                  description: >-
                                    The webhook's ID. Webhooks made in the
                                    dashboard show their `ep_…` ID.
                                url:
                                  type: string
                                  description: The URL Autumn sends events to.
                                description:
                                  anyOf:
                                    - type: string
                                    - type: 'null'
                                  description: A note for your own reference.
                                events:
                                  type: array
                                  items:
                                    type: string
                                  description: >-
                                    The events sent to this webhook, as
                                    `WebhookEventType` names; a type newer than
                                    your client is returned as-is. Empty only
                                    for a webhook made in the dashboard that
                                    receives every event.
                                disabled:
                                  type: boolean
                                  description: >-
                                    When true, no events are sent to the
                                    webhook.
                                created_at:
                                  type: number
                                  description: >-
                                    When the webhook was created, ms since
                                    epoch.
                                updated_at:
                                  type: number
                                  description: >-
                                    When the webhook was last changed, ms since
                                    epoch.
                              required:
                                - id
                                - url
                                - description
                                - events
                                - disabled
                                - created_at
                                - updated_at
                          required:
                            - action
                            - id
                            - webhook
                    description: >-
                      What `webhooks.sync` would do. `adopt` takes over a
                      webhook made in the dashboard with the same URL, keeping
                      its signing secret. `unmanaged` webhooks exist but aren't
                      listed, so sync leaves them alone.
                  errors:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        message:
                          type: string
                      required:
                        - id
                        - message
                    description: >-
                      Listed webhooks `webhooks.sync` would refuse, e.g. when
                      several dashboard webhooks share the URL.
                required:
                  - changes
                  - errors
                title: PreviewSyncWebhooksResponse
                examples:
                  - changes:
                      - action: create
                        id: billing
                        webhook:
                          id: billing
                          url: https://example.com/webhooks/autumn
                          events:
                            - billing.updated
                            - invoice.finalized
                          description: Plan changes and invoices
                          disabled: false
                          created_at: 1781113864000
                          updated_at: 1781113864000
                    errors: []
              example:
                changes:
                  - action: create
                    id: billing
                    webhook:
                      id: billing
                      url: https://example.com/webhooks/autumn
                      events:
                        - billing.updated
                        - invoice.finalized
                      description: Plan changes and invoices
                      disabled: false
                      created_at: 1781113864000
                      updated_at: 1781113864000
                errors: []
      x-codeSamples:
        - lang: typescript
          label: Typescript (SDK)
          source: |-
            import { Autumn } from 'autumn-js'

            const autumn = new Autumn()

            const result = await autumn.webhooks.previewSync({
              webhooks: [
                {
                  id: "billing",
                  url: "https://example.com/webhooks/autumn",
                  events: [
                    "billing.updated",
                    "invoice.finalized",
                  ],
                  description: "Plan changes and invoices",
                },
              ],
            });
        - lang: python
          label: Python (SDK)
          source: |-
            from autumn_sdk import Autumn

            autumn = Autumn(secret_key="am_sk_test...")

            res = autumn.webhooks.preview_sync(
                webhooks=[
                    {
                        "id": "billing",
                        "url": "https://example.com/webhooks/autumn",
                        "events": [
                            "billing.updated",
                            "invoice.finalized",
                        ],
                        "description": "Plan changes and invoices",
                    },
                ],
            )
components:
  securitySchemes:
    secretKey:
      type: http
      scheme: bearer
      bearerFormat: JWT

````