Element definitions
Summary of element endpoints
- GET /admin/api/element_definitions - list all available element definitions.
 - POST /admin/api/element_definitions - create a new element definition.
 - GET /admin/api/element_definitions/1 - get data for a single element definition.
 - PUT /admin/api/element_definitions/1 - update attributes of a single element definition.
 - DELETE /admin/api/element_definitions/1 - remove a element.
 
List all available element definitions
GET /admin/api/element_definitions
Example response:
Status: 200 OK
[
  {
    "id": 1,
    "title": "Person",
    "created_at": "2014-02-05T11:22:47.000Z",
    "updated_at": "2014-02-05T11:22:47.000Z",
    "url": "http://helloworld.voog.co/admin/api/element_definitions/1",
    "elements_url": "http://helloworld.voog.co/admin/api/elements?element_definition_id=1"
  }, {
    "id": 2,
    "title": "Book",
    "created_at": "2014-02-05T16:06:09.000Z",
    "updated_at": "2014-02-05T16:06:09.000Z",
    "url": "http://helloworld.voog.co/admin/api/element_definitions/2",
    "elements_url": "http://helloworld.voog.co/admin/api/elements?element_definition_id=2"
  }
]
Parameters
per_page- elements per response (default:50; maximum:250).page- requested page (default:1).
Filter attributes
Read more about filters.
- Object 
element_definitionattributes:id,title,created_at,updated_at. 
Create a new element definition
POST /admin/api/element_definitions
Example data:
{
  "title": "Author",
  "fields": [{
    "key": "birthday",
    "title": "Birthday",
    "data_type": "date",
    "position": 1
  }, {
    "key": "gender",
    "title": "Gender",
    "data_type": "select",
    "position": 2,
    "options": ["Female", "Male"]
  }, {
    "key": "description",
    "title": "Description",
    "data_type": "text",
    "position": 3
  }, {
    "key": "country",
    "title": "Country",
    "data_type": "string",
    "position": 4
  }, {
    "key": "public",
    "title": "Public",
    "data_type": "boolean",
    "position": 5
  }, {
    "key": "photo",
    "title": "Photo",
    "data_type": "image",
    "position": 6
  }]
}
Example response:
Status: 201 Created
{
  "id": 3,
  "title": "Author",
  "created_at": "2014-02-05T14:22:56.434Z",
  "updated_at": "2014-02-05T14:22:56.434Z",
  "url": "http://helloworld.voog.co/admin/api/element_definitions/3",
  "elements_url": "http://helloworld.voog.co/admin/api/elements?element_definition_id=3",
  "data": {
    "properties": {
      "birthday": {
        "title": "Birthday",
        "data_type": "date",
        "position": 1
      },
      "gender": {
        "title": "Gender",
        "data_type": "select",
        "position": 2,
        "options": ["Female", "Male"]
      },
      "description": {
        "title": "Description",
        "data_type": "text",
        "position": 3
      },
      "country": {
        "title": "Country",
        "data_type": "string",
        "position": 4
      },
      "public": {
        "title": "Public",
        "data_type": "boolean",
        "position": 5
      },
      "photo": {
        "title": "Photo",
        "data_type": "image",
        "position": 6
      }
    }
  }
}
Parameters
Required parameters:
title- name of the definition.
Optional parameters:
fields- definition fields as array where every field is described as hash (eg"fields": [{"key": "description", "title": "Description", "data_type": "text", "position": 1}]).
Required field attributes:
key- unique key for field (column identificator) (e.g.descriptio-field).title- human readable title for given field (e.gDescription).position- filed position (e.g.1) in fields lists.data_type- field type allowed values are:string- string input.text- text input with rich text editor.number- number input that allows integer and numbers with floating point.select- select input.boolean- boolean checkbox.date- date input.datetime- date with time.image- draggable image (path) input.
options- array of select values (e.g["", "Option 1", "Option 2"]) (required for "select" data type).
Get data for a single element definition
GET /admin/api/element_definitions/1
Example request:
GET http://helloworld.voog.co/admin/api/element_definitions/2
Example response:
Status: 200 OK
{
  "id": 2,
  "title": "Book",
  "created_at": "2014-02-05T16:06:09.000Z",
  "updated_at": "2014-02-05T16:06:09.000Z",
  "url": "http://helloworld.voog.co/admin/api/element_definitions/2",
  "elements_url": "http://helloworld.voog.co/admin/api/elements?element_definition_id=2",
  "data": {
    "properties": {
      "isbn": {
        "data_type": "string",
        "title": "ISBN",
        "position": 2
      },
      "category": {
        "data_type": "select",
        "options": [
          "Fiction",
          "Reference",
          "Cookbooks"
        ],
        "title": "Category",
        "position": 1
      },
      "release-date": {
        "data_type": "date",
        "title": "Release date",
        "position": 3
      }
    }
  }
}
Update attributes of a single element definition
PUT /admin/api/element_definitions/1
This request updates the definition with provided attributes.
Example request:
PUT http://helloworld.voog.co/admin/api/element_definitions/3
Example data:
Status: 200 OK
{
  "title": "Author",
  "fields": [{
    "key": "description",
    "title": "Description",
    "data_type": "text",
    "position": 1
  }]
}
Example response:
Status: 200 OK
{
  "id": 3,
  "title": "Author",
  "created_at": "2014-02-05T14:22:56.434Z",
  "updated_at": "2014-02-05T15:01:03.434Z",
  "url": "http://helloworld.voog.co/admin/api/element_definitions/3",
  "elements_url": "http://helloworld.voog.co/admin/api/elements?element_definition_id=3",
  "data": {
    "properties": {
      "description": {
        "title": "Description",
        "data_type": "text",
        "position": 1
      }
    }
  }
}
Parameters
Required parameters:
title- name of the definition.
Optional parameters:
fields- definition fields as array where every field is described as hash (eg"fields": [{"key": "description", "title": "Description", "data_type": "text", "position": 1}]). Replaces fields set with new one. See more.
Remove a element
DELETE /admin/api/element_definitions/1
This request deletes the element from the database. NB! Also all related element objects are deleted with definition.
Example request:
DELETE http://helloworld.voog.co/admin/api/element_definitions/3
Example response:
Status: 204 No Content