Follow

Do you have code samples for the API?

Yes!

 

Here are samples for several popular programming languages:

1) Node.js

var Https = require('https'),
	Querystring = require('querystring'),
	result = [],
	token = '{{ MY API KEY }}',
	params = {
	    'from': '2013-05-31',
	    'to': '2013-05-31',
	    //'orgUnit': 0,
	    //'clockOrgUnit': 0,
	    //'employee': 0,
	    //'department': 0,
//'job': 0, //'status': 'all' }, options = { host: 'api.fareclock.com', path: '/punches/?' + Querystring.stringify(params), headers: { Authorization: 'Token ' + token } }; Https.get(options, function(res) { //console.log('STATUS: ' + res.statusCode); //console.log('HEADERS: ' + JSON.stringify(res.headers)); res.on('data', function (chunk) { //console.log('BODY: ' + chunk); result.push(chunk); }); res.on('end', function(){ console.log("Result: " + result.join()); // // I have my result. Now do whatever I want to do with it. // }); }).on('error', function(e) { console.log('ERROR: ' + e); });
 
2) Python
 
try:
# python 3.4
from http.client import HTTPSConnection
from urllib.parse import urlencode
except ImportError:
# python 2.7
from httplib import HTTPSConnection
from urllib import urlencode
token = '{{ MY API KEY }}'
params = {
    'from': '2013-05-31',
    'to': '2013-05-31',
    #'orgUnit': 0,
    #'clockOrgUnit': 0,
    #'employee': 0,
    #'department': 0,
#'job': 0, #'status': 'all' } headers = { 'Authorization': 'Token ' + token }
conn = HTTPSConnection("api.fareclock.com")
conn.request('GET', "/punches/?" + urlencode(params), headers=headers)
res = conn.getresponse()
result = res.read().decode("utf-8")
conn.close()
print('Result: ' + result)
 
3) C#
 
using System;
using System.Net.Http;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string token = "{{ MY API KEY }}";
            string [] searchParams = {
              "from=2013-05-31",
              "to=2013-05-31"/*,
	      "orgUnit=0",
	      "clockOrgUnit=0",
	      "employee=0",
              "department=0",
"job=0", "status=all",*/ }; var client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", String.Format("Token {0}", token)); var response = client.GetAsync("https://api.fareclock.com/punches/?" + String.Join("&", searchParams)); var responseContent = response.Result.Content; string result = responseContent.ReadAsStringAsync().Result; Console.WriteLine(result); } } }

4) cURL
curl --include --header "Authorization: Token {{ MY API KEY }}" "https://api.fareclock.com/punches?from=2013-05-31&to=2013-05-31"
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Powered by Zendesk