Skip to content

Data Structure

Each Attainable API is comprised of data stores with fields made up of simple data types, as well as the ability to represent relationships. The highest level of the structure is the data store. Each data store has one or more indented fields. Fields are labels mapped to a data type or a relationship.

The following example defines a user data store that has a single field called name that is a string data type.

user:
name: string

There are the following data types available to use:

  • string, text
  • integer, number
  • date, datetime, time
  • boolean, bool

You can also nest fields within a field. The following example represenets a field named preferences that has a field of its own named color that is a string data type.

user:
name: string
preferences: { color: string }

Relationships are possible with two types of definitions:

  • Belongs to <: This represents that this field points to another data store by id number.
  • Has many <<: This field has many pointers to another data store’s items by id number.

The following example defines user data store that has an addresses field that has many address items by id, and an address data store with a field named user that points to another user item by id.

user:
name: string
preferences: { color: string }
addresses: << address # has many addresses
address:
user: < user # belongs to a user
street: string
city: string
postal_code: number
country_code: string

The field names do not have to match the data store they are related to. They only have to match the name of the data store by data type.

Every data store also gets three default fields that are entirely managed by the API:

  • id: a unique identifier field
  • createdat: a date field representing the time of creation for the item
  • updatedat: a date that represents the last update to the item

These fields are returned by default in all of the RESTful responses from the API, but can be optionally removed with a projection query field in the URL of the API request. Learn more about URL options.