1.0.3 • Published 2 years ago

caspio-sdk v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

caspio-sdk

Software development kit (SDK) and REST API wrapper for the Caspio REST API (v2).

Visit the caspio-sdk docs website to see the documentation for this package in a more readable format (as well as in-depth tutorials). If you're already there, great!

Note: This package was developed and tested using Node.js v16.13.0.

Contents

Features

  • Full coverage of all Caspio REST API resource endpoints
  • Extended coverage of many endpoints that offers a cleaner data manipulation interface
  • Capabilities not offered directly by Caspio's REST API (e.g., ability to copy records)
  • Comprehensive documentation that can be difficult or impossible to find directly on Caspio's website
  • Detailed examples that make the documentation come to life
  • Detailed tutorials that explain how to meet common development needs

Installation

npm install caspio-sdk

Usage

All requests to Caspio REST API resource endpoints must be made with a valid access token (which expires every 24 hours). The two subsections below outline how to start using this SDK if you do not already have a valid access token or if you do, respectively.

Getting started without a valid access token

If you do not have a valid access token, then you may obtain one by authenticating with Caspio's REST API in the following manner, namely by providing the clientID, clientSecret, and tokenEndpointURL for one of your Caspio account's active web services profiles:

// provide credentials for active web services profile
const caspioAuthCredentials = {
  clientID: '*****',
  clientSecret: '*****',
  tokenEndpointURL: '*****',
}

// obtain function to make request for a new valid access token
const getAccessToken = require('caspio-sdk/auth')(caspioAuthCredentials);

// obtain new access token
async function sdkGetValidAccessToken() {
  const data = await getAccessToken();
  console.log(data.access_token);
}

Once you have a valid access token, you can follow the directions immediately below to begin issuing requests.

Getting started with a valid access token

Require the caspio-sdk module in your project and make all SDK methods available by providing your Caspio account credentials upon requiring the module, namely an object with your Caspio's accountID and a valid accessToken that will make it possible to issue authorized requests:

// provide credentials for Caspio account
const caspioCredentials = {
  accountID: '*****',
  accessToken: '*****'
}

// obtain authenticated SDK methods to start issuing requests
const caspio = require('caspio-sdk')(caspioCredentials);

// start issuing requests
async function sdkUseMethods() {
  // method categories available: apps, tables, views, files, tasks, utils
  const data = await caspio.(apps|tables|views|files|tasks|utils).desiredMethod(args);
  console.log(data);
}

Example

An example of issuing a request using this SDK is provided below, but a brief description of every method in this SDK may be found in the next section. The docs website provides the full details (i.e., extensive documentation, detailed examples, etc.).

With the above in mind, here is a simple example of using this SDK to fetch a list of a Caspio account's applications and their properties:

const caspioCredentials = {
  accountID: '*****',
  accessToken: '*****'
}

const caspio = require('caspio-sdk')(caspioCredentials);

async function docsDemoMethodUse() {
  // use the 'listing' method from the 'apps' category
  const propertiesForAllApps = await caspio.apps.listing();
  return propertiesForAllApps;
}

docsDemoMethodUse();
 
// sample return value
[
  ...,
  {
    AppName: 'Demo - Physician Directory - Caspio SDK',
    ExternalKey: '09d18152-7c45-44f1-a0e6-5ffe18881b60',
    DataPagesCount: 5,
    DateCreated: '2022-01-25T15:17:10.607',
    DateModified: '2022-01-25T15:20:44.850',
    DefaultIcon: true,
    IconFileName: ''
  },
  ...
]

Many of the examples outlined on the docs website run against the Demo - Physician Directory - Caspio SDK application, a slightly modified version of the default application Caspio provides to users of new accounts.

If you want to run some of the examples in the documentation against the same set of data, then you can use Caspio's "Import" functionality to import the following application (accessible on this package's GitHub page): Demo_Physician_Directory_Caspio_SDK.zip.

Methods Overview

