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 Workspace.

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 Workspace.

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

workspace

required
string Workspace username

definition

required
string Definition token
Responses

200

Definition response

401

Unauthorized

404

Definition not found

GET /{workspace}/definitions/{definition}

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

username = 'your_api_key'
password = 'your_api_secret'

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

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

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

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

request({
  method: 'GET',
  url: 'https://app.mode.com/api/{workspace}/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 Workspace, send a GET request to the definitions resource.

URL Params

workspace

required
string Workspace username
Query Params

filter

string Filter Definition's by token. Example: ?filter=by_tokens

tokens

string Comma separated list of Definition tokens
Responses

200

Definitions collection response

401

Unauthorized

404

No default Library found

GET /{workspace}/definitions

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

username = 'your_api_key'
password = 'your_api_secret'

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

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

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

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

request({
  method: 'GET',
  url: 'https://app.mode.com/api/{workspace}/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

workspace

required
string Workspace username
Responses

200

Definition response

400

Bad request

401

Unauthorized

404

DataSource not found

POST /{workspace}/definitions

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

username = 'your_api_key'
password = 'your_api_secret'

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

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

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

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

request({
  method: 'POST',
  url: 'https://app.mode.com/api/{workspace}/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

workspace

required
string Workspace username

definition

required
string Definition token
Responses

200

Definition response

400

Bad request

401

Unauthorized

404

Definition not found

PATCH /{workspace}/definitions/{definition}

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

username = 'your_api_key'
password = 'your_api_secret'

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

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

headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/hal+json'
}
request = Request('https://app.mode.com/api/{workspace}/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://app.mode.com/api/{workspace}/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 a Workspace, send a DELETE request to the definitions resource.

URL Params

workspace

required
string Workspace username

definition

required
string Definition token
Responses

200

Definition response

400

Bad request

401

Unauthorized

404

Definition not found

DELETE /{workspace}/definitions/{definition}

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

username = 'your_api_key'
password = 'your_api_secret'

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

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

headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/hal+json'
}
request = Request('https://app.mode.com/api/{workspace}/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://app.mode.com/api/{workspace}/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);
});