Tables

Tables

Source:

Methods for tables.

Methods

(static) addField(tableName, fieldToAdd) → {Promise.<{status: 201, statusText: 'Created', message: string}>}

Source:
Since:
  • 1.0.0

Adds a field to table tableName.

Note (incompatible types): Some properties are not compatible with some field types. For example, it is not possible to specify a Prefix for a field whose Type is 'TIMESTAMP'. Use care and caution when creating field definitions.

Example
// add a simple text field (max 255 characters) to the 'Demo_Users' table
const caspio = require('caspio-sdk')(caspioCredentials);

async function addFieldToTable() {
  const fieldDef = {
    "Name": "Sample_Field",
    "Type": "STRING",
    "Unique": false,
    "Description": "Sample data field to collext smaller textual data (max 255 characters)",
    "DisplayOrder": 1,
    "Label": "Sample Field",
  }
  const addFieldResult = await caspio.tables.addField('Demo_Users', fieldDef);
  console.log(addFieldResult);
  return addFieldResult;
}

addFieldToTable();

// sample return value
{
  status: 201,
  statusText: 'Created',
  message: "The field 'Sample_Field' was successfully added to the following table: 'Demo_Users'."
}
Parameters:
Name Type Description
tableName string

Name of table (case-insensitive)

fieldToAdd Object

Definition of field to add to the specified table

Properties
Name Type Attributes Description
Name string

The name of the field to be created. Field names must comply with the following naming protocol as specified in Caspio's documentation:

Must be alphanumeric (a-Z, 0-9);

can be up to 32 characters long; may include an underscore (_);

must begin with a letter; spaces are not allowed

Type string

The type of the field to be created (i.e., data type). Valid types: 'AUTONUMBER', 'PREFIXED AUTONUMBER', 'GUID', 'RANDOM ID', 'STRING', 'TEXT', 'PASSWORD', 'NUMBER', 'INTEGER', 'CURRENCY', 'DATE/TIME', 'YES/NO', 'FILE', 'TIMESTAMP', 'LIST-STRING', 'LIST-NUMBER', LIST-DATE/TIME'

Unique boolean <optional>

Determines whether or not uniqueness should be enforced on values entered in the field

UniqueAllowNulls boolean <optional>

Determines whether or not missing values should be allowed in a field where uniqueness is enforced

Label string <optional>

A label for the field that will be automatically used in DataPages (maximum of 255 characters allowed)

Description string <optional>

Description of the field (maximum of 4000 characters allowed)

DisplayOrder number <optional>

Order in which the field is displayed in a table

OnInsert boolean <optional>

Determines whether or not a timestamp should record when (i.e., date and time) a record was inserted in a table (defaults to true when the field Type is 'TIMESTAMP')

OnUpdate boolean <optional>

Determines whether or not a timestamp should record when (i.e., date and time) a record was updated in a table (defaults to false when the field Type is 'TIMESTAMP')

TimeZone string <optional>

Time zone description for a field with Type of 'TIMESTAMP' (to see all valid time zone descriptions, visit the design page for any table in your application, select the data type of "Timestamp" for the field, and then view the "Time Zone" selection list in the "Options" menu on the right of the table design page)

Format string <optional>

Number format for fields with a Type of 'PREFIXED AUTONUMBER'. Possible values for Format option: '1', '01', '001', '0001', '00001', '000001', '0000001'

Prefix string <optional>

Prefix for values in a field with a Type of either 'PREFIXED AUTONUMBER' or 'RANDOM ID'.

Length number <optional>

Length of random character generation when using a field with a Type of 'RANDOM ID'. The length of a field value recorded may exceed the Length specified if a Prefix has been provided (i.e., the Prefix does not count toward the overall length of the random character string generated). Valid values for the Length option: 6, 7, 8, 9, 10, 11, 12

IsFormula boolean <optional>

Indicates whether or not the field is being used as a formula field. Currently, the Caspio REST API does not enable you to actually specify the formula to be used. The use of this option when creating a field for a table is not recommended.

ListField Array <optional>

Array that specifies the list values to be used when the field has a Type of LIST-STRING, LIST-NUMBER, or LIST-DATE/TIME'. All values specified in the array should have a data type corresponding to <data-type> in LIST-<data-type> (i.e., STRING, NUMBER, or DATE/TIME).

For example, values for a field with a Type of 'LIST-STRING' may be specified as [ "2022-25-12", "Dog", "2022", ... ], a 'LIST-NUMBER' as [ 15, 21, ... ], and a 'LIST-DATE/TIME' as [ "1991-07-30T15:32:57", "2019-01-20", "2020-06-08T00:00:00", ... ].

If you were to then query the definition of the table to which the fields above were added, then the ListField property for the 'LIST-STRING' would appear as { "1": "2022-25-12", "2": "Dog", "3": "2022", ... }, the 'LIST-NUMBER' as { "1": 15, "2": 21, ... }, and the 'LIST-DATE/TIME' as { "1": "1991-07-30T15:32:57", "2": "2019-01-20T00:00:00", "3": "2020-06-08T00:00:00", ... }.

Returns:

Object with information about the attempted creation of the new field for the specified table (i.e., status, statusText, and message).

Type
Promise.<{status: 201, statusText: 'Created', message: string}>

(static) create(tableName, fieldDefinitions) → {Promise.<{status: 201, statusText: 'Created', message: string}>}

Source:
Since:
  • 1.0.0
See:

Creates a new table using the name and field definitions provided (i.e., tableName and fieldDefinitions, respectively). This is often a slow method and takes a while for the request to be processed by Caspio's servers.

Note (incompatible types): Some properties are not compatible with some field types. For example, it is not possible to specify a Prefix for a field whose Type is 'TIMESTAMP'. Use care and caution when creating field definitions. The example that accompanies this method shows examples of each field Type creation.

Example
// create a table titled 'my_new_table' that includes an example
// of the creation of each field type that Caspio has to offer
const caspio = require('caspio-sdk')(caspioCredentials);

