This module provides cmdlets for performing basic API interactions with a FOLIO LSP environment. It is inspired by the FOLIO-FSE python FolioClient library.
For more information about the FOLIO LSP environment and its API, please refer to the FOLIO API documentation.
# From PowerShell Gallery (when published)
Install-Module -Name FolioClient
# From local path
Import-Module -Path ./src/FolioClient/FolioClient.psd1# Create a FOLIO client
$folioClient = Get-FolioClient `
-GatewayUrl "https://folio-snapshot-okapi.dev.folio.org" `
-TenantId "diku" `
-FolioUsername "diku_admin"
# You will be prompted for a password. Alternatively, provide it directly:
$password = ConvertTo-SecureString "admin" -AsPlainText -Force
$folioClient = Get-FolioClient `
-GatewayUrl "https://folio-snapshot-okapi.dev.folio.org" `
-TenantId "diku" `
-FolioUsername "diku_admin" `
-FolioPassword $password
# Retrieve records by CQL query
$items = Get-FolioRecordsByQuery `
-FolioClient $folioClient `
-FolioPath "/inventory/items" `
-FolioKey "items" `
-CqlQuery '(materialTypeId=="b3d29557-c74d-403d-a279-a2ef6b3a80f6")' `
-Limit 100
# Export record IDs to CSV
Get-FolioRecordIdsToCsvByQuery `
-FolioClient $folioClient `
-FolioPath "/inventory/items" `
-FolioKey "items" `
-OutputFilePath "record-ids.csv" `
-Limit 1000Creates a FolioClient instance for authenticating with and making requests to FOLIO.
Parameters:
GatewayUrl(required): The FOLIO API gateway URL (e.g.,https://folio-snapshot-okapi.dev.folio.org)TenantId(required): The tenant ID (e.g.,diku)FolioUsername(required): The username for authenticationFolioPassword(optional): The password as a secure string. If not provided, you will be promptedDebugMode(optional): Enable debug output
Retrieves full records from a FOLIO endpoint using a CQL query.
Parameters:
FolioClient(required): A FolioClient instanceFolioPath(required): The API endpoint path (e.g.,/inventory/items)FolioKey(required): The key in the response containing records (e.g.,items)CqlQuery(optional): CQL query string (default:cql.allRecords=1 sortBy id)Limit(optional): Maximum number of records to return (0 = all)Offset(optional): Number of records to skipBatchSize(optional): Records per request (default: 100)QueryParams(optional): Additional query parameters
Returns: Array of record objects
Retrieves only the record IDs from a FOLIO endpoint using a CQL query.
Parameters: Same as Get-FolioRecordsByQuery
Returns: Array of ID strings
Retrieves record IDs and exports them to a CSV file.
Parameters:
- All parameters from
Get-FolioRecordIdsByQuery OutputFilePath(required): Path where the CSV file will be writtenNoHeaders(optional): Omit column headers from the CSV
Streams records from a FOLIO endpoint with automatic pagination (generator-like behavior). Items are yielded one-at-a-time via the pipeline without accumulating all results in memory.
Parameters:
FolioClient(required): A FolioClient instanceEndpoint(required): The API endpoint path (e.g.,/inventory/items)Key(required): The key in the response containing records (e.g.,items)Query(optional): CQL query string (default:cql.allRecords=1 sortBy id)BatchSize(optional): Records per request (default: 100)Limit(optional): Maximum total records to return (0 = all)Offset(optional): Starting record offset (default: 0)QueryParams(optional): Additional query parameters hashtable
Returns: Stream of record objects (one per pipeline object)
Usage - Stream without collecting:
Invoke-FolioGetAll -FolioClient $folioClient -Endpoint '/inventory/items' -Key 'items' -Limit 1000 | `
Where-Object { $_.status -eq 'Available' } | `
ForEach-Object { Export-Item $_ }Usage - Collect results when needed:
$items = @(Invoke-FolioGetAll -FolioClient $folioClient -Endpoint '/inventory/items' -Key 'items' -Limit 1000)The FolioClient class provides low-level methods for HTTP operations:
Get(endpoint, queryParams)- HTTP GET requestPost(endpoint, body, queryParams)- HTTP POST requestPut(endpoint, body, queryParams)- HTTP PUT requestPatch(endpoint, body, queryParams)- HTTP PATCH requestDelete(endpoint, queryParams)- HTTP DELETE request
For retrieving paginated results with streaming support, use the Invoke-FolioGetAll function instead.
$folioClient = Get-FolioClient -GatewayUrl $url -TenantId $tenant -FolioUsername $username
$items = @(Invoke-FolioGetAll `
-FolioClient $folioClient `
-Endpoint "/inventory/items" `
-Key "items" `
-Query '(materialTypeId=="book-material-type-id")' `
-BatchSize 100)
Write-Host "Retrieved $($items.Count) items"Get-FolioRecordIdsToCsvByQuery `
-FolioClient $folioClient `
-FolioPath "/inventory/items" `
-FolioKey "items" `
-CqlQuery '(status.name=="Available")' `
-OutputFilePath "available-items.csv"# Stream without collecting (processes one item at a time, minimal memory)
$total = 0
Invoke-FolioGetAll `
-FolioClient $folioClient `
-Endpoint "/inventory/items" `
-Key "items" `
-Limit 10000 | `
ForEach-Object {
$total++
# Process each item immediately without storing all 10,000 in memory
if ($_.status -eq 'Available') { Write-Host "Available: $($_.title)" }
}
Write-Host "Processed $total items"# Direct API call
$holdings = $folioClient.Get("/inventory/holdings", @{ limit = 50 })
# POST example
$newRecord = @{ title = "New Title" } | ConvertTo-Json
$result = $folioClient.Post("/inventory/items", $newRecord, @{})The FolioClient supports switching between tenants:
# Switch to a different tenant
$folioClient.TenantId = "different-tenant"
# Reset to the original tenant
$folioClient.ResetTenantId()The module will throw exceptions if authentication fails or API requests encounter errors:
try {
$items = Get-FolioRecordsByQuery -FolioClient $folioClient -FolioPath "/inventory/items" -FolioKey "items"
} catch {
Write-Host "Error: $_"
}- Password Security: Passwords are handled using PowerShell's SecureString type. If you provide a password directly, consider using
ConvertTo-SecureStringwith the-AsPlainTextflag only in development environments. - Token Refresh: The client automatically refreshes authentication tokens before they expire.
- Streaming Pagination: The
Invoke-FolioGetAllfunction handles pagination automatically with streaming support—items are yielded one-at-a-time without accumulating all results in memory. This is ideal for large result sets. - Batch Size: The default batch size is 100 records per request. Increase or decrease based on your API's limits and memory constraints.
- Lazy Loading: Use
Invoke-FolioGetAllto process items as they arrive without loading entire datasets into memory.
- PowerShell 5.1 or higher
- Network connectivity to a FOLIO instance
MIT License - See LICENSE for details
Contributions are welcome! Please refer to the main repository at FOLIO-FSE/FolioClient-PowerShell