This is the official node.js API client for Pageclip.
npm install --save pageclip
Basic usage:
const Pageclip = require('pageclip')
let pageclip = new Pageclip(yourAPIKey)
// Send an item up to Pageclip
pageclip.send({some: 'data'}).then((response) => {
console.log(response.status, response.data) // => 200, [{payload: {...}}]
}).then(() => {
// Fetch all items
return pageclip.fetch()
}).then((response) => {
console.log(response.status, response.data) // => 200, [{payload: {...}}]
})
Create a Pageclip Object.
apiKey
(String) - found in the web interface of Pageclip. Note thatapiKey
must be the private API key. Your public siteKey will not work!
const Pageclip = require('pageclip')
let pageclip = new Pageclip('abc123ABC123abc123abc123abc12345')
Send data to Pageclip.
formName
(String; optional; default: 'default') - form to which you want to attachdata
.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
let pageclip, promise, data
pageclip = new Pageclip('abc123ABC123abc123abc123abc12345')
// Send one item
data = {some: 'data'}
promise = pageclip.send(data).then((response) => {
console.log(
response.status, // 200
response.form, // 'default'
response.data // [Item({some: 'data'})]
)
})
// Send multiple items
data = [{some: 'data'}, {some: 'otherdata'}]
promise = pageclip.send(data).then((response) => {
console.log(
response.status, // 200
response.form, // 'default'
response.data // [Item({some: 'data'}), Item({some: 'otherdata'})]
)
})
// Send one item to a named form
data = {email: '[email protected]'}
promise = pageclip.send('mailinglist', data).then((response) => {
console.log(
response.status, // 200
response.form, // 'mailinglist'
response.data // [Item({email: '[email protected]'})]
)
})
Retrieve your data from Pageclip. At this time, it returns all items in the form—there is no pagination or slicing.
formName
(String; optional; default: 'default') - form from which you want to fetch data.- Returns a
Promise
withObject
payload
let pageclip, promise
pageclip = new Pageclip('api_abc123ABC123abc123abc123abc12345')
// Fetch items from the default form
promise = pageclip.fetch().then((response) => {
console.log(
response.status, // 200
response.form, // 'default'
response.data // [Item]
)
})
// Fetch items from a named form
promise = pageclip.fetch('mailinglist').then((response) => {
console.log(
response.status, // 200
response.form, // 'mailinglist'
response.data // [Item, Item]
)
})
All Item objects returned by the API will have the following shape:
{
itemEid: 'abc123ABC123abc123abc123abc12345',
createdAt: '1983-06-29T14:48:00Z', // ISO date
payload: {
// the data from the user
}
}
API errors will return a response with an errors
key that contains an Array of objects:
{
errors: [{
message: 'Name is required',
property: 'name' // If the error is associated with a property
}, ...]
}