async function createTable() {
  const tableName = 'my_new_table';
  const tableColumnDefs = [
    {
      "Name": "my_id",
      "Type": "AUTONUMBER",
      "Unique": true,
      "Description": "Data Type: Autonumber\n\nDescription: An automatically-assigned ID field. The value is incremented by 1 for each new record and cannot be changed except by resetting it for the entire table.\n\nExamples: Customer_ID, Record_ID\n\nConversion Compatibility: Text (255), Text (64000), Number, Integer, Currency",
      "DisplayOrder": 1,
      "Label": "Example field with Type of AUTONUMBER",
      "UniqueAllowNulls": false,
      "IsFormula": false
    },
    {
      "Format": "001",
      "Prefix": "some_prefix",
      "Name": "my_prefixed_autonumber",
      "Type": "PREFIXED AUTONUMBER",
      "Unique": true,
      "Description": "Data Type: Prefixed Autonumber\n\nDescription: An automatically-assigned ID field with the ability to add a prefix.\n\nUse the Options area to configure the prefix and number format of the ID code to be generated.\n\nExamples: Customer_ID, Record_ID\n\nConversion Compatibility: Text (255), Text (64000)",
      "DisplayOrder": 2,
      "Label": "Example field with Type of PREFIXED AUTONUMBER",
      "UniqueAllowNulls": false,
      "IsFormula": false
    },
    {
      "Name": "guid",
      "Type": "GUID",
      "Unique": true,
      "Description": "Data Type: GUID\n\nDescription: A system-generated and globally-unique identifier value, typically used as a complex unique value.\n\nExamples: Customer_ID, Record_ID\n\nConversion Compatibility: Text (255), Text (64000)",
      "DisplayOrder": 3,
      "Label": "Type GUID",
      "UniqueAllowNulls": false,
      "IsFormula": false
    },
    {
      "Format": "0U",
      "Prefix": "",
      "Length": 8,
      "Name": "random_id",
      "Type": "RANDOM ID",
      "Unique": true,
      "Description": "Data Type: Random ID\n\nDescription: A unique system-generated random ID field with the ability to add a prefix as well as define the length and composition of characters, digits, or both.\n\nUse the Options area to configure the prefix and number of characters the ID code should contain. You can also specify whether to include alphabet characters only, numbers only, or both (alphanumeric).\n\nExamples: Customer_ID, Record_ID\n\nConversion Compatibility: Text (255), Text (64000)",
      "DisplayOrder": 4,
      "Label": "Type: RANDOM ID",
      "UniqueAllowNulls": false,
      "IsFormula": false
    },
    {
      "Name": "Full_Name",
      "Type": "STRING",
      "Unique": false,
      "Description": "Data Type: Text (255)\n\nDescription: Used for a string of text of up to 255 alphanumeric characters and/or symbols. This data type is the most common data type and yields the fastest performance in searches.\n\nYou can also use this data type for numeric characters that are not used as numbers in calculations or formatting--such as phone numbers, zip codes, and social security numbers. Not doing so impacts formatting and prevents proper sorting by this field.\n\nExamples: First_Name, State, Phone, Zip_Code\n\nConversion Compatibility: Text (64000), File (provided that the text field contains proper file paths)",
      "DisplayOrder": 5,
      "Label": "Type: TEXT",
      "UniqueAllowNulls": false,
      "IsFormula": false
    },
    {
      "Name": "Bio",
      "Type": "TEXT",
      "Unique": false,
      "Description": "Data Type: Text (64000)\n\nDescription: Used for a long string of text of up to 64,000 alphanumeric characters and/or symbols.\n\nUse this data type for description fields or other lengthy text data. Otherwise, use Text (255), which performs much faster.\n\nExamples: Description, Comments\n\nConversion Compatibility: Text (255) (longer strings are truncated), File (provided that the text field contains proper file paths)",
      "DisplayOrder": 6,
      "Label": "Type: STRING",
      "UniqueAllowNulls": false,
      "IsFormula": false
    },
    {
      "Name": "password",
      "Type": "PASSWORD",
      "Unique": false,
      "Description": "Data Type: Password\n\nDescription: Used for storing user passwords.\n\nThe value of this field is always encrypted and cannot be seen in Datasheet or DataPages.\n\nExamples: Password\n\nConversion Compatibility: None",
      "DisplayOrder": 7,
      "Label": "Type: PASSWORD",
      "UniqueAllowNulls": false,
      "IsFormula": false
    },
    {
      "Name": "Favorite_Number",
      "Type": "NUMBER",
      "Unique": false,
      "Description": "Data Type: Number\n\nDescription: Used for decimal numbers.\n\nExamples: Weight, height, area, percentage values\n\nConversion Compatibility: Text (255), Text (64000), Integer (decimal values are truncated), Currency (allows up to four decimal points)",
      "DisplayOrder": 8,
      "Label": "Type: NUMBER",
      "UniqueAllowNulls": false,
      "IsFormula": false
    },
    {
      "Name": "Age",
      "Type": "INTEGER",
      "Unique": false,
      "Description": "Data Type: Integer\n\nDescription: Used for numbers that do not have a decimal point, can be used as IDs and in relationships.\n\nExamples: Age, number of children\n\nConversion Compatibility: Text (255), Text (64000), Number, Currency",
      "DisplayOrder": 9,
      "Label": "Type: INTEGER",
      "UniqueAllowNulls": false,
      "IsFormula": false
    },
    {
      "Name": "Salary",
      "Type": "CURRENCY",
      "Unique": false,
      "Description": "Data Type: Currency\n\nDescription: Used for money fields in any currency.\n\nExamples: Price, Salary\n\nConversion Compatibility: Text (255), Text (64000), Integer (decimal values are truncated)",
      "DisplayOrder": 10,
      "Label": "Type: CURRENCY",
      "UniqueAllowNulls": false,
      "IsFormula": false
    },
    {
      "Name": "Birthday",
      "Type": "DATE/TIME",
      "Unique": false,
      "Description": "Data Type: Date/Time\n\nDescription: Used for date and time data.\n\nDataPages automatically display a calendar picker for date/time fields. 'Precision' is specified in the DataPage and is used to configure which part of the date or time part is used.\n\nUse the Options area to specify whether or not to allow blank values in this field.\n\nExamples: Followup_Date, Date_of_Birth\n\nConversion Compatibility: Text (255), Text (64000), Timestamp",
      "DisplayOrder": 11,
      "Label": "Type: DATE/TIME",
      "UniqueAllowNulls": false,
      "IsFormula": false
    },
    {
      "Name": "Married",
      "Type": "YES/NO",
      "Unique": false,
      "Description": "Data Type: Yes/No\n\nDescription: Used for fields that allow only two possible values: yes or no (true or false).\n\nBy default a Yes/No input field appears as a checkbox in forms.\n\nExamples: Active_User, Requested_Newsletter, Published\n\nConversion Compatibility: Text (255), Text (64000), Number",
      "DisplayOrder": 12,
      "Label": "YES/NO",
      "UniqueAllowNulls": false,
      "IsFormula": false
    },
    {
      "Name": "Profile_Picture",
      "Type": "FILE",
      "Unique": false,
      "Description": "Data Type: File\n\nDescription: Used to associate files with a record.\n\nFile fields allow your app users to upload files using a web form. Files are stored in your database and can be used in DataPages.\n\nFiles can also be accessed in the Files area of All Assets, organized in a file folder structure.\n\nExamples: Profile_Photo, Resume, Contract\n\nConversion Compatibility: Text (255) may be truncated, Text (64000)",
      "DisplayOrder": 13,
      "Label": "FILE",
      "UniqueAllowNulls": false,
      "IsFormula": false
    },
    {
      "OnInsert": true,
      "OnUpdate": false,
      "TimeZone": "UTC",
      "Name": "timestamp",
      "Type": "TIMESTAMP",
      "Unique": false,
      "Description": "Data Type: Timestamp\n\nDescription: A timestamp is a type of smart field that automatically records the date and time when a record is submitted and/or updated.\n\nUse the Options area to configure the time zone and the general behavior of the timestamp.\n\nExamples: Date_Submitted, Date_Updated\n\nConversion Compatibility: Text (255), Text (64000), Date/Time",
      "DisplayOrder": 14,
      "Label": "Type: TIMESTAMP",
      "UniqueAllowNulls": false,
      "IsFormula": false
    },
    {
      "Name": "Favorite_Words",
      "Type": "LIST-STRING",
      "Unique": false,
      "Description": "Data Type: List\n\nDescription: A special data type for storing a collection of strings, numbers or dates in a single field. (List - String for text values of up to 255 characters.)\n\nExamples: Allergies, Pizza_Toppings\n\nConversion Compatibility: None",
      "DisplayOrder": 15,
      "Label": "LIST-STRING",
      "UniqueAllowNulls": false,
      "IsFormula": false,
      "ListField": ["25", "Coffee", "Doggo", "Goober", "Jolly", "Malapropism"]
    },
    {
      "Name": "Favorite_Numbers",
      "Type": "LIST-NUMBER",
      "Unique": false,
      "Description": "Data Type: tbd\n\nDescription: A special data type for storing a collection of strings, numbers or dates in a single field. (List - Number for numeric values of up to 15 digits.)\n\nExamples: Allergies, Pizza_Toppings\n\nConversion Compatibility: None",
      "DisplayOrder": 16,
      "Label": "LIST-NUMBER",
      "UniqueAllowNulls": false,
      "IsFormula": false,
      "ListField": [18, 42, 91, 777, 89]
    },
    {
      "Name": "Favorite_Dates",
      "Type": "LIST-DATE/TIME",
      "Unique": false,
      "Description": "Data Type: tbd\n\nDescription: A special data type for storing a collection of strings, numbers or dates in a single field. (List - Date for date or date/time values.)\n\nExamples: Allergies, Pizza_Toppings\n\nConversion Compatibility: None",
      "DisplayOrder": 17,
      "Label": "LIST-DATE/TIME",
      "UniqueAllowNulls": false,
      "IsFormula": false,
      "ListField": ["1991-07-30T15:32:57", "2019-01-20T00:00:00", "2020-06-08T00:00:00", "2021-02-02T00:00:00"]
    }
  ]

  const creationResult = await caspio.tables.create(tableName, tableColumnDefs);
  console.log(creationResult);
  return creationResult;
}

