> 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`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Sample Flows

## Article: Sample Flows

## Article Link: https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-design-theme/sample-flows.md

## Article Content:

# Email Design Themes API: Sample Flows

This article presents possible use cases and corresponding sample flows that you can support. It provides a useful starting point as you plan your implementation.

## Let a site owner pick a theme when composing an email

To let a site owner choose how an email looks without restyling it from scratch each time, your app can offer a theme picker backed by the site's saved themes.

Note that applying a theme happens entirely on your side. There's no API that attaches a theme to an email, so your app reads the theme and applies its `body` to the email it's composing.

To offer a theme picker:

1. Call [Query Email Design Themes](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-design-theme/query-email-design-themes.md) with an empty `filter`, sorting by `title` in ascending order, to list the site's themes. Show the returned `title` values in your picker, along with `updatedDate` so the site owner can tell apart themes that share a title.

1. Call Query Email Design Themes again with `cursorPaging.cursor` set to the returned `pagingMetadata.cursors.next`, and repeat until `pagingMetadata.hasNext` is `false`. Each page holds up to 100 themes.

1. When the site owner selects a theme, call [Get Email Design Theme](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-design-theme/get-email-design-theme.md) with its `id` to retrieve its latest `body`.

1. Apply the returned `body` to the email you're composing, and save the composed email with the styling already applied.

    Copy the styling into the email rather than storing the theme `id` and reading it again at send time. This matches how the Wix email editor behaves: a theme is a starting point, so later edits to the theme don't change emails that were already composed.

## Let a site owner edit a theme without losing concurrent changes

Because a theme can be open in more than one place at a time, edits need to be applied against a known version.

To edit a theme safely:

1. Call [Get Email Design Theme](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-design-theme/get-email-design-theme.md) to load the theme the site owner wants to edit. Keep the returned `revision`.

1. When the site owner saves their changes, call [Update Email Design Theme](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-design-theme/update-email-design-theme.md) with the modified fields and the `revision` from step 1.

1. If the call fails with `INVALID_REVISION`, call Get Email Design Theme again to reload the theme, show the site owner what changed, and let them reapply their edit.

    Emails already composed with this theme keep the styling they were composed with. Editing a theme only affects emails composed after the edit.

## Back up a site's themes to an external system

To keep an external copy of a site's themes, export them once in full and then export only what's changed since the last run. A theme's `updatedDate` is set when it's created and changes every time it's updated, so filtering by `updatedDate` picks up both new and edited themes.

To back up a site's themes:

1. For the first export, call [Query Email Design Themes](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-design-theme/query-email-design-themes.md) with an empty `filter`, sorting by `updatedDate` in ascending order.

1. Call Query Email Design Themes again with `cursorPaging.cursor` set to the returned `pagingMetadata.cursors.next`, and repeat until `pagingMetadata.hasNext` is `false`. Each page holds up to 100 themes.

1. Upload the returned themes to your external system, and save the latest `updatedDate` among them.

1. For each subsequent export, call Query Email Design Themes filtered to themes updated since the saved `updatedDate`:

    ```json
    {
      "query": {
        "filter": {
          "updatedDate": {
            "$gt": "<LATEST_EXPORTED_UPDATED_DATE>"
          }
        },
        "sort": [
          {
            "fieldName": "updatedDate",
            "order": "ASC"
          }
        ]
      }
    }
    ```

1. Repeat steps 2 to 4 for each subsequent export.

    To remove deleted themes from your backup, subscribe to the [Email Design Theme Deleted](https://dev.wix.com/docs/api-reference/business-management/marketing/emails/email-design-theme/email-design-theme-deleted.md) domain event.