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.
npm install knack-sdk
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 })
constructor
#authenticate
#createRecord
#createViewRecord
#deleteRecord
#deleteViewRecord
#getRecord
#getRecords
#updateRecord
#updateViewRecord
#uploadFile
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 a user via their email and password, and stores their token for internal use.
knack.authenticate({ email: 'user@email.com', password: 'password' })
Creates a record in the Object of your choice.
const record = await knack.createRecord({ objectKey: 'object_123', data: { field_234: 'field data' } })
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' } })
Deletes a record by object key and record id.
const { deleted } = await knack.deleteRecord({ objectKey: 'object_123', recordId: '123abc' })
Deletes a record based on a users' allowed actions.
const { deleted } = await knack.deleteRecord({ sceneKey: 'scene_123', viewKey: 'scene_134', recordId: '123abc' })
Gets a record by object key and record id.
const record = await knack.getRecord({ objectKey: 'object_123', recordId: '123abc' })
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'
}]
}
})
Updates a record for a type of Object.
const record = await knack.updateRecord({ objectKey: 'object_123', recordId: '123abc', data: { field_234: 'new field data' } })
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' } })
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 })