Skip to main content
POST
/
v2
/
cohorts
Create cohort
curl --request POST \
  --url 'https://api.permutive.app/cohorts-api/v2/cohorts?k=' \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "Example Segment A",
  "description": "This segment is an example for documentation purposes",
  "query": {
    "event": "Pageview",
    "frequency": {
      "greater_than_or_equal_to": 2
    },
    "where": {
      "property": "properties.client.url",
      "condition": {
        "contains": "football"
      }
    },
    "during": {
      "the_last": {
        "value": 30,
        "unit": "days"
      }
    }
  },
  "tags": [
    "tag_a",
    "tag_b"
  ],
  "segment_type": "real_time"
}
'
import requests

url = "https://api.permutive.app/cohorts-api/v2/cohorts?k="

payload = {
    "name": "Example Segment A",
    "description": "This segment is an example for documentation purposes",
    "query": {
        "event": "Pageview",
        "frequency": { "greater_than_or_equal_to": 2 },
        "where": {
            "property": "properties.client.url",
            "condition": { "contains": "football" }
        },
        "during": { "the_last": {
                "value": 30,
                "unit": "days"
            } }
    },
    "tags": ["tag_a", "tag_b"],
    "segment_type": "real_time"
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    name: 'Example Segment A',
    description: 'This segment is an example for documentation purposes',
    query: {
      event: 'Pageview',
      frequency: {greater_than_or_equal_to: 2},
      where: {property: 'properties.client.url', condition: {contains: 'football'}},
      during: {the_last: {value: 30, unit: 'days'}}
    },
    tags: ['tag_a', 'tag_b'],
    segment_type: 'real_time'
  })
};

fetch('https://api.permutive.app/cohorts-api/v2/cohorts?k=', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.permutive.app/cohorts-api/v2/cohorts?k=",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'name' => 'Example Segment A',
    'description' => 'This segment is an example for documentation purposes',
    'query' => [
        'event' => 'Pageview',
        'frequency' => [
                'greater_than_or_equal_to' => 2
        ],
        'where' => [
                'property' => 'properties.client.url',
                'condition' => [
                                'contains' => 'football'
                ]
        ],
        'during' => [
                'the_last' => [
                                'value' => 30,
                                'unit' => 'days'
                ]
        ]
    ],
    'tags' => [
        'tag_a',
        'tag_b'
    ],
    'segment_type' => 'real_time'
  ]),
  CURLOPT_HTTPHEADER => [
    "Content-Type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.permutive.app/cohorts-api/v2/cohorts?k="

	payload := strings.NewReader("{\n  \"name\": \"Example Segment A\",\n  \"description\": \"This segment is an example for documentation purposes\",\n  \"query\": {\n    \"event\": \"Pageview\",\n    \"frequency\": {\n      \"greater_than_or_equal_to\": 2\n    },\n    \"where\": {\n      \"property\": \"properties.client.url\",\n      \"condition\": {\n        \"contains\": \"football\"\n      }\n    },\n    \"during\": {\n      \"the_last\": {\n        \"value\": 30,\n        \"unit\": \"days\"\n      }\n    }\n  },\n  \"tags\": [\n    \"tag_a\",\n    \"tag_b\"\n  ],\n  \"segment_type\": \"real_time\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.permutive.app/cohorts-api/v2/cohorts?k=")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"Example Segment A\",\n  \"description\": \"This segment is an example for documentation purposes\",\n  \"query\": {\n    \"event\": \"Pageview\",\n    \"frequency\": {\n      \"greater_than_or_equal_to\": 2\n    },\n    \"where\": {\n      \"property\": \"properties.client.url\",\n      \"condition\": {\n        \"contains\": \"football\"\n      }\n    },\n    \"during\": {\n      \"the_last\": {\n        \"value\": 30,\n        \"unit\": \"days\"\n      }\n    }\n  },\n  \"tags\": [\n    \"tag_a\",\n    \"tag_b\"\n  ],\n  \"segment_type\": \"real_time\"\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://api.permutive.app/cohorts-api/v2/cohorts?k=")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"Example Segment A\",\n  \"description\": \"This segment is an example for documentation purposes\",\n  \"query\": {\n    \"event\": \"Pageview\",\n    \"frequency\": {\n      \"greater_than_or_equal_to\": 2\n    },\n    \"where\": {\n      \"property\": \"properties.client.url\",\n      \"condition\": {\n        \"contains\": \"football\"\n      }\n    },\n    \"during\": {\n      \"the_last\": {\n        \"value\": 30,\n        \"unit\": \"days\"\n      }\n    }\n  },\n  \"tags\": [\n    \"tag_a\",\n    \"tag_b\"\n  ],\n  \"segment_type\": \"real_time\"\n}"