createTable();

// sample return value
{
  status: 201,
  statusText: 'Created',
  message: "Table 'my_new_table' has been created successfully."
}
Parameters:
Name Type Description
tableName string

Name of the table

fieldDefinitions Array.<Object>

Definitions of the fields to be created in the new table

Properties
Name Type Attributes Description
Name string

The name of the field to be created. Field names must comply with the following naming protocol as specified in Caspio's documentation:

Must be alphanumeric (a-Z, 0-9); can be up to 32 characters long;

may include an underscore (_);

must begin with a letter; spaces are not allowed

Type string

The data type of the field to be created. Valid types: 'AUTONUMBER', 'PREFIXED AUTONUMBER', 'GUID', 'RANDOM ID', 'STRING', 'TEXT', 'PASSWORD', 'NUMBER', 'INTEGER', 'CURRENCY', 'DATE/TIME', 'YES/NO', 'FILE', 'TIMESTAMP', 'LIST-STRING', 'LIST-NUMBER', LIST-DATE/TIME'

Unique boolean <optional>

Determines whether or not uniqueness should be enforced on values entered in the field

UniqueAllowNulls boolean <optional>

Determines whether or not missing values should be allowed in a field where uniqueness is enforced

Label string <optional>

A label for the field that will be automatically used in DataPages (maximum of 255 characters allowed)

Description string <optional>

Description of the field (maximum of 4000 characters allowed)

DisplayOrder number <optional>

Order in which the field is displayed in a table

OnInsert boolean <optional>

Determines whether or not a timestamp should record when (i.e., date and time) a record was inserted in a table (defaults to true when the field Type is 'TIMESTAMP')

OnUpdate boolean <optional>

Determines whether or not a timestamp should record when (i.e., date and time) a record was updated in a table (defaults to false when the field Type is 'TIMESTAMP')

TimeZone string <optional>

Time zone description for a field with Type of 'TIMESTAMP' (to see all valid time zone descriptions, visit the design page for any table in your application, select the data type of "Timestamp" for the field, and then view the "Time Zone" selection list in the "Options" menu on the right of the table design page)

Format string <optional>

Number format for fields with a Type of 'PREFIXED AUTONUMBER'. Possible values for Format option: '1', '01', '001', '0001', '00001', '000001', '0000001'

Prefix string <optional>

Prefix for values in a field with a Type of either 'PREFIXED AUTONUMBER' or 'RANDOM ID'.

Length number <optional>

Length of random character generation when using a field with a Type of 'RANDOM ID'. The length of a field value recorded may exceed the Length specified if a Prefix has been provided (i.e., the Prefix does not count toward the overall length of the random character string generated). Valid values for the Length option: 6, 7, 8, 9, 10, 11, 12

IsFormula boolean <optional>

Indicates whether or not the field is being used as a formula field. Currently, the Caspio REST API does not enable you to actually specify the formula to be used. The use of this option when creating a field for a table is not recommended.

ListField Array <optional>

Array that specifies the list values to be used when the field has a Type of LIST-STRING, LIST-NUMBER, or LIST-DATE/TIME'. All values specified in the array should have a data type corresponding to <data-type> in LIST-<data-type> (i.e., STRING, NUMBER, or DATE/TIME).

For example, values for a field with a Type of 'LIST-STRING' may be specified as [ "2022-25-12", "Dog", "2022", ... ], a 'LIST-NUMBER' as [ 15, 21, ... ], and a 'LIST-DATE/TIME' as [ "1991-07-30T15:32:57", "2019-01-20", "2020-06-08T00:00:00", ... ].

If you were to then query the definition of the table to which the fields above were added, then the ListField property for the 'LIST-STRING' would appear as { "1": "2022-25-12", "2": "Dog", "3": "2022", ... }, the 'LIST-NUMBER' as { "1": 15, "2": 21, ... }, and the 'LIST-DATE/TIME' as { "1": "1991-07-30T15:32:57", "2": "2019-01-20T00:00:00", "3": "2020-06-08T00:00:00", ... }.

Returns:

Object with information about the attempted creation of the specified table (i.e., status, statusText, and message).

Type
Promise.<{status: 201, statusText: 'Created', message: string}>

(static) createRecord(tableName, recordValuesObj, optionsopt) → {Promise.<({status: 201, statusText: 'Created', message: string}|{status: 201, statusText: 'Created', message: string, createdRecord: object})>}

Source:
Since:
  • 1.0.0

Inserts record recordValuesObj into table tableName (i.e., creates a record).

Example
// create and return a record in the 'Demo_Users' table with a 'Name' field value of 'Osment'
// and an 'Email' field value of 'Osment@google.com'
const caspio = require('caspio-sdk')(caspioCredentials);

async function createTableRecord() {
  const newRecordObj = {
    Name: "Osment",
    Email: "Osment@google.com",
  }
  const creationResult = await caspio.tables.createRecord('Demo_Users', newRecordObj, { row: true });
  console.log(creationResult);
  return creationResult;
}

createTableRecord();

// sample return value
{
  status: 201,
  statusText: 'Created',
  message: "Record successfully created in 'Demo_Users' table.",
  createdRecord: {
    User_ID: 'QNFPG6OT',
    Name: 'Osment',
    Email: 'Osment@google.com',
    Role: '',
    Active: false
  }
}
Parameters:
Name Type Attributes Default Description
tableName string

Name of table (case-insensitive)

recordValuesObj object

Object with key-value pairs in the form <fieldName>:<updatedFieldValue>; that is, any provided key should match a field's Name to be updated and the key's value should be the intended value for that field with the appropriate data type (e.g., { "First_Name": "Updated First Name", "Last_Name": "Updated Last Name" }).

Note (warnings about creating a record with list field values): If you are trying to create the values for a record's ListField property (i.e., when a record's field has a Type of LIST-STRING|NUMBER|DATE/TIME), then be aware that you may be in for a world of pain (read: not recommended). Why?

