Adding and removing people from a segment

A segment is a group of people. You can manually control which people you add or remove from the group. You can also use entry and exit rules to automatically add people who comply with the entry rules or remove people based on the exit rules.

You can add or remove people from a segment manually or automatically.

To add or remove people from a segment automatically using our API, follow the examples below. If your language does not appear in the examples, don't worry, you just need to send an HTTP POST request as shown in this section.

To add and remove people from a segment using PHP (using Composer):

  1. Install the library running the following command:
    $ composer require convertloop/convertloop-php
  2. Instantiate the ConvertLoop\ConvertLoop class passing your credentials:
    $convertloop = new \ConvertLoop\ConvertLoop("your_app_id", "your_api_key", "v1");
    You can find your app_id and api_key in Settings -> Account once you are logged in.
  3. Add a person to one or several segments with the add_to_segments key:
    $convertloop->people()->createOrUpdate(array(
        "email" => "[email protected]",
        "add_to_segments" => array("Segment 1", "Segment 2")
    ));

    You can also remove people from segments with the remove_from_segments key:

    $convertloop->people()->createOrUpdate(array(
        "email" => "[email protected]",
        "remove_from_segments" => array("Segment 1")
    ));

Learn more about the attributes of the create or update function

If you implemented a previous version of ConvertLoop's API using Tags, don't worry: all your Tags have already been automatically converted into Segments, and there is no action required in your code implementation to make them work.

Check out the PHP API Client for more information.

To add and remove people from a segment using Ruby on Rails:

  1. Install the gem in your Gemfile:
    gem 'convertloop', '0.1.2'
  2. Run bundle install from the command line.
  3. Create a file config/initializers/convertloop.rb and paste the following code:
    ConvertLoop.configure(
      app_id: 'your_app_id',
      api_key: 'your_api_key'
    )
    You can find your app_id and api_key in Settings -> Account once you are logged in.
  4. Add a person to one or several segments with the add_to_segments key:
    ConvertLoop.people.create_or_update(
        email: "[email protected]",
        add_to_segments: ["Segment 1", "Segment 2"]
    )

    You can also remove people from segments with the remove_from_segments key:

    ConvertLoop.people.create_or_update(
      email: "[email protected]",
      remove_from_segments: ["Segment 1"]
    )

Learn more about the attributes of the create or update function

If you implemented a previous version of ConvertLoop's API using Tags, don't worry: all your Tags have already been automatically converted into Segments, and there is no action required in your code implementation to make them work.

Check out the Ruby API Client for more information.

To add or remove people from a segment using Ruby (without bundler):

  1. Install the gem from your command line:
    $ gem install convertloop
  2. Configure the ConvertLoop object passing your credentials.
    require 'convertloop'
    ConvertLoop.configure(
      app_id: 'your_app_id',
      api_key: 'your_api_key'
    )
    
    You can find your app_id and api_key in Settings -> Account once you are logged in.
  3. Add a person to one or several segments with the add_to_segments key:
    ConvertLoop.people.create_or_update(
        email: "[email protected]",
        add_to_segments: ["Segment 1", "Segment 2"]
    )

    You can also remove people from segments with the remove_from_segments key:

    ConvertLoop.people.create_or_update(
      email: "[email protected]",
      remove_from_segments: ["Segment 1"]
    )

Learn more about the attributes of the create or update function

If you implemented a previous version of ConvertLoop's API using Tags, don't worry: all your Tags have already been automatically converted into Segments, and there is no action required in your code implementation to make them work.

Check out the Ruby API Client for more information.

To add or remove people from a segment using Node.js:

  1. Install the package from your command line:
    $ npm install convertloop
  2. Configure the ConvertLoop object passing your credentials.
    const Convertloop = require('convertloop')
    const convertloop = new Convertloop({
      app_id: 'your_app_id',
      api_key: 'your_api_key'
    })
    
    You can find your app_id and api_key in Settings -> Account once you are logged in.
  3. Add a person to one or several segments with the add_to_segments key:
    convertloop.people.create_or_update({
        email: "[email protected]",
        add_to_segments: ["Segment 1", "Segment 2"]
    })

    You can also remove people from segments with the remove_from_segments key:

    convertloop.people.create_or_update({
      email: "[email protected]",
      remove_from_segments: ["Segment 1"]
    })

Learn more about the attributes of the create or update function

If you implemented a previous version of ConvertLoop's API using Tags, don't worry: all your Tags have already been automatically converted into Segments, and there is no action required in your code implementation to make them work.

Check out the Node API Client for more information.

To add or remove people from a segment using Java:

  1. Add the dependency in your pom.xml file:
    <dependency>
      <groupId>co.convertloop</groupId>
      <artifactId>convertloop-java</artifactId>
      <version>0.1.0</version>
    </dependency>
    Or add the dependency in your build.gradle file:
    dependencies {
        compile 'co.convertloop:convertloop-java:0.1.0'
    }
  2. Configure the ConvertLoop object passing your credentials:
    Convertloop convertloop = new Convertloop("your_app_id", "your_api_key", "v1");
    You can find your app_id and api_key in Settings -> Account once you are logged in.
  3. Add a person to one or several segments with the add_to_segments key:
    HashMap contact = new HashMap();
    contact.put("email", "[email protected]");
    contact.put("add_to_segments", new String[] {"Segment 1", "Segment 2"});
    convertloop.createOrUpdatePerson(contact);

    You can also remove people from segments with the remove_from_segments key:

    HashMap contact = new HashMap();
    contact.put("email", "[email protected]");
    contact.put("remove_from_segments", new String[] {"Segment 1"});
    convertloop.createOrUpdatePerson(contact);

Learn more about the attributes of the create or update function

If you implemented a previous version of ConvertLoop's API using Tags, don't worry: all your Tags have already been automatically converted into Segments, and there is no action required in your code implementation to make them work.

Check out the Java API Client for more information.

To add or remove a person from a segment using your command line (Linux or Mac) run the following command (replace the highlighted info with your own data):

$ curl -i -u app_id:api_key \
-X POST \
-H "Content-Type: application/json" \
-d '{ "email": "[email protected]", "add_to_segments": ["Segment 1", "Segment 2"] }' \
https://api.convertloop.co/v1/people
You can find your app_id and api_key in Settings -> Account once you are logged in.

Response

After making the request you should receive a JSON response similar to the following:

{
  "pid" : "fe737ab6",
  "user_id": null,
  "email": "[email protected]",
  "name": "",
  "first_seen_at": null,
  "last_seen_at":null,
  "created_at":"2016-12-06T04:48:42.204Z",
  "segments": ["Segment 1", "Segment 2"]
}

Learn more about the attributes of the create or update function

If you implemented a previous version of ConvertLoop's API using Tags, don't worry: all your Tags have already been automatically converted into Segments, and there is no action required in your code implementation to make them work.