response = http.request(request)
puts response.read_body
{
  "id": "38470a62-9837-4c86-bbf3-45dd6d52dd83",
  "code": 12345,
  "name": "Example Segment A",
  "description": "This segment is an example for documentation purposes",
  "query": {
    "event": "Pageview",
    "frequency": {
      "greater_than_or_equal_to": 2
    },
    "where": {
      "property": "properties.client.url",
      "condition": {
        "contains": "football"
      }
    },
    "during": {
      "the_last": {
        "value": 30,
        "unit": "days"
      }
    }
  },
  "tags": [
    "tag_a",
    "tag_b"
  ],
  "state": "Enabled",
  "segment_type": "real_time",
  "created_at": "2022-09-22T15:44:29.518935935Z",
  "last_updated_at": "2022-09-22T15:44:29.518937018Z"
}
{
  "request_id": "b887517b-99a2-4ae0-bc32-93d1fb13d1b7",
  "error": {
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
    "status_code": 400,
    "status": "Bad Request",
    "code": 1002,
    "message": "The provided request body was not structured as expected.",
    "docs": "https://developer.permutive.com/reference#errors"
  }
}
{
  "request_id": "b887517b-99a2-4ae0-bc32-93d1fb13d1b7",
  "error": {
    "type": "https://tools.ietf.org/html/rfc7235#section-3.1",
    "status_code": 401,
    "status": "Unauthorized",
    "code": 2005,
    "message": "The supplied authentication is invalid.",
    "docs": "https://developer.permutive.com/reference#errors"
  }
}
{
  "request_id": "b887517b-99a2-4ae0-bc32-93d1fb13d1b7",
  "error": {
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.3",
    "status_code": 403,
    "status": "Forbidden",
    "code": 2001,
    "message": "The API key provided does not provide access to the request operation or resource.",
    "docs": "https://developer.permutive.com/reference#errors"
  }
}
{
  "request_id": "b887517b-99a2-4ae0-bc32-93d1fb13d1b7",
  "error": {
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.4",
    "status_code": 404,
    "status": "Not Found",
    "code": 3000,
    "message": "The requested resource does not exist.",
    "docs": "https://developer.permutive.com/reference#errors"
  }
}
{
  "request_id": "b887517b-99a2-4ae0-bc32-93d1fb13d1b7",
  "error": {
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.8",
    "status_code": 409,
    "status": "Conflict",
    "code": 4000,
    "message": "A resource with this identifier already exists.",
    "docs": "https://developer.permutive.com/reference#errors"
  }
}
{
  "request_id": "b887517b-99a2-4ae0-bc32-93d1fb13d1b7",
  "error": {
    "type": "https://tools.ietf.org/html/rfc7231#section-6.6.1",
    "status_code": 500,
    "status": "Internal Server Error",
    "code": 5000,
    "message": "An error of unspecified nature was encountered while processing your request. Feel free to get in touch with us at support@permutive.com referencing the Request ID.",
    "docs": "https://developer.permutive.com/reference#errors"
  }
}

Authorizations

k
string
query
required

Body

application/json
name
string
required
query
any
required
description
string
tags
string[]
segmentType
object

Response

Cohort in full (including query)

id
string
required
code
integer
required
name
string
required
query
any
required
state
enum<string>
required
Available options:
Enabled,
Disabled
segmentType
object
required
createdAt
string<date-time>
required
lastUpdatedAt
string<date-time>
required
description
string
tags
string[]
workspaceId
string