The following tables provide very brief descriptions of all methods for each category made available for use in this SDK. Each method is listed first by its name (without the method's signature) and then by a description that provides a very high-level overview of what the method does. The docs website provides the full details for each method.

apps

MethodDescription
dpDeployAllByAppKeyDeploys all DataPages in an application based on the application's ID.
dpDeployAllByAppNameDeploys all DataPages in an application based on the application's name.
dpDeployByKeysDeploy a DataPage in an application by providing the application's ID as well as the DataPage's ID.
dpDeployByNamesDeploy a DataPage in an application by providing the application's name as well as the DataPage's name.
dpDeployCodeByKeysGet a particular type of deploy code (e.g., URL, Facebook, WordPress Embed, etc.) for a DataPage in an application by providing the application's ID, the DataPage's ID, and a single letter that denotes the desired deploy code.
dpDeployCodeByNamesGet a particular type of deploy code (e.g., URL, Facebook, WordPress Embed, etc.) for a DataPage in an application by providing the application's name, the DataPage's name, and a single letter that denotes the desired deploy code.
dpDisableAllByAppKeyDisable all DataPages in an application by providing the application's ID.
dpDisableAllByAppNameDisable all DataPages in an application by providing the application's name.
dpDisableByKeysDisable a DataPage in an application by providing the application's ID as well as the DataPage's ID.
dpDisableByNamesDisable a DataPage in an application by providing the application's name as well as the DataPage's name.
dpPropertiesByAppKeyGet properties of all DataPages in an application by providing the application's ID.
dpPropertiesByAppNameGet properties of all DataPages in an application by providing the application's name.
dpPropertiesByKeysGet properties of a DataPage in an application by providing the application's ID as well as the DataPage's ID.
dpPropertiesByNamesGet properties of a DataPage in an application by providing the application's name as well as the DataPage's name.
listingGet properties of all applications for a Caspio account (no argument needed).
propertiesByKeyGet properties of an application by providing the application's ID.
propertiesByNameGet properties of an application by providing the application's name.

files

MethodDescription
deleteByKeyDelete a file by providing the file's ID.
deleteByPathDelete a file by providing the file's absolute path.
downloadByKeyDownload a file by providing the file's ID and optionally specify a new name for the downloaded file.
downloadByPathDownload a file by providing the file's absolute path and optionally specify a new name for the downloaded file.
metadataByKeyRetrieve metadata for file(s) and folder(s) by providing the file or folder's ID.
metadataByPathRetrieve metadata for a specific file or specific folder by providing the file or folder's absolute path.
uploadByKeyUpload files to a folder by providing the folder's ID (if naming conflicts occur, then the conflicted files are not uploaded).
uploadByPathUpload files to a folder by providing the folder's absolute path (if naming conflicts occur, then the conflicted files are not uploaded).
uploadOverwriteByKeyUpload files to a folder by providing the folder's ID (if naming conflicts occur, then the conflicted files to upload will overwrite the currently existing files).
uploadOverwriteByPathUpload files to a folder by providing the folder's absolute path (if naming conflicts occur, then the conflicted files to upload will overwrite the currently existing files).

tables

MethodDescription
addFieldAdd a field to a currently existing table by providing the table's name and the new field's definition.
createCreate a new table by providing the new table's name and all new field definitions.
createRecordCreate a record in a table by providing the table's name, record to create, and optionally whether or not to return the record once it has been created.
definitionGet the complete definition for a table by providing the table's name.
deleteFieldDelete a field from a table by providing the table's name as well as the name of the field to delete.
deletePasswordFieldValueRemove password values for records from a table by providing the table's name, the name of the field that holds the passwords to be removed, and a WHERE clause that will cause matched records to have their password field's values to be removed.
deleteRecordsDelete records from a table by providing the table's name as well as a WHERE clause that will cause matched records to be deleted.
descriptionGet a simple description for a table by providing the table's name.
fieldDefinitionGet the definition of a specific field in a table by providing the table's name as well as the field's name.
getRecordsGet all records from a table by providing the table's name as well as a query criteria object that specifies which records are to be returned. Pagination is handled automatically so as to return all records that match the provided query criteria. Exercise caution when using this method since all returned records must be held in memory before the method terminates. If you expect an enormous number of records to be returned, then consider using the streaming version of this method detailed below.
getRecordsPaginatedGet paginated records from a table by providing the table's name as well as a query criteria object that specifies which records are to be returned. (Pagination is not handled automatically and only records are returned that match the provided query criteria and comply with Caspio's default request limits.)
getRecordsStreamToFileGet all records from a table by providing the table's name, query criteria object that specifies which records are to be returned, and the file path of the file to which the returned records should be streamed. Pagination is handled automatically so as to ensure all records that match the provided query criteria are streamed to the provided file. Records are streamed in batches of 1000 records (the rate limit for Caspio servers). Consider using this method when the number of records to be returned is enormous (so as not to strain memory resources).
listingGet a list of all table names for a Caspio account (no argument needed).
passwordFieldsGet a list of all field names in a table that hold encrypted passwords by providing the table's name.
updateFieldDefinitionUpdate the definition of a field in a table by providing the table's name, field's name, and the properties and new values of the field to be updated.
updatePasswordFieldValueUpdate password field values in a table by providing the table's name, password field name, new password value to be used, and a WHERE clause that will cause matched records to have their password field values updated to the provided new password value.
updateRecordsUpdate records in a table by providing the table's name, WHERE clause that will cause matched records to be updated, properties of the records to be updated and their new values, and optionally whether or not to return the updated records once they have been updated.

tasks

MethodDescription
listingGet a list of all scheduled tasks for a Caspio account (no argument needed).
propertiesByKeyGet the properties for a scheduled task by providing the task's ID.
propertiesByNameGet the properties for a scheduled task by providing the task's name.
runByKeyRun a scheduled task by providing the task's ID.
runByNameRun a scheduled task by providing the task's name.

