Analytics

Definitions

A Definition in Mode is a saved SELECT statement that can be referenced in other SQL queries. Definitions let you write business logic in one place and reference that logic in multiple Mode reports across your organization.

You can use this resource to create, manage, update, or delete Definitions. Or, use this resource to get a list of all Definitions in your Mode organization.

Definition object

Properties

id

required

string

token

required

string

name

required

string

description

required

string

source

required

string

data_source_id

required

string

created_at

required

string

updated_at

required

string

last_successful_sync_at

required

string

github_link

string

last_saved_at

required

string

_links

required

object

All resource responses contain a set of links that describe other related resources or actions that you can take on this resource. A link is comprised of two main pieces: its name (which describes its relationship to this resource) and its href (the URL of the related action or resource). All resources have at least a _self link which is the URL that will return a representation of this resource.

  • creator
  • last_run
  • last_successful_github_sync
  • self
  • web_edit
  "id": 37,
  "token": "5a4177a2902c",
  "name": "Ex",
  "description": "pariatur in laboris",
  "source": "eu",
  "data_source_id": 365,
  "created_at": "YYYY-MM-DDTHH:MM:SS.msZ",
  "updated_at": "YYYY-MM-DDTHH:MM:SS.msZ",
  "last_successful_sync_at": "YYYY-MM-DDTHH:MM:SS.msZ",
  "last_saved_at": "YYYY-MM-DDTHH:MM:SS.msZ",
  "github_link": "pariatur ullamco velit ex aliqua",
  {
    "_links": {
      "self": {
        "href": "ut quis dolor et enim",
        "templated": false
      },
      "last_run": {
        "href": "laborum occaecat",
        "templated": false
      },
      "last_successful_github_sync": {
        "href": "id ea",
        "templated": false
      },
      "web_edit": {
        "href": "eiusmod Duis nisi sunt",
        "templated": false
      },
      "creator": {
        "href": "elit adipisicing nisi",
        "templated": false
      }
    },
  "_embedded": {}
}

Get a definition

To retrieve information about a single Definition, send a GET request including the definition token to the definitions resource.

URL Params

organization

required
string Organization username

definition

required
string Definition token
Responses

200

Definition response

401

Unauthorized

404

Definition not found

GET /{organization}/definitions/{definition}

curl --include \
     --header "Content-Type: application/json" \
     --header "Accept: application/hal+json" \
  'https://modeanalytics.com/api/{organization}/definitions/{definition}'
require 'http'

username = 'you_api_key'
password = 'you_api_secret'

headers = {
  content_type: 'application/json',
  accept: 'application/hal+json'
}

response = HTTP.basic_auth(user: username, pass: password)
               .headers(headers)
               .get('https://modeanalytics.com/api/{organization}/definitions/{definition}')
puts response
from urllib2 import Request, urlopen

headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/hal+json'
}
request = Request('https://modeanalytics.com/api/{organization}/definitions/{definition}', headers=headers)

response_body = urlopen(request).read()
print(response_body)
var request = require('request');

request({
  method: 'GET',
  url: 'https://modeanalytics.com/api/{organization}/definitions/{definition}',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/hal+json'
  }}, function (error, response, body) {
  console.log('Status:', response.statusCode);
  console.log('Headers:', JSON.stringify(response.headers));
  console.log('Response:', body);
});

List definitions

To return a list of all Definitions for a given Organization, send a GET request to the definitions resource.

URL Params

organization

required
string Organization username
Responses

200

Definitions collection response

401

Unauthorized

404

No default Library found

GET /{organization}/definitions

curl --include \
     --header "Content-Type: application/json" \
     --header "Accept: application/hal+json" \
  'https://modeanalytics.com/api/{organization}/definitions?filter=&tokens='
require 'http'

username = 'you_api_key'
password = 'you_api_secret'

headers = {
  content_type: 'application/json',
  accept: 'application/hal+json'
}

response = HTTP.basic_auth(user: username, pass: password)
               .headers(headers)
               .get('https://modeanalytics.com/api/{organization}/definitions?filter=&tokens=')
puts response
from urllib2 import Request, urlopen

headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/hal+json'
}
request = Request('https://modeanalytics.com/api/{organization}/definitions?filter=&tokens=', headers=headers)

response_body = urlopen(request).read()
print(response_body)
var request = require('request');

