dataclip
v2.0.0
Published
dataclip node client
Downloads
3
Maintainers
Readme
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 thatapiKey
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 senddata
.data
(Object or Array) - data you want to send up. WhenObject
it will treat it as a single Item. IfArray
, it will treat each entry as an Item.- Returns a
Promise
withObject
payload.form_name
(String) - form namedata
(Object or Array) - data you want to send up. WhenObject
it will treat it as a single Item. IfArray
, it will treat each entry as an Item.status
(Integer) - HTTP status codemessage
(String) - Any message from server. (if error it will show the error message)error
(Boolean) - Will be present ifstatus > 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 form—there is no pagination.
formName
(String; optional; default: 'default') - form from which you want to fetch data.- Returns a
Promise
withObject
payloadstatus
(Integer) - HTTP status codeform_name
(String) - form namedata
(Array of Items) - All Items in the form.error
(Boolean) - Will be present ifstatus >= 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
)
})