First, you have to know the numeric values of the keys for the key-value pairs that make up a ListField's definition. For example, suppose the definition of your list field is { "1": "Cat", "2": "Dog", "3": "Frog" }. If you want to have "Dog" and "Frog" as the list values for the created record, then you have to specify the ListField as follows: ListField: [ 2, 3 ]. How are you supposed to know the key values ahead of time? Only by querying the table for its definition with something like the tables.definition method.

Second, if you happen to specify an index value that does not currently exist in a list field's definition, then you'll get something like the following 400 error: "Cannot perform operation because the value doesn't match the data type of the following field(s): <field-name>".

The whole thing is janky as hell and thus not recommended unless you really know what you're doing (even then you might get unlucky).

options object <optional>
{ 'row': false }

The options object currently only supports the row option. If no object is provided, then { 'row': false } is taken as the default value. If an options object is provided with a row property value of true, then the record created by the query is returned in the response object as the value for the createdRecord property; otherwise, the response object does not have a createdRecord property and no created record is returned.

Properties
Name Type Attributes Default Description
row boolean <optional>
false
Returns:

Object with information about the attempted creation of the provided record (i.e., status, statusText, message, and createdRecord if the options argument was passed as { 'row': true })

Type
Promise.<({status: 201, statusText: 'Created', message: string}|{status: 201, statusText: 'Created', message: string, createdRecord: object})>

(static) definition(tableName) → {Promise.<Array.<{Name: string, Type: string, Unique: boolean, UniqueAllowNulls: boolean, Label: string, Description: string, DisplayOrder: number, OnInsert: boolean, OnUpdate, boolean, TimeZone: string, Format: string, Prefix: string, Length: number, IsFormula: boolean, ListField: object}>>}

Source:
Since:
  • 1.0.0

Returns the definition of table tableName as an array of field definitions (objects).

Example
// get the table definition of the 'Demo_Users' table
const caspio = require('caspio-sdk')(caspioCredentials);

async function getTableDefinition() {
  const definition = await caspio.tables.definition('Demo_Users');
  console.log(definition);
  return definition;
}

getTableDefinition();

// sample return value
[
  {
    Format: '0U',
    Prefix: '',
    Length: 8,
    Name: 'User_ID',
    Type: 'RANDOM ID',
    Unique: true,
    Description: '',
    DisplayOrder: 1,
    Label: '',
    UniqueAllowNulls: false,
    IsFormula: false
  },
  {
    Name: 'Name',
    Type: 'STRING',
    Unique: false,
    Description: '',
    DisplayOrder: 2,
    Label: '',
    UniqueAllowNulls: false,
    IsFormula: false
  },
  {
    Name: 'Email',
    Type: 'STRING',
    Unique: true,
    Description: '',
    DisplayOrder: 3,
    Label: '',
    UniqueAllowNulls: false,
    IsFormula: false
  },
  {
    Name: 'Password',
    Type: 'PASSWORD',
    Unique: false,
    Description: '',
    DisplayOrder: 4,
    Label: '',
    UniqueAllowNulls: false,
    IsFormula: false
  },
  {
    Name: 'Role',
    Type: 'STRING',
    Unique: false,
    Description: '',
    DisplayOrder: 5,
    Label: '',
    UniqueAllowNulls: false,
    IsFormula: false
  },
  {
    Name: 'Active',
    Type: 'YES/NO',
    Unique: false,
    Description: '',
    DisplayOrder: 6,
    Label: '',
    UniqueAllowNulls: false,
    IsFormula: false
  }
]
Parameters:
Name Type Description
tableName string

Name of table (case-insensitive)

Returns:

Array of field definitions (objects) where the properties of the objects depend on the field definition (e.g., a field with Type of 'RANDOM ID' may have a Length property as part of the field definition object whereas other fields would not)

Type
Promise.<Array.<{Name: string, Type: string, Unique: boolean, UniqueAllowNulls: boolean, Label: string, Description: string, DisplayOrder: number, OnInsert: boolean, OnUpdate, boolean, TimeZone: string, Format: string, Prefix: string, Length: number, IsFormula: boolean, ListField: object}>>

(static) deleteField(tableName, fieldName) → {Promise.<{status: 200, statusText: 'OK', message: string}>}

Source:
Since:
  • 1.0.0

Deletes field fieldName from table tableName (this may not be possible if other objects depend on this field such as triggered actions, authentications, etc.).

Example
// remove the field 'Sample_Field' from table 'Demo_Users'
const caspio = require('caspio-sdk')(caspioCredentials);

async function deleteTableField() {
  const deleteResult = await caspio.tables.deleteField('Demo_Users', 'Sample_Field');
  console.log(deleteResult);
  return deleteResult;
}

deleteTableField();

// sample return value
{
  status: 200,
  statusText: 'OK',
  message: "The field 'Sample_Field' in table 'Demo_Users' was successfully deleted."
}
Parameters:
Name Type Description
tableName string

Name of table (case-insensitive)

fieldName string

Name of field (case-insensitive)

Returns:

Object with information about the attempted removal of the specified field from the specified table (i.e., status, statusText, and message).

Type
Promise.<{status: 200, statusText: 'OK', message: string}>

(static) deletePasswordFieldValue(tableName, passwordFieldName, whereClause) → {Promise.<{status: 200, statusText: 'OK', recordsAffected: number, message: string}>}

Source:
Since:
  • 1.0.0

Resets (i.e., removes) the password value in field passwordFieldName of table tableName for all records that match the provided WHERE clause query (i.e., whereClause).

Example
// removes the value in field 'Password' of table 'Demo_Users'
// for all records that have an Email field value of 'Edd36@yahoo.com'
const caspio = require('caspio-sdk')(caspioCredentials);

async function removePasswordValue() {
  const whereClause = `Email = 'Edd36@yahoo.com'`;
  const removeResult = await caspio.tables.deletePasswordFieldValue('Demo_Users', 'Password', whereClause);
  console.log(removeResult);
  return removeResult;
}

removePasswordValue();

// sample return value
{
  status: 200,
  statusText: 'OK',
  recordsAffected: 1,
  message: "Password value(s) successfully reset (i.e., removed) for field 'Password' in table 'Demo_Users' for 1 record(s)."
}
Parameters:
Name Type Description
tableName string

Name of table (case-insensitive)

passwordFieldName string

Name of field with Type of 'PASSWORD' in table tableName to target (case-insensitive)

whereClause string

WHERE clause (i.e., query to match records to be affected)

Returns:

Object with information about the attempted resetting or removal of all password values for the matched records (i.e., status, statusText, recordsAffected, and message).

Type
Promise.<{status: 200, statusText: 'OK', recordsAffected: number, message: string}>

(static) deleteRecords(tableName, whereClause) → {Promise.<{status: 200, statusText: 'OK', message: string, recordsAffected: number}>}

Source:
Since:
  • 1.0.0

Deletes all records from table tableName that match whereClause (i.e., the provided WHERE clause).

Example
// delete all records from the 'Demo_Users' table that have
// an 'Email' field value of 'Osment@google.com'
const caspio = require('caspio-sdk')(caspioCredentials);

async function deleteTableRecords() {
  const whereClause = `Email = 'Osment@google.com'`;
  const deleteResult = await caspio.tables.deleteRecords('Demo_Users', whereClause);
  console.log(deleteResult);
  return deleteResult;
}

deleteTableRecords();

// sample return value
{
  status: 200,
  statusText: 'OK',
  message: "1 record(s) in table 'Demo_Users' successfully deleted.",
  recordsAffected: 1
}
Parameters:
Name Type Description
tableName string

Name of table (case-insensitive)

whereClause string

