Shopify customer segment rest api

Topic summary

A user is seeking guidance on implementing Shopify customer segment APIs using REST APIs in Node.js. They also want to know how to integrate customer segment GraphQL APIs on the React side.

Current Response:

  • Another user shared their experience creating customer segments using GraphQL API instead of REST
  • Provided a code snippet showing a GraphQL mutation for segment creation
  • The example demonstrates:
    • Creating a segment named “DISCOUNT_APPLIED_SEGMENT”
    • Using a query filter: customers whose tags do NOT contain ‘vip’
    • Executing the mutation with Shopify’s GraphQL connector

Status: The question about REST API implementation remains unanswered. Only a GraphQL-based solution has been provided so far, which may partially address the React integration question but doesn’t cover the Node.js REST API requirement.

Summarized with AI on November 11. AI used: claude-sonnet-4-5-20250929.

Could you please provide insights on how to utilize customer segment APIs with REST APIs and their implementation in Node.js? Additionally, it would be helpful to know how to integrate GraphQL APIs for customer segments on the React side. Thank you.

Hello @Abhishek2941
Recently, I’ve created customer segment usign the GRAPHQL API. Here is code to create a customer segment.

# Define the GraphQL mutation query
mutation_query = <<~QUERY
  mutation segmentCreate($name: String!, $query: String!) {
    segmentCreate(name: $name, query: $query) {
      segment {
        name
      }
      userErrors {
        field
        message
      }
    }
  }
QUERY

# Define the variables for the mutation
variables = {
  "name": "DISCOUNT_APPLIED_SEGMENT",
  "query": "customer_tags NOT CONTAINS 'vip'"
}

# Execute the mutation query
response = shop.with_shopify_session do
  Shopify::Graphql::Connector.client.query(query: mutation_query, variables: variables)
end