request({
  method: 'GET',
  url: 'https://modeanalytics.com/api/{organization}/definitions?filter=&tokens=',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/hal+json'
  }}, function (error, response, body) {
  console.log('Status:', response.statusCode);
  console.log('Headers:', JSON.stringify(response.headers));
  console.log('Response:', body);
});

Create a definition

To create a new Definition, send a POST request to the definitions resource.

URL Params

organization

required
string Organization username
Responses

200

Definition response

400

Bad request

401

Unauthorized

404

DataSource not found

POST /{organization}/definitions

curl --include \
     --request POST \
     --header "Content-Type: application/json" \
     --header "Accept: application/hal+json" \
  'https://modeanalytics.com/api/{organization}/definitions'
require 'http'

username = 'you_api_key'
password = 'you_api_secret'

headers = {
  content_type: 'application/json',
  accept: 'application/hal+json'
}

response = HTTP.basic_auth(user: username, pass: password)
               .headers(headers)
               .post('https://modeanalytics.com/api/{organization}/definitions')
puts response
from urllib2 import Request, urlopen

headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/hal+json'
}
request = Request('https://modeanalytics.com/api/{organization}/definitions', headers=headers)

response_body = urlopen(request).read()
print(response_body)
var request = require('request');

request({
  method: 'POST',
  url: 'https://modeanalytics.com/api/{organization}/definitions',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/hal+json'
  }}, function (error, response, body) {
  console.log('Status:', response.statusCode);
  console.log('Headers:', JSON.stringify(response.headers));
  console.log('Response:', body);
});

Update a definition

To update a definition, send a PATCH request including the corresponding definition token to the definitions resource.

URL Params

organization

required
string Organization username

definition

required
string Definition token
Responses

200

Definition response

400

Bad request

401

Unauthorized

404

Definition not found

PATCH /{organization}/definitions/{definition}

curl --include \
     --request PATCH \
     --header "Content-Type: application/json" \
     --header "Accept: application/hal+json" \
  'https://modeanalytics.com/api/{organization}/definitions/{definition}'
require 'http'

username = 'you_api_key'
password = 'you_api_secret'

headers = {
  content_type: 'application/json',
  accept: 'application/hal+json'
}

response = HTTP.basic_auth(user: username, pass: password)
               .headers(headers)
               .patch('https://modeanalytics.com/api/{organization}/definitions/{definition}')
puts response
from urllib2 import Request, urlopen

headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/hal+json'
}
request = Request('https://modeanalytics.com/api/{organization}/definitions/{definition}', headers=headers)
request.get_method = lambda: 'PATCH'

response_body = urlopen(request).read()
print(response_body)
var request = require('request');

request({
  method: 'PATCH',
  url: 'https://modeanalytics.com/api/{organization}/definitions/{definition}',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/hal+json'
  }}, function (error, response, body) {
  console.log('Status:', response.statusCode);
  console.log('Headers:', JSON.stringify(response.headers));
  console.log('Response:', body);
});

Delete a definition

To remove a given Definition from an Organization, send a DELETE request to the definitions resource.

URL Params

organization

required
string Organization username

definition

required
string Definition token
Responses

200

Definition response

400

Bad request

401

Unauthorized

404

Definition not found

DELETE /{organization}/definitions/{definition}

curl --include \
     --request DELETE \
     --header "Content-Type: application/json" \
     --header "Accept: application/hal+json" \
  'https://modeanalytics.com/api/{organization}/definitions/{definition}'
require 'http'

username = 'you_api_key'
password = 'you_api_secret'

headers = {
  content_type: 'application/json',
  accept: 'application/hal+json'
}

response = HTTP.basic_auth(user: username, pass: password)
               .headers(headers)
               .delete('https://modeanalytics.com/api/{organization}/definitions/{definition}')
puts response
from urllib2 import Request, urlopen

headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/hal+json'
}
request = Request('https://modeanalytics.com/api/{organization}/definitions/{definition}', headers=headers)
request.get_method = lambda: 'DELETE'

response_body = urlopen(request).read()
print(response_body)
var request = require('request');

request({
  method: 'DELETE',
  url: 'https://modeanalytics.com/api/{organization}/definitions/{definition}',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/hal+json'
  }}, function (error, response, body) {
  console.log('Status:', response.statusCode);
  console.log('Headers:', JSON.stringify(response.headers));
  console.log('Response:', body);
});