utils

MethodDescription
copyRecordCopy a record in a table by providing the table's name, WHERE clause to match the (single) record copy source, and optionally what properties and values should be updated on the copy source before the destination record is created. Only editable fields may be modified in the copy source before the destination record is created. The newly created record is returned upon successful creation.

views

In general, it is recommended to not use the provided methods to create, delete, and/or update records in a view. Why? Because each of these methods is simply a disguised version of creating, deleting, and/or updating records in an underlying table. Usage of these methods may lead to undesirable and/or unpredictable results. The documentation for each method spells out the full details with detailed examples.

MethodDescription
createRecordMethod not recommended. See method documentation for complete details.
deleteRecordsMethod not recommended. See method documentation for complete details.
descriptionGet a simple description for a view by providing the view's name.
getRecordsGet all records from a view by providing the view's name as well as a query criteria object that specifies which records are to be returned. Pagination is handled automatically so as to return all records that match the provided query criteria. Exercise caution when using this method since all returned records must be held in memory before the method terminates. If you expect an enormous number of records to be returned, then consider using the streaming version of this method detailed below.
getRecordsPaginatedGet paginated records from a view by providing the view's name as well as a query criteria object that specifies which records are to be returned. (Pagination is not handled automatically and only records are returned that match the provided query criteria and comply with Caspio's default request limits.)
getRecordsStreamToFileGet all records from a view by providing the view's name, query criteria object that specifies which records are to be returned, and the file path of the file to which the returned records should be streamed. Pagination is handled automatically so as to ensure all records that match the provided query criteria are streamed to the provided file. Records are streamed in batches of 1000 records (the rate limit for Caspio servers). Consider using this method when the number of records to be returned is enormous (so as not to strain memory resources).
listingGet a list of all view names for a Caspio account (no argument needed).
updateRecordsMethod not recommended. See method documentation for complete details.

SDK API Package Documentation

Check out the caspio-sdk docs website for this package's documentation in its most readable form (use the lefthand menu to find methods of interest).

Documentation for immediate reference may be found below.

Objects

Applications : object

Methods for applications.

Kind: global namespace

Applications.listing() ⇒ Promise.<Array.<{AppName: string, ExternalKey: string, DataPagesCount: number, DateCreated: string, DateModified: string, DefaultIcon: boolean, IconFileName: string}>>

Returns list of applications (i.e., an array of objects where each object represents an application and its properties).

Kind: static method of Applications
Returns: Promise.<Array.<{AppName: string, ExternalKey: string, DataPagesCount: number, DateCreated: string, DateModified: string, DefaultIcon: boolean, IconFileName: string}>> - Array of Caspio applications with each application's properties
Since: 1.0.0
Example

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

async function getAllAppProperties() {
  const propertiesForAllApps = await caspio.apps.listing();
  console.log(propertiesForAllApps);
  return propertiesForAllApps;
}

getAllAppProperties();

// sample return value
[
  ...,
  {
    AppName: 'Demo - Physician Directory - Caspio SDK',
    ExternalKey: '09d18152-7c45-44f1-a0e6-5ffe18881b60',
    DataPagesCount: 5,
    DateCreated: '2022-01-25T15:17:10.607',
    DateModified: '2022-01-25T15:20:44.850',
    DefaultIcon: true,
    IconFileName: ''
  },
  ...
]

Applications.propertiesByName(appName) ⇒ Promise.<{AppName: string, ExternalKey: string, DataPagesCount: number, DateCreated: string, DateModified: string, DefaultIcon: boolean, IconFileName: string}>

Returns the application's properties (i.e., an object that represents an application's properties given the application's case-insensitive name, appName).

Kind: static method of Applications
Returns: Promise.<{AppName: string, ExternalKey: string, DataPagesCount: number, DateCreated: string, DateModified: string, DefaultIcon: boolean, IconFileName: string}> - Object representing a Caspio application and its properties
Since: 1.0.0

ParamTypeDescription
appNamestringName of the application (case-insensitive)

Example

// get properties of the 'Demo - Physician Directory - Caspio SDK' application
const caspio = require('caspio-sdk')(caspioCredentials);

async function getAppProperties() {
  const APP_NAME = 'Demo - Physician Directory - Caspio SDK';
  const appProperties = await caspio.apps.propertiesByName(APP_NAME);
  console.log(appProperties);
  return appProperties;
}

getAppProperties();

// sample return value
{
  AppName: 'Demo - Physician Directory - Caspio SDK',
  ExternalKey: '09d18152-7c45-44f1-a0e6-5ffe18881b60',
  DataPagesCount: 5,
  DateCreated: '2022-01-25T15:17:10.607',
  DateModified: '2022-01-25T15:20:44.850',
  DefaultIcon: true,
  IconFileName: ''
}

