Skip to content

Instantly share code, notes, and snippets.

@bbattista
Created September 18, 2014 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbattista/67049086f4c7dd26507e to your computer and use it in GitHub Desktop.
Save bbattista/67049086f4c7dd26507e to your computer and use it in GitHub Desktop.
TSHEETS API calls from Perl
#!/usr/bin/perl
# This example shows how to connect to the Tsheets API using Perl
#
use HTTP::Request::Common;
use LWP::UserAgent;
use JSON;
use Data::Dumper;
# Here's an example query to the API that reports the JSON jobcodes result into a hash array
example_query(); # list jobcodes
sub example_query {
# connect with the tokenized HTTP header
my $req = HTTP::Request->new( 'GET' => "https://rest.tsheets.com/api/v1/jobcodes" );
$req->header( 'Authorization' => 'Bearer <Access Token>'); # use your API-created user token
# get the server response
my $lwp = LWP::UserAgent->new;
my $response = $lwp->request($req);
# parse response into JSON string
my $results = JSON->new;
my $json = $results->pretty->encode($results->decode($response->decoded_content ));
# decode JSON into Perl hash array
my $decoded = decode_json($json);
# print the array contents
print Dumper($decoded);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment