Skip to content

Client API Cmdlets

The Glean PowerShell module exposes a set of generated cmdlets in the Glean/Public/Client directory that wrap the Glean Client API. These functions handle HTTP communication, parameter serialization, and error handling, allowing engineers to interact with Glean services such as search, collections, and verification reminders. Each cmdlet maps directly to a specific REST endpoint, accepting parameters that correspond to query strings, headers, and request bodies.

Common Architecture and Invocation Pattern

Section titled “Common Architecture and Invocation Pattern”

All client cmdlets follow a consistent internal structure. They utilize a process block to construct an invocation hashtable ($__invoke) containing the API name, HTTP method, path, query parameters, headers, and body. This hashtable is then passed to the core Invoke-GleanRequest function.

Key architectural features include:

  • Parameter Sets: Most cmdlets support a Fields parameter set for individual arguments and a Body parameter set for passing a raw hashtable. This allows flexibility for complex oneOf/anyOf shapes or deeply nested objects .
  • Internal Variables: Local variables are prefixed with $__ to prevent collisions with generated parameters, as PowerShell variable names are case-insensitive .
  • Headers and Query Params: Common headers like X-Glean-ActAs and X-Glean-Auth-Type are mapped from parameters to the request headers . The Locale parameter is mapped to the locale query string .
  • Retry and Raw Options: The RetryUnsafe switch allows non-idempotent operations to be retried on HTTP 429/503 errors [src: Glean/Public/Client/Add-GleanCollection.ps1:L28]. The Raw switch returns the undeserialized HTTP response [src: Glean/Public/Client/Add-GleanCollection.ps1:L29].

The search functionality is exposed through two main cmdlets: Find-GleanSearch and Find-GleanSearchRecommendations.

This cmdlet wraps the Autocomplete API, retrieving query suggestions, operators, and documents for a partially typed query . It supports filtering by datasources, result types, and auth tokens for federated results . The ResultSize parameter caps the number of returned results, with a default backend cap of 200 if omitted [src: Glean/Public/Client/Find-GleanSearch.ps1:L21].

This cmdlet retrieves recommended documents based on a source document or URL . It accepts parameters for PageSize and MaxSnippetSize to hint at the desired response size . It also supports TrackingToken for associating requests with previous searches [src: Glean/Public/Client/Find-GleanSearchRecommendations.ps1:L16].

This cmdlet adds items to a Collection . It requires a CollectionId and accepts an array of AddedCollectionItemDescriptors . The request is sent via a POST to /addcollectionitems [src: Glean/Public/Client/Add-GleanCollection.ps1:L80].

This cmdlet creates a verification reminder for a document . It requires a DocumentId and allows specifying an Assignee, RemindInDays, and an optional Reason . The request is sent via a POST to /addverificationreminder [src: Glean/Public/Client/Add-GleanVerification.ps1:L96].