WHERE clause (i.e., query to match records to be affected)

Returns:

Object with information about the attempted deletion of the records matched by the WHERE clause (i.e., status, statusText, message, and recordsAffected)

Type
Promise.<{status: 200, statusText: 'OK', message: string, recordsAffected: number}>

(static) description(tableName) → {Promise.<{Name: string, Note: string}>}

Source:
Since:
  • 1.0.0

Returns the description of the table (i.e., a description of table tableName).

Example
// get the description of the 'Demo_Users' table
const caspio = require('caspio-sdk')(caspioCredentials);

async function getTableDescription() {
  const description = await caspio.tables.description('Demo_Users');
  console.log(description);
  return description;
}

getTableDescription();

// sample return value
{ Name: 'Demo_Users', Note: '' }
Parameters:
Name Type Description
tableName string

Name of the table (case-insensitive)

Returns:

Object with the name of the table (i.e., Name) and a note about the table (i.e., Note)

Type
Promise.<{Name: string, Note: string}>

(static) fieldDefinition(tableName) → {Promise.<{Name: string, Type: string, Unique: boolean, UniqueAllowNulls: boolean, Label: string, Description: string, DisplayOrder: number, OnInsert: boolean, OnUpdate, boolean, TimeZone: string, Format: string, Prefix: string, Length: number, IsFormula: boolean, ListField: object}>}

Source:
Since:
  • 1.0.0

Returns the definition of field fieldName from table tableName.

Example
// get the definition of the field 'Sample_Field' from the 'Demo_Users' table
const caspio = require('caspio-sdk')(caspioCredentials);

async function getFieldDef() {
  const fieldDef = await caspio.tables.fieldDefinition('Demo_Users', 'Sample_Field');
  console.log(fieldDef);
  return fieldDef;
}

getFieldDef();

// sample return value
{
  Name: 'Sample_Field',
  Type: 'STRING',
  Unique: false,
  Description: 'Sample data field to collext smaller textual data (max 255 characters)',
  DisplayOrder: 1,
  Label: 'Sample Field',
  UniqueAllowNulls: false,
  IsFormula: false
}
Parameters:
Name Type Description
tableName string

Name of table (case-insensitive)

Returns:

Field definition (object) where the properties of the object depend on the field definition (e.g., a field with Type of 'RANDOM ID' may have a Length property as part of the field definition object whereas other fields would not)

Type
Promise.<{Name: string, Type: string, Unique: boolean, UniqueAllowNulls: boolean, Label: string, Description: string, DisplayOrder: number, OnInsert: boolean, OnUpdate, boolean, TimeZone: string, Format: string, Prefix: string, Length: number, IsFormula: boolean, ListField: object}>

(static) getRecords(tableName, selectionCriteriaObjopt) → {Promise.<Array.<Object>>}

Source:
Since:
  • 1.0.0

Returns all records from the table that satisfy the provided query criteria (i.e., selectionCriteriaObj). Pagination is automatically handled to ensure all records matching the provided criteria are returned.

Note (potential strain on memory resources): If the query provided results in many thousands or millions of records needing to be returned, then this may cause a strain on memory resources (since all returned records are held in memory when using this method). Consider using the getRecordsStreamToFile method in such an instance where all returned records can be streamed to a file in batches of 1000 records (i.e., the maximum number of records Caspio's REST API will respond with for any request).

Example
// get records from the 'Demo_Users' table using the query criteria
// provided in the criteriaObj object
const caspio = require('caspio-sdk')(caspioCredentials);

async function getTableRecords() {
  const criteriaObj = {
    select: 'Email, ROW_NUMBER() OVER (PARTITION BY Role ORDER BY User_ID) AS rnk_num',
    where: `Name LIKE '%ed%'`,
    orderBy: 'rnk_num'
  }
  const tableRecords = await caspio.tables.getRecords('Demo_Users', criteriaObj);
  console.log(tableRecords);
  return tableRecords;
}

getTableRecords();

// sample return value
[
  { "Email": "Edwardo.Roberts@gmail.com", "rnk_num": 1 },
  { "Email": "Frederick_Sanford@yahoo.com", "rnk_num": 1 },
  { "Email": "Winifred.Stamm41@hotmail.com", "rnk_num": 2 },
  { "Email": "Fred.Daugherty41@hotmail.com", "rnk_num": 2 },
  { "Email": "Alan.Schroeder@gmail.com", "rnk_num": 3 },
  ...
  { "Email": "Eliane.Schroeder@hotmail.com", "rnk_num": 81 },
  { "Email": "Jedediah_Bednar33@yahoo.com", "rnk_num": 81 },
  { "Email": "Edyth3@gmail.com", "rnk_num": 82 },
  { "Email": "Magdalen84@hotmail.com", "rnk_num": 82 },
  { "Email": "Edyth_Mayer@yahoo.com", "rnk_num": 83 },
  { "Email": "Eddie_Predovic14@hotmail.com", "rnk_num": 84 },
  { "Email": "Francesca_Medhurst39@yahoo.com", "rnk_num": 85 },
  { "Email": "Jedediah.Mitchell@hotmail.com", "rnk_num": 86 },
  { "Email": "Wilfred_Funk20@gmail.com", "rnk_num": 87 },
  { "Email": "Mohamed.Hammes@hotmail.com", "rnk_num": 88 },
  { "Email": "Frieda_Strosin@gmail.com", "rnk_num": 89 },
  { "Email": "Ted.Anderson94@yahoo.com", "rnk_num": 90 },
  { "Email": "Jedediah.Runolfsson60@yahoo.com", "rnk_num": 91 },
  { "Email": "Destiny.Schroeder@hotmail.com", "rnk_num": 92 },
  { "Email": "Edwina.Barrows@yahoo.com", "rnk_num": 93 },
  { "Email": "Carlie_Bednar@gmail.com", "rnk_num": 94 },
  { "Email": "Ebony25@gmail.com", "rnk_num": 95 },
  { "Email": "Lexi81@hotmail.com", "rnk_num": 96 },
  { "Email": "Frederique.Kuhn86@gmail.com", "rnk_num": 97 },
  { "Email": "Winifred_Aufderhar63@yahoo.com", "rnk_num": 98 },
  { "Email": "Edd_Carroll0@hotmail.com", "rnk_num": 99 }
]
Parameters:
Name Type Attributes Default Description
tableName string

Name of table (case-insensitive)

selectionCriteriaObj Object <optional>
{}

Object that specifies the criteria to be used in constructing the query. Valid properties include the following: select, where, groupBy, and orderBy.

In large part, the query being constructed resembles most queries constructed using SQL (specifically the SQL Server dialect since Caspio uses SQL Server under the hood). Consult a Caspio rep to find which version your account is running on.

Note: Usage of window functions when expecting more than 1000 records is problematic due to being rate-limited at 1000 records per request (hence there's not an effective window within which to operate).

Properties
Name Type Attributes Default Description
select string <optional>
'*'

List of fields separated by comma, where fields may either be fields directly from the specified table or could be a combination of numerous other things:

aliases such as First_Name AS name;

subqueries that return one value such as (SELECT COUNT(User_ID) FROM Demo_Users) AS demo_users_count;

correlated subqueries such as (SELECT Email from Users WHERE User_ID = Registrations.User_ID) where Registrations is the value of the tableName argument (i.e., the singular table from which records are being pulled);

window functions such as ROW_NUMBER() OVER(PARTITION BY Company, Department ORDER BY Salary DESC, Experience DESC, User_ID) AS comp_dept_sal_rnk to compute salary rankings within departments of a company first by salary amount, years of experience, and finally the User_ID if needed to break ties.

The possibilities are endless--there are numerous possibilities with which to experiment.

where string <optional>
''

WHERE clause. This is used to find the desired records. You may use subqueries in this clause (e.g., User_ID IN (SELECT ... FROM ... ) among other examples)) as well as AND, OR, etc. Much power can be leveraged by using this clause effectively.

groupBy string <optional>
''

GROUP BY clause. Useful for grouping records by specified fields to consequently make aggregate calculations.

orderBy string <optional>
''

ORDER BY clause. Useful for having SQL Server do the heavy lifting concerning sorting before the response gets transmitted across the wire.

Returns:

An array of objects representing the records retrieved from the specified table (i.e., tableName) that were obtained by the query provided (i.e., selectionCriteriaObj).

Type
Promise.<Array.<Object>>

(static) getRecordsPaginated(tableName, selectionCriteriaObjopt) → {Promise.<Array.<Object>>}

Source:
Since:
  • 1.0.0

Returns records in a paginated fashion from table tableName that satisfy the provided query criteria (i.e., selectionCriteriaObj).

Example
// get the default of 100 records from the Demo_Users table using
// the query criteria provided in the criteriaObj object
const caspio = require('caspio-sdk')(caspioCredentials);

async function getPaginatedTableRecords() {
  const criteriaObj = {
    select: 'Email, ROW_NUMBER() OVER (PARTITION BY Role ORDER BY User_ID) AS rnk_num',
    where: `Name LIKE '%ed%'`,
    orderBy: 'rnk_num'
  }
  const tableRecords = await caspio.tables.getRecordsPaginated('Demo_Users', criteriaObj);
  console.log(tableRecords);
  return tableRecords;
}

getPaginatedTableRecords();

// sample return value
[
  { Email: 'Frederick_Sanford@yahoo.com', rnk_num: 1 },
  { Email: 'Edwardo.Roberts@gmail.com', rnk_num: 1 },
  { Email: 'Fred.Daugherty41@hotmail.com', rnk_num: 2 },
  { Email: 'Winifred.Stamm41@hotmail.com', rnk_num: 2 },
  { Email: 'Winifred.Friesen@hotmail.com', rnk_num: 3 },
  { Email: 'Alan.Schroeder@gmail.com', rnk_num: 3 },
  ...
  { Email: 'Meredith.Botsford50@hotmail.com', rnk_num: 48 },
  { Email: 'Braeden63@gmail.com', rnk_num: 48 },
  { Email: 'Eddie_Tromp@hotmail.com', rnk_num: 49 },
  { Email: 'Ned39@gmail.com', rnk_num: 49 },
  { Email: 'Edna92@hotmail.com', rnk_num: 50 },
  { Email: 'Soledad.Collins84@yahoo.com', rnk_num: 50 }
]
Parameters:
Name Type Attributes Default Description
tableName string

Name of table (case-insensitive)

selectionCriteriaObj Object <optional>
{}

Object that specifies the criteria to be used in constructing the query. Valid properties include the following: select, where, groupBy, orderBy, limit, pageNumber, and pageSize.

In large part, the query being constructed resembles most queries constructed using SQL (specifically the SQL Server dialect since Caspio uses SQL Server under the hood). Consult a Caspio rep to find which version your account is running on.

Note: Usage of window functions (e.g., ROW_NUMBER()) when expecting more than 1000 records is problematic due to being rate-limited by Caspio's servers at 1000 records per request (hence there's not an effective window within which to operate).

