Shopify customer segment rest api

Shopify customer segment rest api

Abhishek2941
Shopify Partner
1 0 0

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.

Reply 1 (1)

hardik355
Shopify Partner
240 22 36

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

 

If helpful then please Like and Accept Solution.
For App Development and Design changes Hire Me.
Skype: live:hardikradadiya355
Thanks