Applications.propertiesByKey(externalKey) ⇒ Promise.<{AppName: string, ExternalKey: string, DataPagesCount: number, DateCreated: string, DateModified: string, DefaultIcon: boolean, IconFileName: string}>

Returns the application's properties (i.e., an object that represents an application's properties given the application's ID, externalKey).

Kind: static method of Applications
Returns: Promise.<{AppName: string, ExternalKey: string, DataPagesCount: number, DateCreated: string, DateModified: string, DefaultIcon: boolean, IconFileName: string}> - Object representing a Caspio application and its properties
Since: 1.0.0

ParamTypeDescription
externalKeystringApplication ID

Example

// get properties of the 'Demo - Physician Directory - Caspio SDK' application
// whose application ID is '09d18152-7c45-44f1-a0e6-5ffe18881b60'
const caspio = require('caspio-sdk')(caspioCredentials);

async function getAppProperties() {
  const APP_KEY = '09d18152-7c45-44f1-a0e6-5ffe18881b60';
  const appProperties = await caspio.apps.propertiesByKey(APP_KEY);
  console.log(appProperties);
  return appProperties;
}

getAppProperties();

// sample return value
{
  AppName: 'Demo - Physician Directory - Caspio SDK',
  ExternalKey: '09d18152-7c45-44f1-a0e6-5ffe18881b60',
  DataPagesCount: 5,
  DateCreated: '2022-01-25T15:17:10.607',
  DateModified: '2022-01-25T15:20:44.850',
  DefaultIcon: true,
  IconFileName: ''
}

Applications.dpPropertiesByAppName(appName) ⇒ Promise.<Array.<{Name: string, AppKey: string, AppName: string, Path: string, Type: string, DateCreated: string, DateModified: string, CreatedBy: string, ModifiedBy: string, Note: string}>>

