1

Geckoboard offers this documentation to connect to their datasets API, which you can see the implementation below.

var API_KEY = 'API_KEY';

var gb = require('geckoboard')(
  API_KEY
);


gb.datasets.findOrCreate(
  {
    id: 'sales.by_day',
    fields: {
      quantity: {
        type: 'number',
        name: 'Number of sales'
      },
      gross: {
        type: 'money',
        name: 'Gross value of sales',
        currency_code: "USD"
      },
      date: {
        type: 'date',
        name: 'Date'
      }
    }
  },
  function (err, dataset) {
    if (err) {
      console.error(err);
      return;
    }
    dataset.put(
      [
        { date: '2016-01-01', quantity: 819, gross: 2457000 },
        { date: '2016-01-02', quantity: 409, gross: 1227000 },
        { date: '2016-01-03', quantity: 164, gross: 492000 }
      ],
      function (err) {
        if (err) {
          console.error(err);
          return;
        }

        console.log('Dataset created and data added');
      }
    );
  }
);

I'd like to see if there is a way to post this additional data via python (not using node.js). Would something like this be possible or must I use mode?

[
    { date: '2017-01-01', quantity: 1213, gross: 23423 },
    { date: '2017-01-02', quantity: 111, gross: 1313123 },
    { date: '2017-01-03', quantity: 333, gross: 21314 }
]
Marat
  • 15,215
  • 2
  • 39
  • 48
Chris
  • 5,444
  • 16
  • 63
  • 119
  • I think you are looking for something like this: https://pypi.python.org/pypi/geckoboard/0.8.6 – Stats4224 Feb 21 '17 at 19:55
  • There are so many ways to do that: `requests`, `httplib`, `urllib`, etc. Did you try anything so far? – Marat Feb 21 '17 at 19:55
  • Also see related post: http://stackoverflow.com/questions/31133708/python-script-to-post-data-to-geckoboard – Stats4224 Feb 21 '17 at 19:56
  • There is also a brand-new **R** package to communicate with the Geckoboard **Dataset** as well as **Custom Widget** API. See [RGeckoboard package on github](https://github.com/ploner/RGeckoboard). – lambruscoAcido Jul 11 '18 at 08:11

1 Answers1

2

Update: Geckoboard now has their own official Python client library for their Datasets API https://github.com/geckoboard/geckoboard-python


It's definitely possible to use Python with Geckoboard's Datasets API. You can use any language or platform that can perform HTTPS requests with JSON - though Geckoboard has only released official library's for Ruby and Node so far.

Edit: I made a quick example below, but later found this: https://github.com/helium/geckoboard-python/

In short you just need to:

  • PUT with the a schema object to https://api.geckoboard.com/datasets to create a dataset
  • PUT with the a data array to https://api.geckoboard.com/datasets/:id to replace all data in a dataset
  • POST with the a data array to https://api.geckoboard.com/datasets/:id to append to the data in a dataset
  • DELETE to https://api.geckoboard.com/datasets/:id to delete a dataset

These requests are outlined at -- https://developer.geckoboard.com/api-reference/curl/

I haven't written much Python, so this may not be very Pythonic, but here's a way you could create a Geckoboard library in Python to do this for you, using the requests library underneath:

import requests

  class Geckoboard(object):
          def __init__(self, api_key):
                  self.api_key = api_key

          def create(self, name, schema):
                  url = 'https://api.geckoboard.com/datasets/%s' % name
                  return requests.put(url, json=schema, auth=(self.api_key, ''))

          def delete(self, name):
                  url = 'https://api.geckoboard.com/datasets/%s' % name
                  return request.delete(url, auth=(self.api_key, ''))

          def replace(self, name, data):
                  url = 'https://api.geckoboard.com/datasets/%s/data' % name
                  return requests.put(url, json=data, auth=(self.api_key, ''))

          def append(self, name, data):
                  url = 'https://api.geckoboard.com/datasets/%s/data' % name
                  return requests.post(url, json=data, auth=(self.api_key, ''))
  • 1
    Thanks! I tried to use the replace function and inputted this as the data: [{'date':'2016-01-01','quantity': 819,'gross':2457000 },{'date':'2016-01-02','quantity':409,'gross':1227000 },{'date':'2016-01-03','quantity':164,'gross': 492000}]. However, I receive the following error: {u'error': {u'message': u'Invalid JSON was received by the server.'}} – Chris Feb 21 '17 at 23:30
  • 1
    Think I figured it out! The data input should be {'data':[{'date':'2016-01-01','quantity': 819,'gross':2457000 },{'date':'2016-01-02','quantity':409,'gross':1227000 },{'date':'2016-01-03','quantity':164,'gross': 492000}]} – Chris Feb 21 '17 at 23:38