+=head2 GetWebserviceBatchId
+
+ my $batchid = GetWebserviceBatchId();
+
+Retrieves the ID of the import batch for webservice.
+If necessary, creates the import batch.
+
+=cut
+
+my $WEBSERVICE_BASE_QRY = <<EOQ;
+SELECT import_batch_id FROM import_batches
+WHERE batch_type = 'webservice'
+AND import_status = 'staged'
+EOQ
+sub GetWebserviceBatchId {
+ my ($params) = @_;
+
+ my $dbh = C4::Context->dbh;
+ my $sql = $WEBSERVICE_BASE_QRY;
+ my @args;
+ foreach my $field (qw(matcher_id overlay_action nomatch_action item_action)) {
+ if (my $val = $params->{$field}) {
+ $sql .= " AND $field = ?";
+ push @args, $val;
+ }
+ }
+ my $id = $dbh->selectrow_array($sql, undef, @args);
+ return $id if $id;
+
+ $params->{batch_type} = 'webservice';
+ $params->{import_status} = 'staged';
+ return AddImportBatch($params);
+}
+