Working with Web Services > Interacting with patron data using Perl > Interacting with patron data using REST

Interacting with patron data using REST

For the PatronSamples application, you need to provide values for some of the variables. In addition to the BASE_URL, you need to specify a valid userID, password, and userLibrary for a patron account on your Symphony system; a couple valid itemIDs - one for an item that the specific patron already has checked out and can renew and one for an item that the specific patron has authority and capability to place a hold on; and the web services clientID.

The first REST subroutine logs in the specified user and returns a session token. On lines 252-253, we set up the variables used for the HTTP POST command and for handling the returned data in XML format. On line 255, we set the application to be read for the UTF-8 encoded data that gets returned.

Then, in lines 256-258, we set up the request.

my $response = $ua->post($BASE_URL.'rest/security/loginUser',
{clientID=>$clientID,
login=>$userID, password=>$password});

This call for loginUser uses the login information specified in variables. Typically, you would get this information from the user through a web page form or other type of input to the application.

After checking for success to the request and converting the XML data to an internal representation for Perl, the subroutine returns the session token value so that other privileged operations can use it:

return $data->{sessionToken};

This session token is then used for the next subroutine, lookupMyAccountInfoRest, which returns the itemID of an item that the user has checked out.

On lines 279-281, we make the request:

my $response = $ua->post($BASE_URL.'rest/patron/lookupMyAccountInfo',
{clientID=>$clientID, sessionToken=>$sessionToken,
includePatronCheckoutInfo=>'ALL'});

The lookupMyAccountInfo request is part of the patron service, as indicated in the endpoint address. It also requires a client ID and session token, which have been passed through as variables. We have decided to get all the patron checkout information for this request. The lookupMyAccountInfo operation can retrieve lots of different kinds of data about the patron account. Since we only care about getting the checkout data for this application, restricting the result to one area is more efficient.

After checking the response and converting the XML, line 289 returns the itemID of a checked out item.

return $data->{patronCheckoutInfo}->{itemID};

This code assumes that there is at least one checked out item. This line finds the value from the ItemID node and assigns it to the returned data.

The next subroutine then takes the session token and the item ID and renews the item. This code assumes that the item can be renewed by this patron account. Lines 303-305 perform the request.

my $response = $ua->post($BASE_URL.'rest/patron/renewMyCheckout',
{clientID=>$clientID, sessionToken=>$sessionToken,
itemID=>$checkoutItemID});

The renewMyCheckout operation takes either a titleID or itemID.

The subroutine checks for a success message in the response and then prints the data from the response.

The next subroutine, createMyHoldRequest, is passed in the session token so that the patron can create a hold request on an item.

On lines 321-323, we make the hold request.

my $response = $ua->post($BASE_URL.'rest/patron/createMyHold',
{clientID=>$clientID, sessionToken=>$sessionToken,
itemID=>$hold2ItemID, pickupLibraryID=>$userLibrary});

The createMyHold operation requires a valid client ID and session token, as well as an item ID or title ID and a pickup location.

After checking for success in the response, the subroutine prints the returned HoldKey.

Finally, the last subroutine, logoutRest, uses the session token to log out the patron.

The request is made in lines 340-341.

my $response = $ua->post($BASE_URL.'rest/security/logoutUser',
{clientID=>$clientID, sessionToken=>$sessionToken});

The logoutUser operation requires a valid session token and client ID.

The subroutine completes by displaying the response data.

See the SearchingSamples application for the complete code to achieve all this patron functionality.

 

 


© 2009-2012 SirsiDynix