Perl Example

NOTE: Get an APIKey.

Some Basic Setup

Here we load our required modules, and ask the user to give us some input from the command line.

 #!/usr/bin/env perl

 use strict;
 use Wing::Client;
 use Getopt::Long;
 use feature 'say';

 my $url = "https://tabletop.events";
 my $conid;
 my $username;
 my $password;
 my $api_key;

 GetOptions(
    "conid=s"       => \$conid,
    "username=s"    => \$username,
    "passwword=s"   => \$password,
    "api_key=s"     => \$api_key,
 );

 unless ($conid && $username && $password && $api_key) {
    say "Usage: $0 --conid=xxx --username=MYUSER --password=MYPASS --api_key=xxx";
    exit;
 }

 my $wing = Wing::Client->new(uri => $url);

Log In

Here we establish a user session. We could store this session to use over and over so that we don't have to enter our username and password and api_key on every execution of the program.

 my $session = $wing->post('session', { username => $username, password => $password, api_key_id => $api_key });

Fetch Registrant Badges

Fetch badges for our registered users.

 my $data = { paging => { total_pages => 10000, next_page_number => 1 }};     # giving ourselves some
                                                                              # initial data so the loop
                                                                              # doesn't die before we've
                                                                              # fetched anything
 my @badges;
 while ($data->{paging}{total_pages} >= $data->{paging}{next_page_number}) {
     $data = $wing->get('/api/convention/'.$conid.'/badges', {                # build the url to the
                                                                              # badges API, note that
                                                                              # Wing::Client does
                                                                              # https://tabletop.events
                                                                              # for us

         verified                    => 1,                                    # we only want badges that
                                                                              # have actually completed
                                                                              # the checkout process

         print_count                 => 0,                                    # only return them if they
                                                                              # haven't already been
                                                                              # printed

         session_id                  => $session->{id},                       # have to give it our
                                                                              # session_id since we're
                                                                              # asking for privileged
                                                                              # data

         _page_number                => $data->{paging}{next_page_number},    # we'll use the paging data
                                                                              # returned by the api to
                                                                              # loop until we have all
                                                                              # the badge data

         _items_per_page             => 100,                                  # get 100 badges per
                                                                              # request

         _include_related_objects    => ['conventionreceipt'],                # let's include the
                                                                              # convention receipt object
                                                                              # in our result set

         _include_relationships      => 1,                                    # let's get the
                                                                              # relationship urls so that
                                                                              # we know how to fetch the
                                                                              # tickets for each badge

         _order_by                   => 'badge_number',                       # override whatever the
                                                                              # default ordering for
                                                                              # badges would be
     });
     foreach my $badge (@{$data->{items}}) {
        push @badges, $badge;
     }
 }

Fetch Registrant Tickets

Given that we fetched a list of badges we might want to download the tickets associated with those badges as well.

 my $badge = pop @badges;
 my $data = { paging => { total_pages => 10000, next_page_number => 1 }};
 my @tickets;
 while ($data->{paging}{total_pages} >= $data->{paging}{next_page_number}) {
     $data = $wing->get($badge->{_relationships}{tickets}, {                # let's use the URL the badge
                                                                            # provides for us for
                                                                            # fetching tickets

         verified                    => 1,                                  # only get tickets that
                                                                            # completed the checkout
                                                                            # process

         print_count                 => 0,                                  # only return them if they
                                                                            # haven't already been
                                                                            # printed

         session_id                  => $session->{id},                     # gotta give our creds to
                                                                            # fetch privileged data

         _page_number                => $data->{paging}{next_page_number},  # use the service's paging
                                                                            # data to iterate through all
                                                                            # the tickets

         _items_per_page             => 100,                                # fetch 100 tickets per
                                                                            # request

         _include_related_objects    => ['conventionreceipt','event'],      # include the receipt object
                                                                            # and the event object in our
                                                                            # result set

         _order_by                   => 'ticket_number',                    # override the default
                                                                            # ordering for tickets
     });
     foreach my $ticket (@{$data->{items}}) {
        push @tickets, $ticket;
     }
 }

Mark Badges and Tickets Printed

If you're using an external printing service to print your badges and tickets, then you may want to be able to mark them printed with your own program.

 $wing->post('convention/'.$conid.'/print', {
    session_id      => $session->{id},
    badges          => ['xxx','xxx','xxx','xxx','xxx'],         # the list of badge ids to mark printed
    tickets         => ['xxx','xxx','xxx','xxx','xxx'],         # the list of ticket ids to mark printed
 });