Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewrjones/615033 to your computer and use it in GitHub Desktop.
Save andrewrjones/615033 to your computer and use it in GitHub Desktop.
Extract data from SharePoint list - with paging
#!perl
use strict;
use warnings;
use LWP::UserAgent;
use LWP::Debug;
use SOAP::Lite on_action => sub { "$_[0]$_[1]"; };#, +trace => 'debug';
import SOAP::Data 'name', 'value';
# you will need to change these details
my $soap = SOAP::Lite->proxy('http://example.com/MySite/_vti_bin/lists.asmx', keep_alive => 1);
$soap->proxy->credentials('example.com:80', '', 'username', 'password');
$soap->schema->useragent( LWP::UserAgent->new(keep_alive => 1) );
$soap->uri('http://schemas.microsoft.com/sharepoint/soap/');
# this holds the arguments for server side paging
my $nextpage;
do {
my $in_listName = name('listName' => 'Name or ID of list');
my $in_rowLimit = name('rowLimit' => 1000); # amount to retrieve per page
# set up the query options
my $in_queryOptions = name('queryOptions' =>
\SOAP::Data->value(
name('QueryOptions' =>
\SOAP::Data->value(
name('Paging')->attr({ ListItemCollectionPositionNext => $nextpage })
)
)
)
);
my $call = $soap->GetListItems($in_listName, $in_rowLimit, $in_queryOptions);
die($call->faultstring()) if defined $call->fault();
$nextpage = $call->dataof('//GetListItemsResult/listitems/data')
->attr->{ListItemCollectionPositionNext};
my @items = $call->dataof('//GetListItemsResult/listitems/data/row');
foreach my $data (@items) {
# do something with each list item
}
} while($nextpage);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment