In API version 2022-04, we introduced the [`Segment`](/docs/api/admin-graphql/latest/objects/Segment) object in the GraphQL Admin API, which you can use to filter out specific customers for marketing, analytics, and reporting purposes.
As of API version 2022-04, [saved searches](/docs/apps/build/marketing-analytics/customer-segments/migrate-saved-searches) and [discounts](/docs/api/admin-graphql/latest/unions/Discount) applied to saved searches are deprecated in the GraphQL Admin API. These changes affect all merchants because all stores have built-in, default saved searches.
This guide shows you how to migrate your app from using saved searches to customer segments.
> Caution:
> Segmentation is a breaking change that replaces the GraphQL Admin API [SavedSearch](/docs/api/admin-graphql/latest/objects/savedsearch#top) object. If your app uses saved searches, then you need to migrate your app to support segments.
## Requirements
- Your app can make [authenticated requests](/docs/api/admin-graphql#authentication) to the GraphQL Admin API.
- Your app has the `read_customers` and `write_customers` [access scopes](/docs/api/usage/access-scopes). Learn how to [configure your access scopes using Shopify CLI](/docs/apps/build/cli-for-apps/app-configuration).
## Step 1: Determine if your app is affected
Your app is affected if it uses any deprecated [GraphQL Admin API types and fields](#graphql).
To determine whether your store is using customer saved searches, you can make a request to the GraphQL Admin API. The following example shows how to retrieve the first 250 [customer saved searches](/docs/api/admin-graphql/latest/queries/customerSavedSearches):
### GraphQL
This section describes deprecated GraphQL API types and fields and their replacements, changes to existing GraphQL Admin API types and fields, and recommended mutations for creating and modifying discount codes.
#### Deprecated types
The following types were removed from the [GraphQL Admin API](/docs/api/admin-graphql):
- `DiscountCustomerSavedSearches` object
- `DiscountCustomerSavedSearchesInput` input object
Use the following elements instead:
- [`DiscountCustomerSegments`](/docs/api/admin-graphql/latest/objects/DiscountCustomerSegments) object
- [`DiscountCustomerSegmentsInput`](/docs/api/admin-graphql/latest/input-objects/discountcustomersegmentsinput) input object
#### Deprecated fields
The following fields were removed from the [GraphQL Admin API](/docs/api/admin-graphql):
- `savedSearches` field from the [`PriceRuleCustomerSelection`](/docs/api/admin-graphql/latest/objects/pricerulecustomerselection) object
- `savedSearchesIds` field from the [`PriceRuleCustomerSelectionInput`](/docs/api/admin-graphql/latest/input-objects/pricerulecustomerselectioninput) input object
Use the following fields instead:
- `segments` field from the [`PriceRuleCustomerSelection`](/docs/api/admin-graphql/latest/objects/pricerulecustomerselection) object
- `segmentIds` field from the [`PriceRuleCustomerSelectionInput`](/docs/api/admin-graphql/latest/input-objects/pricerulecustomerselectioninput) input object
#### Recommended mutations for creating and modifying discount codes
You can use the Discounts API to create and update discount codes for all customers or for specific customers. You can specify which customers can use which discount codes by using the [GraphQL Admin API](/docs/apps/build/marketing-analytics/customer-segments/manage) to filter out customers based on specific attributes.
The following mutations enable you to create or modify the following discount codes:
- [`DiscountCodeBxgyCreate`](/docs/api/admin-graphql/latest/mutations/discountcodebxgycreate)
- [`DiscountCodeBxgyUpdate`](/docs/api/admin-graphql/latest/mutations/discountcodebxgyupdate)
- [`DiscountCodeFreeShippingCreate`](/docs/api/admin-graphql/latest/mutations/discountcodefreeshippingcreate)
- [`DiscountCodeFreeShippingUpdate`](/docs/api/admin-graphql/latest/mutations/discountcodefreeshippingupdate)
- [`discountCodeBasicCreate`](/docs/api/admin-graphql/latest/mutations/discountcodebasiccreate)
- [`discountCodeBasicUpdate`](/docs/api/admin-graphql/latest/mutations/discountcodebasicupdate)
## Step 2: Determine whether you have unmigratable saved searches
The following types of saved searches are unmigratable if they create or update price rules or discount codes:
- Free text
- Saved searches that contain more than five filters
Unmigratable saved searches are blocked by the [API validation](/docs/apps/build/marketing-analytics/customer-segments#validation-behavior-of-saved-searches) and return an error. If an API request is blocked, then the price rule or discount code isn't affected.
If a saved search is updated, causing it to match the unmigratable saved search criteria, and that saved search is referenced by a price rule or a discount code, then the API request is blocked, and an error message is returned.
The following mutations are blocked if they use unmigratable saved searches:
- [`discountCodeBasicCreate`](/docs/api/admin-graphql/latest/mutations/discountCodeBasicCreate)
- [`discountCodeBasicUpdate`](/docs/api/admin-graphql/latest/mutations/discountCodeBasicUpdate)
- [`discountCodeBxgyCreate`](/docs/api/admin-graphql/latest/mutations/discountCodeBxgyCreate)
- [`discountCodeBxgyUpdate`](/docs/api/admin-graphql/latest/mutations/discountCodeBxgyUpdate)
- [`discountCodeFreeShippingCreate`](/docs/api/admin-graphql/latest/mutations/discountCodeFreeShippingCreate)
- [`discountCodeFreeShippingUpdate`](/docs/api/admin-graphql/latest/mutations/discountCodeFreeShippingUpdate)
- [`priceRuleCreate`](/docs/api/admin-graphql/latest/mutations/priceRuleCreate)
- [`priceRuleUpdate`](/docs/api/admin-graphql/latest/mutations/priceRuleUpdate)
- [`savedSearchUpdate`](/docs/api/admin-graphql/latest/mutations/savedSearchUpdate)
## Step 3: Retrieve segment migrations
To determine which saved search corresponds to which segment, you can query [`SegmentMigrations`](/docs/api/admin-graphql/latest/queries/segmentMigrations). For example, use the `segmentMigrations` query to retrieve the segment ID that corresponds to a saved search ID.
The following example shows how to retrieve the first three segment migrations:
## Step 4: Update your app to support segments
If you want your app to support segments, then you can change your app to use the queries and mutations that are described in the [Manage customer segments](/docs/apps/build/marketing-analytics/customer-segments/manage) guide.
## Next steps
- Learn how to [manage customer segments](/docs/apps/build/marketing-analytics/customer-segments/manage).