Creating a Stream

POST /streams

Before connecting to the Stream endpoint, a customer will need to create a stream. Validic allows a customer to create up to 5 streams (note that this number is the number of streams, not the number of client connections to the stream). Attempting to create more than the allowed number will result in an error. Please note that optional filters need to be assigned when creating a stream. This allows Validic to apply the filters for each client that connects to the created stream’s connect endpoint, ensuring all clients receive a consistent view of the stream.

Request Parameters

NameRequired FieldTypeDescription
namerequiredstringA unique name for the stream.
resource_filteroptionalArrayOptional resource filter that is applied which will only send events if the event resource type is in the provided list.
Supported Values:
intraday
measurement
nutrition
sleep
summary
workout
event_type_filteroptionalArrayOptional SSE filter that is applied which will only send events if the event type is in the provided list.

Supported Values:
data
connection
* rule

Note: poke events are required and will not be filtered even if values are added to this list.
start_dateoptionalstringOptional date filter that is applied which will only send events if the event start time is on or after the provided start date. Format: YYYY-MM-DD

HTTP Response Status

Response CodeDescription
201 (Created)Indicates the request was received and the object was created successfully.
422 (Unprocessable Entity)An error occurred and an error response has been sent with details.

Code Samples

POST /streams?token=6f46db36dd6543d2b82d91698fcd0896 HTTP/1.1
Host: streams.v2.validic.com
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 207a8cd0-dcc8-eaf8-a021-8f874d351543

{
  "name": "meaningful-customer-name",
  "start_date": "2017-07-25",
  "resource_filter": ["summary", "measurement"]
}
curl -X POST \
  'https://streams.v2.validic.com/streams?token=6f46db36dd6543d2b82d91698fcd0896' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: c2ca248f-5f38-ef86-45f8-a58099a6d7a7' \
  -d '{
  "name": "meaningful-customer-name",
  "start_date": "2017-07-25",
  "resource_filter": ["summary", "measurement"]
}'
var client = new RestClient("https://streams.v2.validic.com/streams?token=6f46db36dd6543d2b82d91698fcd0896");
var request = new RestRequest(Method.POST);
request.AddHeader("postman-token", "e2ab9270-a07d-7a96-1c20-e83c24851c7a");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"meaningful-customer-name\",\n  \"start_date\": \"2017-07-25\",\n  \"resource_filter\": [\"summary\", \"measurement\"]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
package main

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

func main() {

	url := "https://streams.v2.validic.com/streams?token=6f46db36dd6543d2b82d91698fcd0896"

	payload := strings.NewReader("{\n  \"name\": \"meaningful-customer-name\",\n  \"start_date\": \"2017-07-25\",\n  \"resource_filter\": [\"summary\", \"measurement\"]\n}")

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

	req.Header.Add("content-type", "application/json")
	req.Header.Add("cache-control", "no-cache")
	req.Header.Add("postman-token", "3ce2efd8-5ef8-d085-bf98-347f7e7ee1c4")

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

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

	fmt.Println(res)
	fmt.Println(string(body))

}
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://streams.v2.validic.com/streams?token=6f46db36dd6543d2b82d91698fcd0896",
  "method": "POST",
  "headers": {
    "content-type": "application/json",
    "cache-control": "no-cache",
    "postman-token": "6286b8f9-d891-a007-f79a-8a1610822dac"
  },
  "processData": false,
  "data": "{\n  \"name\": \"meaningful-customer-name\",\n  \"start_date\": \"2017-07-25\",\n  \"resource_filter\": [\"summary\", \"measurement\"]\n}"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});
<?php

$request = new HttpRequest();
$request->setUrl('https://streams.v2.validic.com/streams');
$request->setMethod(HTTP_METH_POST);

$request->setQueryData(array(
  'token' => '6f46db36dd6543d2b82d91698fcd0896'
));

$request->setHeaders(array(
  'postman-token' => 'ee3c63f5-e200-8e43-d710-23877ad5e373',
  'cache-control' => 'no-cache',
  'content-type' => 'application/json'
));

$request->setBody('{
  "name": "meaningful-customer-name",
  "start_date": "2017-07-25",
  "resource_filter": ["summary", "measurement"]
}');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}
require 'uri'
require 'net/http'

url = URI("https://streams.v2.validic.com/streams?token=6f46db36dd6543d2b82d91698fcd0896")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/json'
request["cache-control"] = 'no-cache'
request["postman-token"] = 'd3e6b88d-54b8-f73f-a90d-327ffc59d424'
request.body = "{\n  \"name\": \"meaningful-customer-name\",\n  \"start_date\": \"2017-07-25\",\n  \"resource_filter\": [\"summary\", \"measurement\"]\n}"

response = http.request(request)
puts response.read_body
import requests

url = "https://streams.v2.validic.com/streams"

querystring = {"token":"6f46db36dd6543d2b82d91698fcd0896"}

payload = "{\n  \"name\": \"meaningful-customer-name\",\n  \"start_date\": \"2017-07-25\",\n  \"resource_filter\": [\"summary\", \"measurement\"]\n}"
headers = {
    'content-type': "application/json",
    'cache-control': "no-cache",
    'postman-token': "6b164ce7-cfbc-c481-eac8-4743bd478886"
    }

response = requests.request("POST", url, data=payload, headers=headers, params=querystring)

print(response.text)

In response, Validic will respond with an "id" which will be used to open a stream. Here is the sample response:

{
    "id": "598372650b11e700018284ab",
    "name": "meaningful-customer-name",
    "resource_filter": [
        "summary",
        "measurement"
    ],
    "start_date": "2017-07-25",
    "group": "stream_598372650b11e700018284ab",
    "members": 0,
    "created_at": "2017-08-03T18:58:45Z",
    "updated_at": "2017-08-03T18:58:45Z"
}

Validic allows a customer to create up to 5 streams (note that this number is the number of streams, not the number of client connections to the stream) and load balance the responses across those additional streams. Again, attempting to create more than the allowed number will result in an error.

📘

Filters

Optional filters need to be assigned at the time the stream is created. This allows Validic to apply the filters for each client that connects to the created stream’s connect endpoint, ensuring all clients receive a consistent view of the stream.

Response Field Descriptions

NameTypeDescription
idstringUnique identifier for the stream.
namestringThe name of the stream provided by the customer.
groupstringValidic name for the stream.
membersintegerThe number of clients currently connected.
start_datestringOnly events with start times on or after this field are sent.
resource_filterarrayOnly events with resource types included in this list are sent.
event_type_filterarrayOnly Server Sent Events with an event type included in this list are sent.
created_atstringThe date and time the resource was created.
updated_atstringThe date and time the resource was updated.

What’s Next