All things Shopify and commerce
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
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