Properties
Name Type Attributes Default Description
select string <optional>
'*'

List of fields separated by comma, where fields may either be fields directly from the specified table or could be a combination of numerous other things:

aliases such as First_Name AS name;

subqueries that return one value such as (SELECT COUNT(*) FROM Demo_Users) AS demo_users_count;

correlated subqueries such as (SELECT Email from Users WHERE User_ID = Registrations.User_ID) when Registrations is the value of the tableName argument (i.e., the singular table from which records are being pulled);

window functions such as ROW_NUMBER() OVER(PARTITION BY Company, Department ORDER BY Salary DESC, Experience DESC, User_ID) AS comp_dept_sal_rnk to compute salary rankings within departments of a company first by salary amount, years of experience, and finally the User_ID if needed to break ties.

The possibilities are endless--there are numerous possibilities with which to experiment.

where string <optional>
''

WHERE clause. This is used to find the desired records. You may use subqueries in this clause (e.g., User_ID IN (SELECT ... FROM ... ) among other examples) as well as AND, OR, etc. Much power can be leveraged by using this clause effectively.

groupBy string <optional>
''

GROUP BY clause. Useful for grouping records by specified fields to consequently make aggregate calculations.

orderBy string <optional>
''

ORDER BY clause. Useful for having SQL Server do the heavy lifting concerning sorting before the response gets transmitted across the wire.

limit number <optional>
100

Specifies the maximum number of records to be returned. Maximum possible value of 1000 with a default value of 100. Skipped if either pageNumber or pageSize has been specified.

pageNumber number <optional>

Page number corresponding to the pagination that results from the initial query. Defaults to 1 if pageSize has been specified but pageNumber has not.

pageSize number <optional>

Number of records per page (possible from 5 to 1000). Defaults to 25 if pageNumber has been specified but pageSize has not.

Returns:

An array of objects representing the records retrieved from the specified table (i.e., tableName) that were obtained by the query provided (i.e., selectionCriteriaObj).

Type
Promise.<Array.<Object>>

(static) getRecordsStreamToFile(tableName, filePath, selectionCriteriaObjopt) → {void}

Source:
Since:
  • 1.0.0

