Skip to main content

Migrate saved searches to customer segments

In API version 2022-04, we introduced the 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 and discounts 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 object. If your app uses saved searches, then you need to migrate your app to support segments.



Anchor to Step 1: Determine if your app is affectedStep 1: Determine if your app is affected

Your app is affected if it uses any deprecated GraphQL Admin API types and fields.

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:

POST https://{shop}.myshopify.com/api/{api_version}/graphql.json

GraphQL query

{
customerSavedSearches(first: 250) {
edges {
node {
id
}
}
}
}

JSON response

{
"data": {
"customerSavedSearches": {
"edges": [
{
"node": {
"id": "gid:\/\/shopify\/SavedSearch\/1126907871254"
}
},
{
"node": {
"id": "gid:\/\/shopify\/SavedSearch\/1126907904022"
}
},
{
"node": {
"id": "gid:\/\/shopify\/SavedSearch\/1126907936790"
}
},
{
"node": {
"id": "gid:\/\/shopify\/SavedSearch\/1126907969558"
}
}
]
}
}
}

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.

The following types were removed from the GraphQL Admin API:

The following fields were removed from the GraphQL Admin API:

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 to filter out customers based on specific attributes.

The following mutations enable you to create or modify the following discount codes:


Anchor to Step 2: Determine whether you have unmigratable saved searchesStep 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:


Anchor to Step 3: Retrieve segment migrationsStep 3: Retrieve segment migrations

To determine which saved search corresponds to which segment, you can query 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:

POST https://{shop}.myshopify.com/api/{api_version}/graphql.json

GraphQL query

query {
segmentMigrations(first: 3) {
edges {
cursor
node {
savedSearchId
segmentId
}
}
pageInfo {
hasNextPage
hasPreviousPage
}
}
}

JSON response

{
"data": {
"segmentMigrations": {
"edges": [
{
"cursor": "SEGMENT_CURSOR",
"node": {
"savedSearchId": 1,
"segmentId": 1
}
},
{
"cursor": "SEGMENT_CURSOR",
"node": {
"savedSearchId": 2,
"segmentId": 2
}
},
{
"cursor": "SEGMENT_CURSOR",
"node": {
"savedSearchId": 3,
"segmentId": 3
}
}
],
"pageInfo": {
"hasNextPage": false,
"hasPreviousPage": false
}
}
}
}

Anchor to Step 4: Update your app to support segmentsStep 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 guide.



Was this page helpful?