Created
September 18, 2014 22:58
-
-
Save bbattista/67049086f4c7dd26507e to your computer and use it in GitHub Desktop.
TSHEETS API calls from Perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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