Subscription

Subscription Upsert

Upsert a new Subscription. Subscriptions allow you to listen and recieve notification of events inside of Lytics, most common would be listen to users entering/leaving segments to serve as triggers.

When creating subscriptions they have the following fields.

fieldDataTypeDescription
channelstringRequired: What Type of subscription. [kinesis, webhook]
namestringName of this Subscription
descriptionstringLong text description (optional)
segment_ids[]stringList of segment Ids
withbackfillboolShould all members of this segment be included? They will be marked as "entered" segment.

Webhook only fields:

fieldDataTypeDescription
webhook_urlstringRequired for Webhooks, only used on webhooks, url to post to.
headersmap[string]stringOptional map of headers to send with webhook
segmentio_writekeystringOptional api key for sending to segment.io

Kinesis only fields:

fieldDataTypeDescription
regionstringRequired. AWS Region
streamstringRequired. Kinesis stream
role_arnstringAWS IAM Role to use for assume-role (see integrations doc)
identifier_fieldstringOptional. If provided, pull this field from user field and use as shard-key in Kinesis Put.

Create a Webhook Subscription that includes the Segment definition and custom headers (optional)


curl -s -H "Authorization: $LIOKEY" -H "Content-Type: application/json" \
  -XPOST "https://api.lytics.io/api/subscription" -d '
{
    "segmentql": "FILTER AND ( score_momentum > 25, score_quantity > 25 ) ALIAS seg_webhook1",
    "name":"test1",
    "channel" : "webhook",
    "description":"hello world",
    "webhook_url":"https://demo.appspot.com/log",
    "headers": {"Authorization": "dGhpczp0aGF0"}
}
' | jq "."

Create a Webhook subscription with list of SegmentId's (previously created) to listen to.

curl -s -H "Authorization: $LIOKEY" -H "Content-Type: application/json" \
  -XPOST "https://api.lytics.io/api/subscription" -d '
{
    "segment_ids": ["1234abcd","abc345"],
    "channel":"webhook",
    "name":"test2",
    "description":"hello world",
    "webhook_url":"https://demo.appspot.com/log"
}
' | jq "."

Create a Kinesis Subscription


curl -s -H "Authorization: $LIOKEY" -H "Content-Type: application/json" \
  -XPOST "https://api.lytics.io/api/subscription" -d '
{
    "channel":"kinesis",
    "segment_ids": ["1234abcd","abc345"],
    "name":"test2",
    "description":"hello world",
    "stream":"lytics_triggers_stream",
    "region": "us-east-1",
    "identifier_field":"user_id",
    "role_arn":"arn:aws:iam::4444444444444:role/LyticsWriteToKinesis"
}
' | jq "."



post/api/subscription

Request

  • Base URL
    https://api.lytics.io
  • URL
    https://api.lytics.io/api/subscription
  • Auth
    API key in header Authorization

Query parameters

account_idstring

Your Lytics account ID.

Request body

segment_idsstring[]
namestring
channelstring
withbackfillboolean
descriptionstring
webhook_urlstring

Example request

{
  "segment_ids": [
    "1234abcd",
    "abc345"
  ],
  "name": "test2",
  "channel": "webhook",
  "withbackfill": false,
  "description": "hello world",
  "webhook_url": "https://lyticswwwapp.appspot.com/log"
}

Response

OK

Example response

{
  "data": {
    "id": "3573009ab39bbc9614f754c0fafd53d7",
    "segment_ids": [
      "f897270369f977294871f21cc0d826e7"
    ],
    "segmentql": "FILTER AND ( score_momentum > 25, score_quantity > 25 ) ALIAS seg_webhook1",
    "description": "hello world",
    "name": "test1",
    "updated": "2016-06-30T15:33:14.376262062-07:00",
    "created": "2016-06-30T15:33:14.37626196-07:00",
    "user_id": "2916b84ba4fa8b510591fd6e1c2320db",
    "account_id": "testid",
    "workflow": "webhook_triggers"
  }
}

Changes

No recorded changes to this operation across all 1 revision of this API.