Documentation / Developer / Lytics APIs

Query

Schema management API to add/edit queries and user-fields.

For a full breakdown of the Lytics Query Language as well as examples on how to use these APIs see the LQL documentation.

Query List

/api/query

Get all current queries.

GET

Query List

/api/query

List of all queries

Response 200

Headers
Content-Type: application/json
Body
{
    "status": "success",
    "data": [
      {
          "alias": "user_custom_query.lql",
          "by_fields": [
            "email"
          ],
          "fields": 
            {
              "email": 
                {
                  "as": "email",
                  "is_by": true,
                  "type": "string",
                  "shortdesc": "Email Address",
                  "longdesc": "A user's email address",
                  "identities": [
                    "email"
                  ]
                }
            },
          "from": "custom_stream",
          "id": "abcdef123",
          "into": "user",
          "keyword": "SELECT",
          "query_type": "SELECT",
          "table": "user",
          "updated": "2014-10-30T21:01:06.493Z",
          "created": "2014-10-30T21:01:06.493Z",
          "text": "SELECT ..."
      }
    ]
}
POST

Query Upsert

/api/query{?version}

Uses ALIAS name inside parsed query for ID, and either creates/updates a query.

CHANGE NOTIFICATION This api in the past has returned a single object but is changing to return an array of query objects (because posted QL text may contain more than one statement). To get the old behavior of single object pass version=old.

# new version, will be default in Sept 2017.
curl -s -XPOST "https://api.lytics.io/api/query?version=new" \
   -H "Authorization: $LIOKEY" \
   --data-binary @your_file.lql

# old version, returns object
curl -s -XPOST "https://api.lytics.io/api/query?version=old" \
   -H "Authorization: $LIOKEY" \
   --data-binary @your_file.lql
Parameters
versionstring (optional)
Ex: old
Use the "new" array based response or "old" object.

Request

Headers
Content-Type: text/plain
Body
SELECT .....
FROM stream_name
BY field_name
ALIAS my_query_name

Response 200

Headers
Content-Type: application/json
Body
{
    "status": "success",
    "data": [
      {
          "alias": "user_custom_query.lql",
          "by_fields": [
            "email"
          ],
          "fields": 
            {
              "email": 
                {
                  "as": "email",
                  "is_by": true,
                  "type": "string",
                  "shortdesc": "Email Address",
                  "longdesc": "A user's email address",
                  "identities": [
                    "email"
                  ]
                }
            },
          "from": "custom_stream",
          "id": "abcdef123",
          "into": "user",
          "keyword": "SELECT",
          "query_type": "SELECT",
          "table": "user",
          "updated": "2014-10-30T21:01:06.493Z",
          "created": "2014-10-30T21:01:06.493Z",
          "text": "SELECT ..."
      }
    ]
}

Query

/api/query/{idOrAlias}

Get a single Query resource.

Parameters
idOrAliasstring (required)
Ex: 1234
query Id OR Alias in path
GET

Query Fetch

/api/query/{idOrAlias}

Get single query by ALIAS OR ID

Response 200

Headers
Content-Type: application/json
Body
{
    "status": "success",
    "data": {
          "id": "abcdef123",
          "updated": "2014-10-30T21:01:06.493Z",
          "created": "2014-10-30T21:01:06.493Z",
          "text": "SELECT ..."
    }
}
DELETE

Query Delete

/api/query/{idOrAlias}

Delete A query by idOrAlias.

Response 204

POST

Query Validation

/api/query/_validate{?version}

Upload a query for syntax validation only.

# validate query syntax
curl -s -XPOST "https://api.lytics.io/api/query/_validate" \
   -H "Authorization: $LIOKEY" \
   -H "Content-Type: text/plain" \
   --data-binary @your_file.lql
Parameters
versionstring (optional)
Ex: old
Use the "new" array based response or "old" object.

Request

Headers
Content-Type: text/plain
Body
SELECT .....
FROM stream_name
BY field_name
ALIAS my_query_name

Response 200

Headers
Content-Type: application/json
Body
{
    "status": "success",
    "data": {
          "id": "abcdef123",
          "updated": "2014-10-30T21:01:06.493Z",
          "created": "2014-10-30T21:01:06.493Z",
          "text": "SELECT ..."
    }
}
POST

Query Test Evaluation

/api/query/_test

Upload a query AND data to see how it will be interpreted.

# add any name/value paris to query string param for data input
# then upload query and get evaluation response
curl -s -XPOST "https://api.lytics.io/api/query/_test?name=value" \
   -H "Authorization: $LIOKEY" \
   -H "Content-Type: text/plain" \
   --data-binary @your_file.lql

Request

Headers
Content-Type: text/plain
Body
    SELECT .....
    FROM stream_name
    BY field_name
    ALIAS my_query_name

Response 200

Headers
Content-Type: application/json
Body
{
    "status": "success",
    "data": {
          "id": "abcdef123",
          "updated": "2014-10-30T21:01:06.493Z",
          "created": "2014-10-30T21:01:06.493Z",
          "text": "SELECT ..."
    }
}