Returns a list of DataPage properties for DataPages associated with an application (i.e., an array of objects where the objects represent an application's DataPages and their properties--the application is identified by its case-insensitive name, appName).

Kind: static method of Applications
Returns: Promise.<Array.<{Name: string, AppKey: string, AppName: string, Path: string, Type: string, DateCreated: string, DateModified: string, CreatedBy: string, ModifiedBy: string, Note: string}>> - Array of DataPages and their properties linked to a specific application
Since: 1.0.0

ParamTypeDescription
appNamestringName of the application (case-insensitive)

Example

// get all DataPage properties linked to the 'Demo - Physician Directory - Caspio SDK' application
const caspio = require('caspio-sdk')(caspioCredentials);

async function dpPropertiesForApp() {
  const APP_NAME = 'Demo - Physician Directory - Caspio SDK';
  const dpProperties = await caspio.apps.dpPropertiesByAppName(APP_NAME);
  console.log(dpProperties);
  return dpProperties;
}

dpPropertiesForApp();

// sample return value
[
  ...,
  {
    Name: 'Physician Registration',
    AppKey: '409550008f83dc4dd4554a07b7bf',
    AppName: 'Demo - Physician Directory - Caspio SDK',
    Path: '/Public Interfaces',
    Type: 'WEBFORM',
    DateCreated: '2022-01-25T15:20:43.787',
    DateModified: '2022-01-25T15:20:43.837',
    CreatedBy: 'user@user.com',
    ModifiedBy: '',
    Note: ''
  },
  ...
]

Applications.dpPropertiesByAppKey(externalKey) ⇒ Promise.<Array.<{Name: string, AppKey: string, AppName: string, Path: string, Type: string, DateCreated: string, DateModified: string, CreatedBy: string, ModifiedBy: string, Note: string}>>

Returns a list of DataPage properties for DataPages associated with an application (i.e., an array of objects where the objects represent an application's DataPages and their properties--the application is identified by its App ID, externalKey).

Kind: static method of Applications
Returns: Promise.<Array.<{Name: string, AppKey: string, AppName: string, Path: string, Type: string, DateCreated: string, DateModified: string, CreatedBy: string, ModifiedBy: string, Note: string}>> - Array of DataPages and their properties linked to a specific application
Since: 1.0.0

ParamTypeDescription
externalKeystringApplication ID

Example

// get all DataPage properties linked to the 'Demo - Physician Directory - Caspio SDK' application
// whose App ID is '09d18152-7c45-44f1-a0e6-5ffe18881b60'
const caspio = require('caspio-sdk')(caspioCredentials);

async function dpPropertiesForApp() {
  const APP_KEY = '09d18152-7c45-44f1-a0e6-5ffe18881b60';
  const dpProperties = await caspio.apps.dpPropertiesByAppKey(APP_KEY);
  console.log(dpProperties);
  return dpProperties;
}

dpPropertiesForApp();

// sample return value
[
  ...,
  {
    Name: 'Physician Registration',
    AppKey: '409550008f83dc4dd4554a07b7bf',
    AppName: 'Demo - Physician Directory - Caspio SDK',
    Path: '/Public Interfaces',
    Type: 'WEBFORM',
    DateCreated: '2022-01-25T15:20:43.787',
    DateModified: '2022-01-25T15:20:43.837',
    CreatedBy: 'user@user.com',
    ModifiedBy: '',
    Note: ''
  },
  ...
]

Applications.dpPropertiesByNames(appName, dataPageName) ⇒ Promise.<{Name: string, AppKey: string, AppName: string, Path: string, Type: string, DateCreated: string, DateModified: string, CreatedBy: string, ModifiedBy: string, Note: string}>

Returns the DataPage's properties (object) for the specified DataPage (i.e., dataPageName) linked to the specified application (i.e., appName), where both specifications are case-insensitive.

Kind: static method of Applications
Returns: Promise.<{Name: string, AppKey: string, AppName: string, Path: string, Type: string, DateCreated: string, DateModified: string, CreatedBy: string, ModifiedBy: string, Note: string}> - Object representing the properties of the specified DataPage for the specified application
Since: 1.0.0

ParamTypeDescription
appNamestringName of the application (case-insensitive)
dataPageNamestringName of the DataPage (case-insensitive)

Example

// get properties of the 'Physician Registration' DataPage which is a DataPage in
// the 'Demo - Physician Directory - Caspio SDK' application
const caspio = require('caspio-sdk')(caspioCredentials);

async function dpGetProperties() {
  const APP_NAME = 'Demo - Physician Directory - Caspio SDK';
  const DP_NAME = 'Physician Registration';
  const dpProperties = await caspio.apps.dpPropertiesByNames(APP_NAME, DP_NAME);
  console.log(dpProperties);
  return dpProperties;
}

dpGetProperties();

// sample return value
{
  Name: 'Physician Registration',
  AppKey: '409550008f83dc4dd4554a07b7bf',
  AppName: 'Demo - Physician Directory - Caspio SDK',
  Path: '/Public Interfaces',
  Type: 'WEBFORM',
  DateCreated: '2022-01-25T15:20:43.787',
  DateModified: '2022-01-25T15:20:43.837',
  CreatedBy: 'user@user.com',
  ModifiedBy: '',
  Note: ''
}

Applications.dpPropertiesByKeys(externalKey, appKey) ⇒ Promise.<{Name: string, AppKey: string, AppName: string, Path: string, Type: string, DateCreated: string, DateModified: string, CreatedBy: string, ModifiedBy: string, Note: string}>

Returns the DataPage's properties (object) for the specified DataPage (i.e., appKey) linked to the specified application (i.e., externalKey).

Kind: static method of Applications
Returns: Promise.<{Name: string, AppKey: string, AppName: string, Path: string, Type: string, DateCreated: string, DateModified: string, CreatedBy: string, ModifiedBy: string, Note: string}> - Object representing the properties of the specified DataPage for the specified application
Since: 1.0.0

ParamTypeDescription
externalKeystringApplication ID
appKeystringDataPage ID

Example

// get properties of the 'Physician Registration' DataPage which is a DataPage in
// the 'Demo - Physician Directory - Caspio SDK' application
// 'Physician Registration' DataPage key: '409550008f83dc4dd4554a07b7bf'
// 'Demo - Physician Directory - Caspio SDK' application key: '09d18152-7c45-44f1-a0e6-5ffe18881b60'
const caspio = require('caspio-sdk')(caspioCredentials);

async function dpGetProperties() {
  const APP_ID = '09d18152-7c45-44f1-a0e6-5ffe18881b60';
  const DP_ID = '409550008f83dc4dd4554a07b7bf';
  const dpProperties = await caspio.apps.dpPropertiesByKeys(APP_ID, DP_ID);
  console.log(dpProperties);
  return dpProperties;
}

dpGetProperties();

// sample return value
{
  Name: 'Physician Registration',
  AppKey: '409550008f83dc4dd4554a07b7bf',
  AppName: 'Demo - Physician Directory - Caspio SDK',
  Path: '/Public Interfaces',
  Type: 'WEBFORM',
  DateCreated: '2022-01-25T15:20:43.787',
  DateModified: '2022-01-25T15:20:43.837',
  CreatedBy: 'user@user.com',
  ModifiedBy: '',
  Note: ''
}

Applications.dpDeployCodeByNames(appName, dataPageName, deployMethod) ⇒ Promise.<string>

Returns deploy code (string) for a DataPage given an application name (i.e., appName), DataPage name (i.e., dataPageName), and deploy method (i.e., deployMethod), where all parameters are case-insensitive.

Kind: static method of Applications
Returns: Promise.<string> - String representing the deploy code for the specified DataPage for the specified application
See: Read the Caspio documentation on SEO deployment directions for more details.
Since: 1.0.0

ParamTypeDescription
appNamestringName of the application (case-insensitive)
dataPageNamestringName of the DataPage (case-insensitive)
deployMethod'I' | 'F' | 'U' | 'L' | 'E' | 'N' | 'P' | 'A' | 'X' | 'B' | 'Y' | 'Z'Deploy method (case-insensitive). Valid deploy methods: I (iFrame), F (Frame), U (URL), L (Link), E (Embedded), N (Net), P (PHP), A (ASP), X (ASPX), B (Facebook), Y (WordPress Frame), Z (WordPress Embed). Note: Deploy methods P, A, and X are SEO deployment methods and are only available to DataPages that meet certain criteria. If the criteria are not met, an error is thrown.

Example

// get the URL deploy code of the 'Physician Registration' DataPage
// which lives in the 'Demo - Physician Directory - Caspio SDK' application
const caspio = require('caspio-sdk')(caspioCredentials);

async function dpGetDeployCode() {
  const APP_NAME = 'Demo - Physician Directory - Caspio SDK';
  const DP_NAME = 'Physician Registration';
  const dpDeployCode = await caspio.apps.dpDeployCodeByNames(APP_NAME, DP_NAME, 'U');
  console.log(dpDeployCode);
  return dpDeployCode;
}

dpGetDeployCode();

// sample return value
'https://ab1de2fg3.caspio.com/dp/409550008f83dc4dd4554a07b7bf'

Applications.dpDeployCodeByKeys(externalKey, appKey, deployMethod) ⇒ Promise.<string>

Returns deploy code (string) for a DataPage given an application's ID (i.e., externalKey), DataPage ID (i.e., appKey), and deploy method (i.e., deployMethod), where the deployMethod is case-insensitive.

Kind: static method of Applications
Returns: Promise.<string> - String representing the deploy code for the specified DataPage for the specified application
See: Read the Caspio documentation on SEO deployment directions for more details.
Since: 1.0.0

ParamTypeDescription
externalKeystringApplication ID
appKeystringDataPage ID
deployMethod'I' | 'F' | 'U' | 'L' | 'E' | 'N' | 'P' | 'A' | 'X' | 'B' | 'Y' | 'Z'Deploy method (case-insensitive). Valid deploy methods: I (iFrame), F (Frame), U (URL), L (Link), E (Embedded), N (Net), P (PHP), A (ASP), X (ASPX), B (Facebook), Y (WordPress Frame), Z (WordPress Embed). Note: Deploy methods P, A, and X are SEO deployment methods and are only available to DataPages that meet certain criteria. If the criteria are not met, an error is thrown.

Example

// get the URL deploy code of the 'Physician Registration' DataPage
// which lives in the 'Demo - Physician Directory - Caspio SDK' application
const caspio = require('caspio-sdk')(caspioCredentials);

async function dpGetDeployCode() {
  const APP_ID = '09d18152-7c45-44f1-a0e6-5ffe18881b60';
  const DP_ID = '409550008f83dc4dd4554a07b7bf';
  const dpDeployCode = await caspio.apps.dpDeployCodeByKeys(APP_ID, DP_ID, 'U');
  console.log(dpDeployCode);
  return dpDeployCode;
}

dpGetDeployCode();

// sample return value
'https://ab1de2fg3.caspio.com/dp/409550008f83dc4dd4554a07b7bf'

Applications.dpDeployByNames(appName, dataPageName) ⇒ Promise.<{status: 200, statusText: 'OK', message: string}>

Deploy a DataPage by specifying the name of the application to which the DataPage is linked (i.e., appName) as well as specifying the name of the DataPage itself (i.e., dataPageName).

Kind: static method of Applications
Returns: Promise.<{status: 200, statusText: 'OK', message: string}> - Object with information about the attempted deployment (i.e., status, statusText, and message).
Since: 1.0.0

ParamTypeDescription
appNamestringName of the application (case-insensitive)
dataPageNamestringName of the DataPage (case-insensitive)

Example

// deploy the 'Physician Registration' DataPage which is part of the
// 'Demo - Physician Directory - Caspio SDK' application
const caspio = require('caspio-sdk')(caspioCredentials);

async function dpDeploy() {
  const APP_NAME = 'Demo - Physician Directory - Caspio SDK';
  const DP_NAME = 'Physician Registration';
  const deployResult = await caspio.apps.dpDeployByNames(APP_NAME, DP_NAME);
  console.log(deployResult);
  return deployResult;
}

dpDeploy();

// sample return value
{
  status: 200,
  statusText: 'OK',
  message: "DataPage 'Physician Registration' has been successfully deployed."
}

Applications.dpDeployByKeys(externalKey, appKey) ⇒ Promise.<{status: 200, statusText: 'OK', message: string}>

Deploy a DataPage by specifying the ID of the application to which the DataPage is linked (i.e., externalKey) as well as specifying the ID of the DataPage itself (i.e., appKey).

Kind: static method of Applications
Returns: Promise.<{status: 200, statusText: 'OK', message: string}> - Object with information about the attempted deployment (i.e., status, statusText, and message).
Since: 1.0.0

ParamTypeDescription
externalKeystringApplication ID
appKeystringDataPage ID

Example

// deploy the 'Physician Registration' DataPage which is part of the
// 'Demo - Physician Directory - Caspio SDK' application
const caspio = require('caspio-sdk')(caspioCredentials);

async function dpDeploy() {
  const APP_ID = '09d18152-7c45-44f1-a0e6-5ffe18881b60';
  const DP_ID = '409550008f83dc4dd4554a07b7bf';
  const deployResult = await caspio.apps.dpDeployByKeys(APP_ID, DP_ID);
  console.log(deployResult);
  return deployResult;
}

dpDeploy();

// sample return value
{
  status: 200,
  statusText: 'OK',
  message: 'DataPage successfully deployed.'
}

Applications.dpDisableByNames(appName, dataPageName) ⇒ Promise.<{status: 200, statusText: 'OK', message: string}>

Disable a DataPage by specifying the name of the application to which the DataPage is linked (i.e., appName) as well as specifying the name of the DataPage itself (i.e., dataPageName).

Kind: static method of Applications
Returns: Promise.<{status: 200, statusText: 'OK', message: string}> - Object with information about the disable attempt (i.e., status, statusText, and message).
Since: 1.0.0

ParamTypeDescription
appNamestringName of the application (case-insensitive)
dataPageNamestringName of the DataPage (case-insensitive)

Example

// disable the 'Physician Registration' DataPage which is part of the
// 'Demo - Physician Directory - Caspio SDK' application
const caspio = require('caspio-sdk')(caspioCredentials);

async function dpDisable() {
  const APP_NAME = 'Demo - Physician Directory - Caspio SDK';
  const DP_NAME = 'Physician Registration';
  const disableResult = await caspio.apps.dpDisableByNames(APP_NAME, DP_NAME);
  console.log(disableResult);
  return disableResult;
}

dpDisable();

// sample return value
{
  status: 200,
  statusText: 'OK',
  message: "DataPage 'Physician Registration' has been successfully disabled."
}

Applications.dpDisableByKeys(externalKey, appKey) ⇒ Promise.<{status: 200, statusText: 'OK', message: string}>

Disable a DataPage by specifying the ID of the application to which the DataPage is linked (i.e., externalKey) as well as specifying the ID of the DataPage itself (i.e., appKey).

Kind: static method of Applications
Returns: Promise.<{status: 200, statusText: 'OK', message: string}> - Object with information about the disable attempt (i.e., status, statusText, and message).
Since: 1.0.0

ParamTypeDescription
externalKeystringApplication ID
appKeystringDataPage ID

Example

// disable the 'Physician Registration' DataPage which is part of the
// 'Demo - Physician Directory - Caspio SDK' application
const caspio = require('caspio-sdk')(caspioCredentials);

async function dpDeploy() {
  const APP_ID = '09d18152-7c45-44f1-a0e6-5ffe18881b60';
  const DP_ID = '409550008f83dc4dd4554a07b7bf';
  const deployResult = await caspio.apps.dpDeployByKeys(APP_ID, DP_ID);
  console.log(deployResult);
  return deployResult;
}

dpDeploy();

// sample return value
{
  status: 200,
  statusText: 'OK',
  message: 'DataPage successfully disabled.'
}

Applications.dpDeployAllByAppName(appName) ⇒ Promise.<{status: 200, statusText: 'OK', message: string}>

Deploys all DataPages in an application where the application is specified by its case-insensitive name (i.e., appName).

Kind: static method of Applications
Returns: Promise.<{status: 200, statusText: 'OK', message: string}> - Object with information about the attempted deployment of all DataPages in the specified application (i.e., status, statusText, and message).
Since: 1.0.0

ParamTypeDescription
appNamestringName of the application (case-insensitive)

Example

// deploy all DataPages in the 'Demo - Physician Directory - Caspio SDK' application
const caspio = require('caspio-sdk')(caspioCredentials);

async function dpDeployAll() {
  const APP_NAME = 'Demo - Physician Directory - Caspio SDK';
  const deployResult = await caspio.apps.dpDeployAllByAppName(APP_NAME);
  console.log(deployResult);
  return deployResult;
}

dpDeployAll();

// sample return value
{
  status: 200,
  statusText: 'OK',
  message: "All DataPages in application 'Demo - Physician Directory - Caspio SDK' have been successfully deployed."
}

Applications.dpDeployAllByAppKey(externalKey) ⇒ Promise.<{status: 200, statusText: 'OK', message: string}>

Deploys all DataPages in an application where the application is specified by its ID (i.e., externalKey).

Kind: static method of Applications
Returns: Promise.<{status: 200, statusText: 'OK', message: string}> - Object with information about the attempted deployment of all DataPages in the specified application (i.e., status, statusText, and message).
Since: 1.0.0

ParamTypeDescription
externalKeystringApplication ID

Example

// deploy all DataPages in the 'Demo - Physician Directory - Caspio SDK' application
const caspio = require('caspio-sdk')(caspioCredentials);

async function dpDeployAll() {
  const APP_ID = '09d18152-7c45-44f1-a0e6-5ffe18881b60';
  const deployResult = await caspio.apps.dpDeployAllByAppKey(APP_ID);
  console.log(deployResult);
  return deployResult;
}

dpDeployAll();

// sample return value
{
  status: 200,
  statusText: 'OK',
  message: 'All DataPages in the specified application have been successfully deployed.'
}

Applications.dpDisableAllByAppName(appName) ⇒ Promise.<{status: 200, statusText: 'OK', message: string}>

Disables all DataPages in an application where the application is specified by its case-insensitive name (i.e., appName).

Kind: static method of Applications
Returns: Promise.<{status: 200, statusText: 'OK', message: string}> - Object with information about the attempted disabling of all DataPages in the specified application (i.e., status, statusText, and message).
Since: 1.0.0

ParamTypeDescription
appNamestringName of the application (case-insensitive)

Example

// disable all DataPages in the 'Demo - Physician Directory - Caspio SDK' application
const caspio = require('caspio-sdk')(caspioCredentials);

async function dpDisableAll() {
  const APP_NAME = 'Demo - Physician Directory - Caspio SDK';
  const disableResult = await caspio.apps.dpDisableAllByAppName(APP_NAME);
  console.log(disableResult);
  return disableResult;
}

dpDisableAll();

// sample return value
{
  status: 200,
  statusText: 'OK',
  message: "All DataPages in application 'Demo - Physician Directory - Caspio SDK' have been successfully disabled."
}

Applications.dpDisableAllByAppKey(externalKey) ⇒ Promise.<{status: 200, statusText: 'OK', message: string}>

Disables all DataPages in an application where the application is specified by its ID (i.e., externalKey).

Kind: static method of Applications
Returns: Promise.<{status: 200, statusText: 'OK', message: string}> - Object with information about the attempted disabling of all DataPages in the specified application (i.e., status, statusText, and message).
Since: 1.0.0

ParamTypeDescription
externalKeystringApplication ID

Example

// disable all DataPages in the 'Demo - Physician Directory - Caspio SDK' application
const caspio = require('caspio-sdk')(caspioCredentials);

async function dpDisableAll() {
  const APP_ID = '09d18152-7c45-44f1-a0e6-5ffe18881b60';
  const disableResult = await caspio.apps.dpDisableAllByAppKey(APP_ID);
  console.log(disableResult);
  return disableResult;
}

dpDisableAll();

// sample return value
{
  status: 200,
  statusText: 'OK',
  message: 'All DataPages in the specified application have been successfully disabled.'
}

Tables : object

Methods for tables.

Kind: global namespace

Tables.listing() ⇒ Promise.<Array.<string>>

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

Kind: static method of Tables
Returns: Promise.<Array.<string>> - Array of strings representing table names for a Caspio account
Since: 1.0.0
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',
  ...
]

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

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.

Kind: static method of Tables
Returns: Promise.<{status: 201, statusText: 'Created', message: string}> - Object with information about the attempted creation of the specified table (i.e., status, statusText, and message).
See: Caspio documentation for creating tables
Since: 1.0.0

ParamTypeDescription
tableNamestringName of the table
fieldDefinitionsArray.<Object>Definitions of the fields to be created in the new table
fieldDefinitions[].NamestringThe 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
fieldDefinitions[].TypestringThe 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'
[fieldDefinitions[].Unique]booleanDetermines whether or not uniqueness should be enforced on values entered in the field
[fieldDefinitions[].UniqueAllowNulls]booleanDetermines whether or not missing values should be allowed in a field where uniqueness is enforced
[fieldDefinitions[].Label]stringA label for the field that will be automatically used in DataPages (maximum of 255 characters allowed)
[fieldDefinitions[].Description]stringDescription of the field (maximum of 4000 characters allowed)
[fieldDefinitions[].DisplayOrder]numberOrder in which the field is displayed in a table
[fieldDefinitions[].OnInsert]booleanDetermines 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')
[fieldDefinitions[].OnUpdate]booleanDetermines 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')
[fieldDefinitions[].TimeZone]stringTime 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)
[fieldDefinitions[].Format]stringNumber format for fields with a Type of 'PREFIXED AUTONUMBER'. Possible values for Format option: '1', '01', '001', '0001', '00001', '000001', '0000001'
[fieldDefinitions[].Prefix]stringPrefix for values in a field with a Type of either 'PREFIXED AUTONUMBER' or 'RANDOM ID'.
[fieldDefinitions[].Length]numberLength 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
[fieldDefinitions[].IsFormula]booleanIndicates 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.
[fieldDefinitions[].ListField]ArrayArray 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", ... }.

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":