New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

knack-api

Package Overview
Dependencies
Maintainers
2
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knack-api

Knack API

latest
Source
npmnpm
Version
2.0.3
Version published
Maintainers
2
Created
Source

knack-api

View-based API wrapper for the Knack platform. Provides CRUD operations (GET, POST, PUT, DELETE) with automatic pagination, retry logic, and built-in session management.

For object-based requests, see knack-object-api.

Installation

npm install knack-api

Import

// JavaScript
const { knack_api } = require('knack-api');

// TypeScript
import { knack_api } from 'knack-api/ts';

API

All methods accept a settings object and return a Promise.

host and subdomain are optional on all request types. By default, requests go to https://api.knack.com. Setting host: 'knackly' and subdomain: 'api' would send requests to https://api.knackly.com.

knack_api.get(settings)

Retrieves records from a view. Automatically paginates through all available pages.

const results = await knack_api.get({
  sceneKey: 'scene_1',
  viewKey: 'view_1',
  host: 'knackly',
  subdomain: 'api',
});

knack_api.post(settings)

Creates a new record.

const result = await knack_api.post({
  sceneKey: 'scene_1',
  viewKey: 'view_1',
  payload: { field_1: 'value' },
  retry: true,
});

knack_api.put(settings)

Updates an existing record.

const result = await knack_api.put({
  sceneKey: 'scene_1',
  viewKey: 'view_1',
  recordId: '6123abc456def',
  payload: { field_1: 'updated value' },
  retry: true,
});

knack_api.deletion(settings)

Deletes a record.

const result = await knack_api.deletion({
  sceneKey: 'scene_1',
  viewKey: 'view_1',
  recordId: '6123abc456def',
  retry: true,
});

Settings Reference

GET Settings

ParameterTypeRequiredDefaultDescription
sceneKeystringYesScene identifier (e.g. 'scene_1')
viewKeystringYesView identifier (e.g. 'view_1')
recordIdstringNoFetch a single record by ID
filtersobjectNoFilter rules (see Filters)
sortobject | object[]NoSort configuration (see Sorting)
pagenumberNo1Starting page number
rowsPerPagenumberNo1000Records per page (max 1000)
recordLimitnumberNoMaximum total records to retrieve
retrybooleanNoEnable retry on failure (up to 3 attempts)
cbfunctionNoCallback invoked after each page request
isPublicbooleanNofalseSkip authentication for public views
contextobjectNoContext for views that require a parent record ID (see Context)
hoststringNo'knack'Host used in the request URL
subdomainstringNo'api'Subdomain used in the request URL

POST Settings

ParameterTypeRequiredDescription
sceneKeystringYesScene identifier
viewKeystringYesView identifier
payloadobjectYesField values for the new record
retrybooleanYesEnable retry on failure
isPublicbooleanNoSkip authentication for public views
hoststringNoHost used in the request URL
subdomainstringNoSubdomain used in the request URL

PUT Settings

ParameterTypeRequiredDescription
sceneKeystringYesScene identifier
viewKeystringYesView identifier
recordIdstringYesID of the record to update
payloadobjectYesField values to update
retrybooleanYesEnable retry on failure
isPublicbooleanNoSkip authentication for public views
hoststringNoHost used in the request URL
subdomainstringNoSubdomain used in the request URL

DELETE Settings

ParameterTypeRequiredDescription
sceneKeystringYesScene identifier
viewKeystringYesView identifier
recordIdstringYesID of the record to delete
retrybooleanYesEnable retry on failure
isPublicbooleanNoSkip authentication for public views
hoststringNoHost used in the request URL
subdomainstringNoSubdomain used in the request URL

Filters

Pass a filters object to narrow GET results.

const results = await knack_api.get({
  sceneKey: 'scene_1',
  viewKey: 'view_1',
  filters: {
    match: 'and',
    rules: [
      { field: 'field_1', operator: 'contains', value: 'search term' },
      { field: 'field_2', operator: 'is not blank' },
    ],
  },
});

Available Operators

OperatorDescription
isExact match
is notNot equal
is blankField is empty
is not blankField is not empty
containsString contains value
does not containString does not contain value
starts withString starts with value
ends withString ends with value
is anyValue is in a list
higher thanNumeric greater than
lower thanNumeric less than
nearLocation proximity (use range for distance)
is todayDate is today
is today or beforeDate is today or earlier
is today or afterDate is today or later
is before todayDate is before today
is after todayDate is after today
is beforeDate is before value
is afterDate is after value
is during the currentDate during current period
is during the previousDate during previous period
is during the nextDate during next period
is before the previousDate before previous period
is after the nextDate after next period
is before current timeTime is before now
is after current timeTime is after now

Sorting

Sort accepts a single object or an array for multi-field sorting.

// Single sort
const results = await knack_api.get({
  sceneKey: 'scene_1',
  viewKey: 'view_1',
  sort: { field: 'field_1', order: 'asc' },
});

// Multi-field sort
const results = await knack_api.get({
  sceneKey: 'scene_1',
  viewKey: 'view_1',
  sort: [
    { field: 'field_1', order: 'asc' },
    { field: 'field_2', order: 'desc' },
  ],
});

Include / Exclude Fields

Filter which fields are returned from a GET request using .include() or .exclude().

// Only return specific fields
const results = await knack_api.get(settings).include(['field_1', 'field_2']);

// Return all fields except those specified
const results = await knack_api.get(settings).exclude(['field_3']);

Pagination

GET requests automatically paginate through all available pages and return the combined results. You can control this behavior with:

  • rowsPerPage — Records per request (max 1000, default 1000).
  • recordLimit — Stop after retrieving this many total records.
  • page — Start from a specific page (default 1).
// Fetch up to 200 records, 50 per request
const results = await knack_api.get({
  sceneKey: 'scene_1',
  viewKey: 'view_1',
  rowsPerPage: 50,
  recordLimit: 200,
});

Callback

The cb parameter is called after each individual page request. This is useful for tracking progress when fetching large datasets.

const results = await knack_api.get({
  sceneKey: 'scene_1',
  viewKey: 'view_1',
  cb: (data) => {
    console.log(`Received ${data.records.length} records`);
  },
});

All records are still accumulated in memory and returned in the final resolved promise.

Public Views

Set isPublic: true to skip user token verification. Use this for views that are accessible without authentication.

const results = await knack_api.get({
  sceneKey: 'scene_1',
  viewKey: 'view_1',
  isPublic: true,
});

Available on get, post, and put methods.

Context

Some views require a parent record ID to fetch related data. Pass a context object where the key follows the pattern {page-slug}_id and the value is the record ID.

const results = await knack_api.get({
  sceneKey: 'scene_1',
  viewKey: 'view_1',
  context: {
    'my-page-slug_id': '6123abc456def',
  },
});

Retry Logic

When retry is enabled, failed requests are automatically retried up to 3 times before rejecting the promise.

Session Management

For authenticated requests, the library verifies the user's session token before making API calls. If the session has expired, a modal is displayed prompting the user to log back in, and the promise is rejected with "User token is invalid.".

License

ISC

Keywords

Knack

FAQs

Package last updated on 19 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts