GithubHelp home page GithubHelp logo

knack-sdk's Introduction

knack-sdk

An unofficial SDK for working with the Knack API. For more information about Knack and their products click here, and for documentation on their API click here.

Install

npm install knack-sdk

Setup and Usage

import Knack from 'knack-sdk'

const knack = new Knack({ appId: 'your-app-id', apiKey: 'your-api-key' })

const record = await knack.createRecord({ objectKey: 'object_123', data: { field_234: 'field data' } })
const foundRecord = await knack.getRecord({ objectKey: 'object_123', recordId: record.id })
const updatedRecord = await knack.updateRecord({ objectKey: 'object_123', recordId: record.id, data: { field_234: 'better field data' } })
const { deleted } = await knack.deleteRecord({ objectKey: 'object_123', recordId: record.id })

API

constructor

The constructor function of the Knack Class. It only requires your apiKey and apiId. Returns an instance of the Knack Class.

new Knack({ appId: 'your-app-id', apiKey: 'your-api-key' })

authenticate

Authenticate a user via their email and password, and stores their token for internal use.

knack.authenticate({ email: '[email protected]', password: 'password' })

createRecord

Creates a record in the Object of your choice.

const record = await knack.createRecord({ objectKey: 'object_123', data: { field_234: 'field data' } })

createViewRecord

Creates a record in the Object of your choice, limited to a User's view.

const record = await knack.createViewRecord({ sceneKey: 'scene_123', viewKey: 'scene_134', data: { field_234: 'field data' } })

deleteRecord

Deletes a record by object key and record id.

const { deleted } = await knack.deleteRecord({ objectKey: 'object_123', recordId: '123abc' })

deleteViewRecord

Deletes a record based on a users' allowed actions.

const { deleted } = await knack.deleteRecord({ sceneKey: 'scene_123', viewKey: 'scene_134', recordId: '123abc' })

getRecord

Gets a record by object key and record id.

const record = await knack.getRecord({ objectKey: 'object_123', recordId: '123abc' })

getRecords

Gets record by object key and filters. Supports pagination and sorting.

const {
  current_page,
  records,
  total_pages,
  total_records
} = await knack.getRecords({
  objectKey: 'object_123',
  filters: {
    match: 'and',
    rules: [{
      field: 'field_31',
      operator: 'contains',
      value: 'from',
      field_name: 'Companies Name'
    }]
  }
})

updateRecord

Updates a record for a type of Object.

const record = await knack.updateRecord({ objectKey: 'object_123', recordId: '123abc', data: { field_234: 'new field data' } })

updateViewRecord

Updates a record of a type of Object, limited to a User's view.

const record = await knack.updateViewRecord({ sceneKey: 'scene_123', viewKey: 'scene_134', recordId: '123abc', data: { field_234: 'new field data' } })

uploadFile

Uploads a file or image to a record in a designated field. File must be a readable stream.

const file = fs.createReadStream('path/to/your/file.jpg')
const record = await knack.uploadFile({ objectKey: 'object_123', fieldKey: 'field_234', file })

knack-sdk's People

Contributors

tsiege avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.