2.0.0 • Published 2 years ago

dataclip v2.0.0

Weekly downloads
7
License
MIT
Repository
github
Last release
2 years ago

DataClip-node

This is the official node.js API client for Dataclip.

Usage

npm i dataclip

API

Dataclip (apiKey)

Create a DataClip Object.

  • apiKey (String) - found in the web interface of DataClip. Note that apiKey must be the private API key. Your public siteKeys and formkeys will not work!
const Dataclip = require('dataclip')
let dataclip = new Dataclip('api_12345678909876')

Basic usage:

const Dataclip = require('dataclip')
let dataclip = new Dataclip(your_api_key)

// Send an item up to DataClip
dataclip.send({label: 'your_data'}).then((response) => {
  console.log(response) // => 201, [{status: {...}}]
}).then(() => {
  // Fetch all form items 
  return dataclip.fetch()
}).then((response) => {
  console.log(response.status, response.data) // => 200, [{status: {...}}]
})

Dataclip::send(formName, data)

Send data to Dataclip.

  • formName (String; optional; default: 'default') - form to which you want to send data.
  • data (Object or Array) - data you want to send up. When Object it will treat it as a single Item. If Array, it will treat each entry as an Item.
  • Returns a Promise with Object payload.
    • form_name (String) - form name
    • data (Object or Array) - data you want to send up. When Object it will treat it as a single Item. If Array, it will treat each entry as an Item.
    • status (Integer) - HTTP status code
    • message (String) - Any message from server. (if error it will show the error message)
    • error (Boolean) - Will be present if status > 400.
let dataclip, data
dataclip = new Dataclip('api_1234567890987456')

// Send single item
data = {label: 'data'}
dataclip.send(data).then((response) => {
  console.log(
    response.status, // 201
    response.form_name, // 'default'
    response.message, // 'data saved successfully'
    response.error, //false
    response.data, // [data{label: 'data'}]
  )
})

// Send multiple items
data = [{label_1: 'data_1'}, {label_2: 'data_2'}]
dataclip.send(data).then((response) => {
  console.log(
    response.status, // 201
    response.form_name, // 'default'
    response.message, // 'data saved successfully'
    response.error, //false
    response.data, // [Item({label_1: 'data_1'}), Item({label_2: 'data_2'})]
  )
})

// Send one item to a specific named form
data = {contact: '+94 77 84 22728'}
dataclip.send('my_cotact_form', data).then((response) => {
  console.log(
    response.status, // 200
    response.form_name, // 'my_cotact_form'
    response.message, // 'data saved successfully'
    response.error, //false
    response.data, // [data{label: 'data'}]

  )
})

Dataclip::fetch(formName)

Retrieve your data from Dataclip. At this time, it returns all items in the formthere is no pagination.

  • formName (String; optional; default: 'default') - form from which you want to fetch data.
  • Returns a Promise with Object payload
    • status (Integer) - HTTP status code
    • form_name (String) - form name
    • data (Array of Items) - All Items in the form.
    • error (Boolean) - Will be present if status >= 400.
    • message (String) - Any message from server. (if error it will show the error message)
    • last_entry (Time stamp) - Data and time of last data entry
let dataclip
dataclip = new Dataclip('api_1234567890987456')

// Fetch items from the default form
dataclip.fetch().then((response) => {
  console.log(
    response.status, // 200
    response.form_name, // 'default'
    response.data,    // [Item, Item]
    reponse.message, //success
    response.error //false
  )
})

// Fetch items from a named form
dataclip.fetch('my_contact_form').then((response) => {
  console.log(
    response.status, // 200
    response.form_name, // 'my_contact_form'
    response.data,    // [Item,Item]
    reponse.message, //success
    response.error //false
  )
})
2.0.0

2 years ago

1.0.1

4 years ago

1.0.0

4 years ago