npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

knackhq-client

v0.1.1

Published

KnackHQ API Client Module

Downloads

13

Readme

extremely simple node knackhq client

How do I use it?

Very carefully!

First install into your project with:

npm install knackhq-client --save

Next, add it into your code somewhere:

var knack = require('knackhq-client');

Now you're ready to authenticate! You can authenticate as the root user with:

knack.authenticate({ apikey: 'your api key', appid: 'your app id' }, function(error) {
  if (error) {
    // failed to log in!
  }
});

Or as an app user with:

knack.authenticate({ email: 'user email', password: 'user password', appid: 'your app id' }, function(error) {
  if (error) {
    // failed to log in!
  }
});

I'm logged in. Now what the heck do I do?

I'm glad you asked. The thing to do from here is to start updating, editing, creating, and searching for records. So let's try it:

create a record

To do this, you'll need the object key of the object you want to create a record in. We're calling this object_key here, as well as whatever fields you want to fill with data. I'm referring to that as field_key:

knack.create_record({ object_key: object_key, body: {
  field_key: 'my data'
} }, function(error, data) {
  // should have an error here if there was a problem, or the record data in the data object if the add was successful
});

edit a record

To do this, you'll need the object key of the object you want to create a record in. We're calling this object_key here, as well as whatever fields you want to update the data of. I'm referring to that as field_key again. Lastly, we'll need the ID of the record we want to update, the record_id:

knack.update_record({ object_key: object_key, record_id: record_id, body: { field_key: 'my updated data' } }, function(err, record) {
  // should have an error here if there was a problem, or the record data in the data object if the add was successful
});

delete a record

To do this, you'll need the object key of the object you want to create a record in. We're calling this object_key here. We'll also need the ID of the record we want to delete, the record_id:

knack.delete_record({ object_key: object_key, record_id: record_id }, function(err, status) {
  // should have an error here if there was a problem, or a success status if the record was deleted
});

find a record

Finding a record optionally involves involves building a filter array that Knack will match records to. More about filters here. Again, object_key and field_key are used. The rows_per_page option will specify how many records you would like to have returned. If we're interested in getting the next page of results, we can increment the page variable, which starts at page 0:

var filters = filters: [{ field: field_key, operator: 'is', value: 'my criteria' }] };
knack.find_record({ object_key: object_key, rows_per_page: 500, page: page, filters: filters }, function(error, data) {
  if (error) {
    // something bad happened!
  }

  if (!data.records || !data.records.length) {
    // no records
  }
});

upload an image

Note: this is actually a 2 step process that will use 2 api calls in your knack plan

filename is the local path and filename to the file or image you want to upload. object_key is the object key of the where the record containing the file will be stored. field_key is the field that the file will be attached to (of type File or Image), and body is the body of the entry if you want to include additional information (this is also doing a create_record call!)

knack.upload_image({ filename: filename, object_key: object_key, field_key: field_key, body: {
  field_key: 'some other info'
} }, function(err, status) {
  // should have an error here if there was a problem, or a success status if the record was deleted
});

Method Signatures

knack.authenticate(options, callback)

options: { apikey: , appid: } OR { email: , password: , appid }
callback: function(error)

knack.authenticate_user(options, callback)

options: { email: , password: , appid }
callback: function(error)

knack.request(options, callback)

options: { path: , method: , body: }
callback: function(error, response_object)

knack.objects(callback)

callback: function(error, response_object)

knack.object_records(options, callback)

options: { object_key: }
callback: function(error, response_object)

knack.create_record(options, callback)

options: { object_key: , body: {} }
callback: function(error, response_object)

knack.delete_record(options, callback)

options: { object_key: , record_id: }
callback: function(error, response_object)

knack.find_record(options, callback)

options: { { object_key: , rows_per_page: , page: filters: [{}] } }
callback: function(error, response_object)

knack.update_record(options, callback)

options: { { object_key: , record_id: , body: {} } }
callback: function(error, response_object)

knack.upload_image(options, callback)

options: { field_key: , filename: , body: {} }
callback: function(error, response_object)