Streams all records from the table (i.e., tableName) that satisfy the provided query criteria (i.e., selectionCriteriaObj) to a file (i.e., filePath). Pagination is automatically handled to ensure all records matching the provided criteria are streamed to the specified file. Records are streamed in batches of 1000 records (Caspio's rate limit for returning records). Useful when you need to process huge amounts of data but do not want to hold everything in memory.

Example
// stream all records from the 'Demo_Users' table to the 'StreamedDemoUsers.json' file
const caspio = require('caspio-sdk')(caspioCredentials);

async function streamTableRecordsToFile() {
  await caspio.tables.getRecordsStreamToFile('Demo_Users', 'StreamedDemoUsers.json');
}

streamTableRecordsToFile();

// no return value
Parameters:
Name Type Attributes Default Description
tableName string

Name of table (case-insensitive)

filePath string

Path of file to write to (file path should have an extension of .json)

selectionCriteriaObj Object <optional>
{}

Object that specifies the criteria to be used in constructing the query. Valid properties include the following: select, where, groupBy, and orderBy.

In large part, the query being constructed resembles most queries constructed using SQL (specifically the SQL Server dialect since Caspio uses SQL Server under the hood). Consult a Caspio rep to find which version your account is running on.

Note: Usage of window functions when expecting more than 1000 records is problematic due to being rate-limited at 1000 records per request (hence there's not an effective window within which to operate).

Properties
Name Type Attributes Default Description
select string <optional>
'*'

List of fields separated by comma, where fields may either be fields directly from the specified table or could be a combination of numerous other things:

aliases such as First_Name AS name;

subqueries that return one value such as (SELECT COUNT(User_ID) FROM Demo_Users) AS demo_users_count;

correlated subqueries such as (SELECT Email from Users WHERE User_ID = Registrations.User_ID) where Registrations is the value of the tableName argument (i.e., the singular table from which records are being pulled);

window functions such as ROW_NUMBER() OVER(PARTITION BY Company, Department ORDER BY Salary DESC, Experience DESC, User_ID) AS comp_dept_sal_rnk to compute salary rankings within departments of a company first by salary amount, years of experience, and finally the User_ID if needed to break ties.

The possibilities are endless--there are numerous possibilities with which to experiment.

where string <optional>
''

WHERE clause. This is used to find the desired records. You may use subqueries in this clause (e.g., User_ID IN (SELECT ... FROM ... ) among other examples)) as well as AND, OR, etc. Much power can be leveraged by using this clause effectively.

groupBy string <optional>
''

GROUP BY clause. Useful for grouping records by specified fields to consequently make aggregate calculations.

orderBy string <optional>
''

ORDER BY clause. Useful for having SQL Server do the heavy lifting concerning sorting before the response gets transmitted across the wire.

Returns:

No value is returned

Type
void

(static) listing() → {Promise.<Array.<string>>}

Source:
Since:
  • 1.0.0

Returns an array of strings where each string represents an available table for a Caspio account.

Example
// get list of all table names linked to a Caspio account
const caspio = require('caspio-sdk')(caspioCredentials);

async function getTableNames() {
  const tableNames = await caspio.tables.listing();
  console.log(tableNames);
  return tableNames;
}

getTableNames();

// sample return value
[
  ...,
  'Demo_Physicians',
  ...
]
Returns:

Array of strings representing table names for a Caspio account

Type
Promise.<Array.<string>>

(static) passwordFields(tableName) → {Promise.<Array.<string>>}

Source:
Since:
  • 1.0.0

Returns a list of the names of all password fields in table tableName (i.e., an array of the names of whatever fields are present in table tableName that have a Type of 'PASSWORD').

Example
// get list of all fields with a Type of 'PASSWORD' from the table 'Demo_Users'
const caspio = require('caspio-sdk')(caspioCredentials);

async function getTablePasswordFields() {
  const passwordFields = await caspio.tables.passwordFields('Demo_Users');
  console.log(passwordFields);
  return passwordFields;
}

getTablePasswordFields();

// sample return value
[ 'Password' ]
Parameters:
Name Type Description
tableName string

Name of table (case-insensitive)

Returns:

Array of strings representing the names of fields present in the specified table that have a Type of 'PASSWORD'

Type
Promise.<Array.<string>>

(static) updateFieldDefinition(tableName, fieldName, updatedFieldDef) → {Promise.<{status: 200, statusText: 'OK', message: string}>}

Source:
Since:
  • 1.0.0

Updates field fieldName of table tableName using properties and values of the updatedFieldDef object.

Note 1 (importance of New prefix): It is critically important that all updated field properties be prepended with New in the provided updatedFieldDef object; otherwise, an error will be thrown. For example, if you want to update the Type of a field from 'STRING' to 'TEXT', then you need to specify the updatedFieldDef object as { ..., 'NewType': 'TEXT', ... } as opposed to { ..., 'Type': 'TEXT', ... }. The presence of 'New' is required.

Note 2 (warning about list types): Be wary of updating a field with a Type of LIST-STRING|NUMBER|DATE/TIME for reasons outlined in this method's documentation.

Example
// update the field 'Sample_Field' in table 'Demo_Users'
// to have a Type of 'TEXT' instead of 'STRING'
const caspio = require('caspio-sdk')(caspioCredentials);

async function updateTableField() {
  const updatedFieldDef = {
    "NewType": "TEXT"
  }
  const updateResult = await caspio.tables.updateFieldDefinition('Demo_Users', 'Sample_Field', updatedFieldDef);
  console.log(updateResult);
}

updateTableField();

// sample return value
{
  status: 200,
  statusText: 'OK',
  message: "The field 'Sample_Field' in table 'Demo_Users' was successfully updated."
}
Parameters:
Name Type Description
tableName string

Name of table (case-insensitive)

fieldName string

Name of field (case-sensitive)

updatedFieldDef Object

Definition of field to update in table tableName (note again the importance of prepending field properties with New such as 'NewType', 'NewUnique', etc.).

Properties
Name Type Attributes Description
NewName string <optional>

The name of the field to be created. Field names must comply with the following naming protocol as specified in Caspio's documentation:

Must be alphanumeric (a-Z, 0-9);

can be up to 32 characters long; may include an underscore (_);

must begin with a letter; spaces are not allowed

NewType string <optional>

The type of the field to be created (i.e., data type). Valid types: 'AUTONUMBER', 'PREFIXED AUTONUMBER', 'GUID', 'RANDOM ID', 'STRING', 'TEXT', 'PASSWORD', 'NUMBER', 'INTEGER', 'CURRENCY', 'DATE/TIME', 'YES/NO', 'FILE', 'TIMESTAMP', 'LIST-STRING', 'LIST-NUMBER', LIST-DATE/TIME'

NewUnique boolean <optional>

Determines whether or not uniqueness should be enforced on values entered in the field

NewUniqueAllowNulls boolean <optional>

Determines whether or not missing values should be allowed in a field where uniqueness is enforced

NewLabel string <optional>

A label for the field that will be automatically used in DataPages (maximum of 255 characters allowed)

NewDescription string <optional>

Description of the field (maximum of 4000 characters allowed)

NewDisplayOrder number <optional>

Order in which the field is displayed in a table

NewOnInsert boolean <optional>

Determines whether or not a timestamp should record when (i.e., date and time) a record was inserted in a table (defaults to true when the field Type is 'TIMESTAMP')

NewOnUpdate boolean <optional>

Determines whether or not a timestamp should record when (i.e., date and time) a record was updated in a table (defaults to false when the field Type is 'TIMESTAMP')

NewTimeZone string <optional>

Time zone description for a field with Type of 'TIMESTAMP' (to see all valid time zone descriptions, visit the design page for any table in your application, select the data type of "Timestamp" for the field, and then view the "Time Zone" selection list in the "Options" menu on the right of the table design page)

NewFormat string <optional>

Number format for fields with a Type of 'PREFIXED AUTONUMBER'. Possible values for Format option: '1', '01', '001', '0001', '00001', '000001', '0000001'

NewPrefix string <optional>

Prefix for values in a field with a Type of either 'PREFIXED AUTONUMBER' or 'RANDOM ID'.

NewLength number <optional>

Length of random character generation when using a field with a Type of 'RANDOM ID'. The length of a field value recorded may exceed the Length specified if a Prefix has been provided (i.e., the Prefix does not count toward the overall length of the random character string generated). Valid values for the Length option: 6, 7, 8, 9, 10, 11, 12

NewListField Array <optional>

Array that specifies the list values to be used when the field has a Type of LIST-STRING, LIST-NUMBER, or LIST-DATE/TIME'. All values specified in the array should have a data type corresponding to <data-type> in LIST-<data-type> (i.e., STRING, NUMBER, or DATE/TIME). Note that the values specified in the update will effectively remove the previous values.

For example, values for a field with a Type of 'LIST-STRING' may be specified as [ "2022-25-12", "Dog", "2022", ... ], a 'LIST-NUMBER' as [ 15, 21, ... ], and a 'LIST-DATE/TIME' as [ "1991-07-30T15:32:57", "2019-01-20", "2020-06-08T00:00:00", ... ].

If you were to then query the definition of the table to which the fields above were added, then the ListField property for the 'LIST-STRING' would appear as { "num1": "2022-25-12", "num2": "Dog", "num3": "2022", ... }, the 'LIST-NUMBER' as { "num1": 15, "num2": 21, ... }, and the 'LIST-DATE/TIME' as { "num1": "1991-07-30T15:32:57", "num2": "2019-01-20T00:00:00", "num3": "2020-06-08T00:00:00", ... }, where all of the num values depend on what the previous definition was of the ListField.

Note: The definition for an updated ListField is a bit wonky, and how the object keys are created for the new definition depends on the following three possibilities concerning each element as specified in the NewListField array:

  • element currently exists in ListField: Nothing happens.
  • element does not exist in ListField but did at some point in the past: The original key-value pair is effectively restored; that is, if the current ListField definition is { "1": "Cat", "4": "Frog", "6": "Mouse" } but included the key-value pair "2": "Dog" at some point in the past, then specifying NewListField as [ "Cat", "Dog", "Frog" ] will result in a new ListField definition of { "1": "Cat", "2": "Dog", "4": "Frog" }. The key-value pair "2": "Dog" is effectively restored.
  • element does not exist in ListField and never has: A completely new key-value pair is created, where the numeric value of the key will be the highest possible value that is next in sequence; that is, if [ "Cat", "Dog", "Frog" ] was the array originally specified for ListField, with corresponding definition { "1": "Cat", "2": "Dog", "3": "Frog" }, then specifying NewListField as [ "Dog", "Cow" ] would result in the following ListField definition: { "2": "Dog", "4": "Cow" }.
Returns:

Object with information about the attempted update of the specified field for the specified table (i.e., status, statusText, and message).

Type
Promise.<{status: 200, statusText: 'OK', message: string}>

(static) updatePasswordFieldValue(tableName, passwordFieldName, newPasswordValue, whereClause) → {Promise.<{status: 200, statusText: 'OK', recordsAffected: number, message: string}>}

Source:
Since:
  • 1.0.0

Updates the password field passwordFieldName in table tableName with a value of newPasswordValue for all records that are matched by the provided WHERE clause query (i.e., whereClause).

Example
// update the value in field 'Password' of table 'Demo_Users'
// to 'myPassword!' for all records in table 'Demo_Users' that have
// an Email field value of 'Edd36@yahoo.com'
const caspio = require('caspio-sdk')(caspioCredentials);

async function updateTablePassword() {
  const whereClause = `Email = 'Edd36@yahoo.com'`;
  const updateResult = await caspio.tables.updatePasswordFieldValue('Demo_Users', 'Password', 'myPassword!', whereClause);
  console.log(updateResult);
  return updateResult;
}

updateTablePassword();

// sample return value
{
  status: 200,
  statusText: 'OK',
  recordsAffected: 1,
  message: "Password value(s) successfully updated for field 'Password' in table 'Demo_Users' for 1 record(s)."
}
Parameters:
Name Type Description
tableName string

Name of table (case-insensitive)

passwordFieldName string

Name of field in table tableName with a Type of 'PASSWORD' to target (case-insensitive)

newPasswordValue string

New password value

whereClause string

WHERE clause (i.e., query to match records to be affected)

Returns:

Object with information about the attempted update of all password values for the matched records (i.e., status, statusText, recordsAffected, and message).

Type
Promise.<{status: 200, statusText: 'OK', recordsAffected: number, message: string}>

(static) updateRecords(tableName, whereClause, newRecordValuesObj, optionsopt) → {Promise.<({status: 200, statusText: 'OK', message: string, recordsAffected: number}|{status: 200, statusText: 'OK', message: string, recordsAffected: number, updatedRecords: Array.<Object>})>}

Source:
Since:
  • 1.0.0

Updates all records in table tableName matched by whereClause (i.e., the provided WHERE clause) with values from the newRecordValuesObj object.

Example
// Update the 'Name' field in the 'Demo_Users' table to have a value of
// 'Eddy Rath' for all records that have an 'Email' field with value 'Edd36@yahoo.com'
const caspio = require('caspio-sdk')(caspioCredentials);

async function updateTableRecords() {
  const whereClause = `Email = 'Edd36@yahoo.com'`;
  const newValuesObj = {
    Name: "Eddy Rath"
  }
  const updateResult = await caspio.tables.updateRecords('Demo_Users', whereClause, newValuesObj, { rows: true });
  console.log(updateResult);
  return updateResult;
}

updateTableRecords();

// sample return value
{
  status: 200,
  statusText: 'OK',
  message: "1 record(s) affected. Note: If the number of affected records is higher than expected, then be sure to check any triggered actions associated with the 'Demo_Users' table, which can cause various records in other tables to be affected.",
  recordsAffected: 1,
  updatedRecords: [
    {
      User_ID: '7NQC2PHT',
      Name: 'Eddy Rath',
      Email: 'Edd36@yahoo.com',
      Role: 'Admin',
      Active: false
    }
  ]
}
Parameters:
Name Type Attributes Default Description
tableName string

Name of table (case-insensitive)

whereClause string

WHERE clause (i.e., query to match records to be affected)

newRecordValuesObj object

Object with key-value pairs in the form <fieldName>:<updatedFieldValue>; that is, any provided key should match a field's Name to be updated and the key's value should be the updated value for that field (e.g., { "First_Name": "Updated First Name", "Last_Name": "Updated Last Name" }).

Note (warnings about updating a record's list field values): If you are trying to update the values for a record's ListField property (i.e., when a record's field has a Type of LIST-STRING|NUMBER|DATE/TIME), then be aware that you may be in for a world of pain (read: not recommended). Why?

First, you have to know the numeric values of the keys for the key-value pairs that make up a ListField's definition. For example, suppose the definition of your list field is { "1": "Cat", "2": "Dog", "3": "Frog" }. If you want to have "Dog" and "Frog" as the list values for the updated record(s), then you have to specify the ListField as follows: ListField: [ 2, 3 ]. How are you supposed to know the key values ahead of time? Only by querying the table for its definition with something like the tables.definition method.

Second, if you happen to specify an index value that does not currently exist in a list field's definition, then you'll get something like the following 400 error: "Cannot perform operation because the value doesn't match the data type of the following field(s): <field-name>".

Third, if you update records by only specifying fields with a Type of LIST-STRING|NUMBER|DATE/TIME (i.e., all field values you are updating are of the list type variety), then the RecordsAffected property on the response object will read 0 even if numerous records were updated. This is obviously a bug.

Fourth (as if you needed another reason to avoid updating values in list fields), if { 'rows': true } is specified on the request while updating list field values only, then Caspio's servers throw a 500 error. The reason why is not entirely clear. This is also obviously a bug.

The whole thing is janky as hell and thus not recommended unless you really know what you're doing (even then you might get unlucky).

options object <optional>
{ 'rows': false }

The options object currently only supports the rows option. If no object is provided, then { 'rows': false } is taken as the default value. If an options object is provided with a rows property value of true, then the records updated by the query are returned in the response object as the value for the updatedRecords property; otherwise, the response object does not have an updatedRecords property and no updated records are returned.

Properties
Name Type Attributes Default Description
rows boolean <optional>
false
Returns:

Object with information about the attempted update of the records matched by the WHERE clause (i.e., status, statusText, message, recordsAffected, and updatedRecords if the options argument was passed as { 'rows': true })

Type
Promise.<({status: 200, statusText: 'OK', message: string, recordsAffected: number}|{status: 200, statusText: 'OK', message: string, recordsAffected: number, updatedRecords: Array.<Object>})>