Skip to content

Instantly share code, notes, and snippets.

@joshed-io
Created March 1, 2013 11:14
Show Gist options
  • Save joshed-io/5063992 to your computer and use it in GitHub Desktop.
Save joshed-io/5063992 to your computer and use it in GitHub Desktop.
Feed Ralph Pizza - Publish an event to the Keen IO API with node.js and the npm request package
// install the 'request' package first with 'npm install request'
var request = require('request');
// replace with your Keen IO project token
var projectToken = "501999234-FAKE-PROJECT-ID";
// create a sample JSON event for an event collection
var eventCollection = "meals";
var sampleEvent = {
username: "ralph",
food: "pizza"
};
// calculate the API URL
var apiUrl = "https://api.keen.io/3.0/projects/" + projectToken + "/events/" + eventCollection;
// perform a POST to the API using the request package
request({
uri: apiUrl,
method: "POST",
json: sampleEvent
}, function(error, response, body) {
// response will be { "created": true } if successful
// console.log(body);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment