The Glean Java SDK provides convenient access to the Glean REST API for Java 8+. It includes POJOs for all API models, fluent builders for requests, and supports both synchronous and asynchronous execution using standard HTTP clients.
This SDK combines both the Client and Indexing API namespaces into a single unified package:
- Client API: Used for search, retrieval, and end-user interactions with Glean content
- Indexing API: Used for indexing content, permissions, and other administrative operations
Each namespace has its own authentication requirements and access patterns. While they serve different purposes, having them in a single SDK provides a consistent developer experience across all Glean API interactions.
// Example of accessing Client namespace
Glean glean = Glean.builder()
.apiToken("client-token")
.instance("instance-name")
.build();
glean.client().search().query()
.searchRequest(SearchRequest.builder().query("search term").build())
.call();
// Example of accessing Indexing namespace
Glean glean = Glean.builder()
.apiToken("indexing-token")
.instance("instance-name")
.build();
glean.indexing().documents().index()
.request(DocumentBulkIndexRequest.builder() /* document data */ .build())
.call();
Remember that each namespace requires its own authentication token type as described in the Authentication Methods section.
JDK 11 or later is required.
The samples below show how a published SDK artifact is used:
Gradle:
implementation 'com.glean.api-client:glean-api-client:0.5.6'
Maven:
<dependency>
<groupId>com.glean.api-client</groupId>
<artifactId>glean-api-client</artifactId>
<version>0.5.6</version>
</dependency>
After cloning the git repository to your file system you can build the SDK artifact from source to the build
directory by running ./gradlew build
on *nix systems or gradlew.bat
on Windows systems.
If you wish to build from source and publish the SDK artifact to your local Maven repository (on your filesystem) then use the following command (after cloning the git repo locally):
On *nix:
./gradlew publishToMavenLocal -Pskip.signing
On Windows:
gradlew.bat publishToMavenLocal -Pskip.signing
A logging framework/facade has not yet been adopted but is under consideration.
For request and response logging (especially json bodies) use:
SpeakeasyHTTPClient.setDebugLogging(true); // experimental API only (may change without warning)
Example output:
Sending request: http://localhost:35123/bearer#global GET
Request headers: {Accept=[application/json], Authorization=[******], Client-Level-Header=[added by client], Idempotency-Key=[some-key], x-speakeasy-user-agent=[speakeasy-sdk/java 0.0.1 internal 0.1.0 org.openapis.openapi]}
Received response: (GET http://localhost:35123/bearer#global) 200
Response headers: {access-control-allow-credentials=[true], access-control-allow-origin=[*], connection=[keep-alive], content-length=[50], content-type=[application/json], date=[Wed, 09 Apr 2025 01:43:29 GMT], server=[gunicorn/19.9.0]}
Response body:
{
"authenticated": true,
"token": "global"
}
WARNING: This should only used for temporary debugging purposes. Leaving this option on in a production system could expose credentials/secrets in logs. Authorization headers are redacted by default and there is the ability to specify redacted header names via SpeakeasyHTTPClient.setRedactedHeaders
.
Another option is to set the System property -Djdk.httpclient.HttpClient.log=all
. However, this second option does not log bodies.
package hello.world;
import com.glean.api_client.glean_api_client.Glean;
import com.glean.api_client.glean_api_client.models.components.*;
import com.glean.api_client.glean_api_client.models.operations.ChatResponse;
import java.lang.Exception;
import java.util.List;
public class Application {
public static void main(String[] args) throws Exception {
Glean sdk = Glean.builder()
.apiToken("<YOUR_BEARER_TOKEN_HERE>")
.build();
ChatResponse res = sdk.client().chat().create()
.chatRequest(ChatRequest.builder()
.messages(List.of(
ChatMessage.builder()
.fragments(List.of(
ChatMessageFragment.builder()
.text("What are the company holidays this year?")
.build()))
.build()))
.build())
.call();
if (res.chatResponse().isPresent()) {
// handle response
}
}
}
package hello.world;
import com.glean.api_client.glean_api_client.Glean;
import com.glean.api_client.glean_api_client.models.components.*;
import com.glean.api_client.glean_api_client.models.operations.ChatStreamResponse;
import java.lang.Exception;
import java.util.List;
public class Application {
public static void main(String[] args) throws Exception {
Glean sdk = Glean.builder()
.apiToken("<YOUR_BEARER_TOKEN_HERE>")
.build();
ChatStreamResponse res = sdk.client().chat().createStream()
.chatRequest(ChatRequest.builder()
.messages(List.of(
ChatMessage.builder()
.fragments(List.of(
ChatMessageFragment.builder()
.text("What are the company holidays this year?")
.build()))
.build()))
.build())
.call();
if (res.chatRequestStream().isPresent()) {
// handle response
}
}
}
This SDK supports the following security scheme globally:
Name | Type | Scheme | Environment Variable |
---|---|---|---|
apiToken |
http | HTTP Bearer | GLEAN_API_TOKEN |
To authenticate with the API the apiToken
parameter must be set when initializing the SDK client instance. For example:
package hello.world;
import com.glean.api_client.glean_api_client.Glean;
import com.glean.api_client.glean_api_client.models.components.*;
import com.glean.api_client.glean_api_client.models.operations.ActivityResponse;
import java.lang.Exception;
import java.time.OffsetDateTime;
import java.util.List;
public class Application {
public static void main(String[] args) throws Exception {
Glean sdk = Glean.builder()
.apiToken("<YOUR_BEARER_TOKEN_HERE>")
.build();
Activity req = Activity.builder()
.events(List.of(
ActivityEvent.builder()
.action(ActivityEventAction.HISTORICAL_VIEW)
.timestamp(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
.url("https://example.com/")
.build(),
ActivityEvent.builder()
.action(ActivityEventAction.SEARCH)
.timestamp(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
.url("https://example.com/search?q=query")
.params(ActivityEventParams.builder()
.query("query")
.build())
.build(),
ActivityEvent.builder()
.action(ActivityEventAction.VIEW)
.timestamp(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
.url("https://example.com/")
.params(ActivityEventParams.builder()
.duration(20L)
.referrer("https://example.com/document")
.build())
.build()))
.build();
ActivityResponse res = sdk.client().activity().report()
.request(req)
.call();
// handle response
}
}
Glean supports different authentication methods depending on which API namespace you're using:
The Client namespace supports two authentication methods:
-
Manually Provisioned API Tokens
- Can be created by an Admin or a user with the API Token Creator role
- Used for server-to-server integrations
-
OAuth
- Requires OAuth setup to be completed by an Admin
- Used for user-based authentication flows
The Indexing namespace supports only one authentication method:
- Manually Provisioned API Tokens
- Can be created by an Admin or a user with the API Token Creator role
- Used for secure document indexing operations
Important
Client tokens will not work for Indexing operations, and Indexing tokens will not work for Client operations. You must use the appropriate token type for the namespace you're accessing.
For more information on obtaining the appropriate token type, please contact your Glean administrator.
Available methods
- retrieve - Retrieve an agent
- retrieveSchemas - List an agent's schemas
- list - Search agents
- runStream - Create an agent run and stream the response
- run - Create an agent run and wait for the response
- create - Create Answer
- delete - Delete Answer
- update - Update Answer
- retrieve - Read Answer
- list - List Answers
- createToken - Create authentication token
- create - Chat
- deleteAll - Deletes all saved Chats owned by a user
- delete - Deletes saved Chats
- retrieve - Retrieves a Chat
- list - Retrieves all saved Chats
- retrieveApplication - Gets the metadata for a custom Chat application
- uploadFiles - Upload files for Chat.
- retrieveFiles - Get files uploaded by a user for Chat.
- deleteFiles - Delete files uploaded by a user for chat.
- createStream - Chat
- addItems - Add Collection item
- create - Create Collection
- delete - Delete Collection
- deleteItem - Delete Collection item
- update - Update Collection
- updateItem - Update Collection item
- retrieve - Read Collection
- list - List Collections
- retrievePermissions - Read document permissions
- retrieve - Read documents
- retrieveByFacets - Read documents by facets
- summarize - Summarize documents
- list - List entities
- readPeople - Read people
- retrieve - Gets specified policy
- update - Updates an existing policy
- list - Lists policies
- create - Creates new policy
- download - Downloads violations CSV for policy
- create - Creates new one-time report
- download - Downloads violations CSV for report
- status - Fetches report run status
- retrieve - Read insights
- retrieve - Read messages
- queryAsAdmin - Search the index (admin)
- autocomplete - Autocomplete
- retrieveFeed - Feed of documents and events
- recommendations - Recommend documents
- query - Search
- create - Create shortcut
- delete - Delete shortcut
- retrieve - Read shortcut
- list - List shortcuts
- update - Update shortcut
- addReminder - Create verification
- list - List verifications
- verify - Update verification
- rotateToken - Rotate token
- status - Beta: Get datasource status
- add - Add or update datasource
- retrieveConfig - Get datasource config
-
addOrUpdate - Index document
-
index - Index documents
-
bulkIndex - Bulk index documents
-
processAll - Schedules the processing of uploaded documents
-
delete - Delete document
-
debug - Beta: Get document information
-
debugMany - Beta: Get information of a batch of documents
-
checkAccess - Check document access
-
status- Get document upload and indexing status⚠️ Deprecated -
count- Get document count⚠️ Deprecated
-
debug - Beta: Get user information
-
count- Get user count⚠️ Deprecated -
index - Index employee
-
bulkIndex - Bulk index employees
-
processAllEmployeesAndTeams - Schedules the processing of uploaded employees and teams
-
delete - Delete employee
-
indexTeam - Index team
-
deleteTeam - Delete team
-
bulkIndexTeams - Bulk index teams
- updatePermissions - Update document permissions
- indexUser - Index user
- bulkIndexUsers - Bulk index users
- indexGroup - Index group
- bulkIndexGroups - Bulk index groups
- indexMembership - Index membership
- bulkIndexMemberships - Bulk index memberships for a group
- processMemberships - Schedules the processing of group memberships
- deleteUser - Delete user
- deleteGroup - Delete group
- deleteMembership - Delete membership
- authorizeBetaUsers - Beta users
Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an exception.
By default, an API error will throw a models/errors/APIException
exception. When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the create
method throws the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
models/errors/CollectionError | 422 | application/json |
models/errors/APIException | 4XX, 5XX | */* |
package hello.world;
import com.glean.api_client.glean_api_client.Glean;
import com.glean.api_client.glean_api_client.models.components.*;
import com.glean.api_client.glean_api_client.models.errors.CollectionError;
import com.glean.api_client.glean_api_client.models.operations.CreatecollectionResponse;
import java.lang.Exception;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Map;
public class Application {
public static void main(String[] args) throws CollectionError, Exception {
Glean sdk = Glean.builder()
.apiToken("<YOUR_BEARER_TOKEN_HERE>")
.build();
CreateCollectionRequest req = CreateCollectionRequest.builder()
.name("<value>")
.addedRoles(List.of(
UserRoleSpecification.builder()
.role(UserRole.VERIFIER)
.person(Person.builder()
.name("George Clooney")
.obfuscatedId("abc123")
.relatedDocuments(List.of(
RelatedDocuments.builder()
.querySuggestion(QuerySuggestion.builder()
.query("app:github type:pull author:mortimer")
.searchProviderInfo(SearchProviderInfo.builder()
.name("Google")
.searchLinkUrlTemplate("https://www.google.com/search?q={query}&hl=en")
.build())
.label("Mortimer's PRs")
.datasource("github")
.requestOptions(SearchRequestOptions.builder()
.facetBucketSize(977077L)
.datasourceFilter("JIRA")
.datasourcesFilter(List.of(
"JIRA"))
.queryOverridesFacetFilters(true)
.facetFilters(List.of(
FacetFilter.builder()
.fieldName("type")
.values(List.of(
FacetFilterValue.builder()
.value("Spreadsheet")
.relationType(RelationType.EQUALS)
.build(),
FacetFilterValue.builder()
.value("Presentation")
.relationType(RelationType.EQUALS)
.build()))
.build()))
.facetFilterSets(List.of(
FacetFilterSet.builder()
.filters(List.of(
FacetFilter.builder()
.fieldName("type")
.values(List.of(
FacetFilterValue.builder()
.value("Spreadsheet")
.relationType(RelationType.EQUALS)
.build(),
FacetFilterValue.builder()
.value("Presentation")
.relationType(RelationType.EQUALS)
.build()))
.build()))
.build(),
FacetFilterSet.builder()
.filters(List.of(
FacetFilter.builder()
.fieldName("type")
.values(List.of(
FacetFilterValue.builder()
.value("Spreadsheet")
.relationType(RelationType.EQUALS)
.build(),
FacetFilterValue.builder()
.value("Presentation")
.relationType(RelationType.EQUALS)
.build()))
.build()))
.build(),
FacetFilterSet.builder()
.filters(List.of(
FacetFilter.builder()
.fieldName("type")
.values(List.of(
FacetFilterValue.builder()
.value("Spreadsheet")
.relationType(RelationType.EQUALS)
.build(),
FacetFilterValue.builder()
.value("Presentation")
.relationType(RelationType.EQUALS)
.build()))
.build()))
.build()))
.authTokens(List.of(
AuthToken.builder()
.accessToken("123abc")
.datasource("gmail")
.scope("email profile https://www.googleapis.com/auth/gmail.readonly")
.tokenType("Bearer")
.authUser("1")
.build()))
.build())
.ranges(List.of(
TextRange.builder()
.startIndex(86650L)
.document(Document.builder()
.metadata(DocumentMetadata.builder()
.datasource("datasource")
.objectType("Feature Request")
.container("container")
.parentId("JIRA_EN-1337")
.mimeType("mimeType")
.documentId("documentId")
.createTime(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
.updateTime(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
.components(List.of(
"Backend",
"Networking"))
.status("[\"Done\"]")
.pins(List.of(
PinDocument.builder()
.documentId("<id>")
.audienceFilters(List.of(
FacetFilter.builder()
.fieldName("type")
.values(List.of(
FacetFilterValue.builder()
.value("Spreadsheet")
.relationType(RelationType.EQUALS)
.build(),
FacetFilterValue.builder()
.value("Presentation")
.relationType(RelationType.EQUALS)
.build()))
.build()))
.build()))
.collections(List.of(
Collection.builder()
.name("<value>")
.description("meaty dial elegantly while react")
.id(854591L)
.audienceFilters(List.of(
FacetFilter.builder()
.fieldName("type")
.values(List.of(
FacetFilterValue.builder()
.value("Spreadsheet")
.relationType(RelationType.EQUALS)
.build(),
FacetFilterValue.builder()
.value("Presentation")
.relationType(RelationType.EQUALS)
.build()))
.build()))
.items(List.of(
CollectionItem.builder()
.collectionId(697663L)
.itemType(CollectionItemItemType.TEXT)
.shortcut(Shortcut.builder()
.inputAlias("<value>")
.build())
.build(),
CollectionItem.builder()
.collectionId(697663L)
.itemType(CollectionItemItemType.TEXT)
.shortcut(Shortcut.builder()
.inputAlias("<value>")
.build())
.build(),
CollectionItem.builder()
.collectionId(697663L)
.itemType(CollectionItemItemType.TEXT)
.shortcut(Shortcut.builder()
.inputAlias("<value>")
.build())
.build()))
.build()))
.interactions(DocumentInteractions.builder()
.reacts(List.of(
Reaction.builder()
.build(),
Reaction.builder()
.build()))
.shares(List.of(
Share.builder()
.numDaysAgo(365776L)
.build(),
Share.builder()
.numDaysAgo(365776L)
.build(),
Share.builder()
.numDaysAgo(365776L)
.build()))
.build())
.verification(Verification.builder()
.state(State.DEPRECATED)
.metadata(VerificationMetadata.builder()
.reminders(List.of(
Reminder.builder()
.assignee(Person.builder()
.name("George Clooney")
.obfuscatedId("abc123")
.build())
.remindAt(268615L)
.build()))
.lastReminder(Reminder.builder()
.assignee(Person.builder()
.name("George Clooney")
.obfuscatedId("abc123")
.build())
.remindAt(423482L)
.build())
.build())
.build())
.shortcuts(List.of(
Shortcut.builder()
.inputAlias("<value>")
.build(),
Shortcut.builder()
.inputAlias("<value>")
.build(),
Shortcut.builder()
.inputAlias("<value>")
.build()))
.customData(Map.ofEntries(
Map.entry("someCustomField", CustomDataValue.builder()
.build())))
.build())
.build())
.build()))
.inputDetails(SearchRequestInputDetails.builder()
.hasCopyPaste(true)
.build())
.build())
.results(List.of(
SearchResult.builder()
.url("https://example.com/foo/bar")
.title("title")
.nativeAppUrl("slack://foo/bar")
.snippets(List.of(
SearchResultSnippet.builder()
.snippet("snippet")
.mimeType("mimeType")
.build()))
.build()))
.build(),
RelatedDocuments.builder()
.querySuggestion(QuerySuggestion.builder()
.query("app:github type:pull author:mortimer")
.searchProviderInfo(SearchProviderInfo.builder()
.name("Google")
.searchLinkUrlTemplate("https://www.google.com/search?q={query}&hl=en")
.build())
.label("Mortimer's PRs")
.datasource("github")
.requestOptions(SearchRequestOptions.builder()
.facetBucketSize(977077L)
.datasourceFilter("JIRA")
.datasourcesFilter(List.of(
"JIRA"))
.queryOverridesFacetFilters(true)
.facetFilters(List.of(
FacetFilter.builder()
.fieldName("type")
.values(List.of(
FacetFilterValue.builder()
.value("Spreadsheet")
.relationType(RelationType.EQUALS)
.build(),
FacetFilterValue.builder()
.value("Presentation")
.relationType(RelationType.EQUALS)
.build()))
.build()))
.facetFilterSets(List.of(
FacetFilterSet.builder()
.filters(List.of(
FacetFilter.builder()
.fieldName("type")
.values(List.of(
FacetFilterValue.builder()
.value("Spreadsheet")
.relationType(RelationType.EQUALS)
.build(),
FacetFilterValue.builder()
.value("Presentation")
.relationType(RelationType.EQUALS)
.build()))
.build()))
.build(),
FacetFilterSet.builder()
.filters(List.of(
FacetFilter.builder()
.fieldName("type")
.values(List.of(
FacetFilterValue.builder()
.value("Spreadsheet")
.relationType(RelationType.EQUALS)
.build(),
FacetFilterValue.builder()
.value("Presentation")
.relationType(RelationType.EQUALS)
.build()))
.build()))
.build(),
FacetFilterSet.builder()
.filters(List.of(
FacetFilter.builder()
.fieldName("type")
.values(List.of(
FacetFilterValue.builder()
.value("Spreadsheet")
.relationType(RelationType.EQUALS)
.build(),
FacetFilterValue.builder()
.value("Presentation")
.relationType(RelationType.EQUALS)
.build()))
.build()))
.build()))
.authTokens(List.of(
AuthToken.builder()
.accessToken("123abc")
.datasource("gmail")
.scope("email profile https://www.googleapis.com/auth/gmail.readonly")
.tokenType("Bearer")
.authUser("1")
.build()))
.build())
.ranges(List.of(
TextRange.builder()
.startIndex(86650L)
.document(Document.builder()
.metadata(DocumentMetadata.builder()
.datasource("datasource")
.objectType("Feature Request")
.container("container")
.parentId("JIRA_EN-1337")
.mimeType("mimeType")
.documentId("documentId")
.createTime(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
.updateTime(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
.components(List.of(
"Backend",
"Networking"))
.status("[\"Done\"]")
.pins(List.of(
PinDocument.builder()
.documentId("<id>")
.audienceFilters(List.of(
FacetFilter.builder()
.fieldName("type")
.values(List.of(
FacetFilterValue.builder()
.value("Spreadsheet")
.relationType(RelationType.EQUALS)
.build(),
FacetFilterValue.builder()
.value("Presentation")
.relationType(RelationType.EQUALS)
.build()))
.build()))
.build()))
.collections(List.of(
Collection.builder()
.name("<value>")
.description("meaty dial elegantly while react")
.id(854591L)
.audienceFilters(List.of(
FacetFilter.builder()
.fieldName("type")
.values(List.of(
FacetFilterValue.builder()
.value("Spreadsheet")
.relationType(RelationType.EQUALS)
.build(),
FacetFilterValue.builder()
.value("Presentation")
.relationType(RelationType.EQUALS)
.build()))
.build()))
.items(List.of(
CollectionItem.builder()
.collectionId(697663L)
.itemType(CollectionItemItemType.TEXT)
.shortcut(Shortcut.builder()
.inputAlias("<value>")
.build())
.build(),
CollectionItem.builder()
.collectionId(697663L)
.itemType(CollectionItemItemType.TEXT)
.shortcut(Shortcut.builder()
.inputAlias("<value>")
.build())
.build(),
CollectionItem.builder()
.collectionId(697663L)
.itemType(CollectionItemItemType.TEXT)
.shortcut(Shortcut.builder()
.inputAlias("<value>")
.build())
.build()))
.build()))
.interactions(DocumentInteractions.builder()
.reacts(List.of(
Reaction.builder()
.build(),
Reaction.builder()
.build()))
.shares(List.of(
Share.builder()
.numDaysAgo(365776L)
.build(),
Share.builder()
.numDaysAgo(365776L)
.build(),
Share.builder()
.numDaysAgo(365776L)
.build()))
.build())
.verification(Verification.builder()
.state(State.DEPRECATED)
.metadata(VerificationMetadata.builder()
.reminders(List.of(
Reminder.builder()
.assignee(Person.builder()
.name("George Clooney")
.obfuscatedId("abc123")
.build())
.remindAt(268615L)
.build()))
.lastReminder(Reminder.builder()
.assignee(Person.builder()
.name("George Clooney")
.obfuscatedId("abc123")
.build())
.remindAt(423482L)
.build())
.build())
.build())
.shortcuts(List.of(
Shortcut.builder()
.inputAlias("<value>")
.build(),
Shortcut.builder()
.inputAlias("<value>")
.build(),
Shortcut.builder()
.inputAlias("<value>")
.build()))
.customData(Map.ofEntries(
Map.entry("someCustomField", CustomDataValue.builder()
.build())))
.build())
.build())
.build()))
.inputDetails(SearchRequestInputDetails.builder()
.hasCopyPaste(true)
.build())
.build())
.results(List.of(
SearchResult.builder()
.url("https://example.com/foo/bar")
.title("title")
.nativeAppUrl("slack://foo/bar")
.snippets(List.of(
SearchResultSnippet.builder()
.snippet("snippet")
.mimeType("mimeType")
.build()))
.build()))
.build()))
.metadata(PersonMetadata.builder()
.type(PersonMetadataType.FULL_TIME)
.title("Actor")
.department("Movies")
.email("[email protected]")
.location("Hollywood, CA")
.phone("6505551234")
.photoUrl("https://example.com/george.jpg")
.startDate(LocalDate.parse("2000-01-23"))
.datasourceProfile(List.of(
DatasourceProfile.builder()
.datasource("github")
.handle("<value>")
.build(),
DatasourceProfile.builder()
.datasource("github")
.handle("<value>")
.build()))
.querySuggestions(QuerySuggestionList.builder()
.suggestions(List.of(
QuerySuggestion.builder()
.query("app:github type:pull author:mortimer")
.label("Mortimer's PRs")
.datasource("github")
.build()))
.build())
.inviteInfo(InviteInfo.builder()
.invites(List.of(
ChannelInviteInfo.builder()
.build(),
ChannelInviteInfo.builder()
.build()))
.build())
.customFields(List.of(
CustomFieldData.builder()
.label("<value>")
.values(List.of(
CustomFieldValue.of(CustomFieldValueStr.builder()
.build()),
CustomFieldValue.of(CustomFieldValueStr.builder()
.build()),
CustomFieldValue.of(CustomFieldValueStr.builder()
.build())))
.build(),
CustomFieldData.builder()
.label("<value>")
.values(List.of(
CustomFieldValue.of(CustomFieldValueStr.builder()
.build()),
CustomFieldValue.of(CustomFieldValueStr.builder()
.build()),
CustomFieldValue.of(CustomFieldValueStr.builder()
.build())))
.build()))
.badges(List.of(
Badge.builder()
.key("deployment_name_new_hire")
.displayName("New hire")
.iconConfig(IconConfig.builder()
.color("#343CED")
.key("person_icon")
.iconType(IconType.GLYPH)
.name("user")
.build())
.build()))
.build())
.build())
.build()))
.removedRoles(List.of(
UserRoleSpecification.builder()
.role(UserRole.VIEWER)
.person(Person.builder()
.name("George Clooney")
.obfuscatedId("abc123")
.metadata(PersonMetadata.builder()
.type(PersonMetadataType.FULL_TIME)
.title("Actor")
.department("Movies")
.email("[email protected]")
.location("Hollywood, CA")
.phone("6505551234")
.photoUrl("https://example.com/george.jpg")
.startDate(LocalDate.parse("2000-01-23"))
.datasourceProfile(List.of(
DatasourceProfile.builder()
.datasource("github")
.handle("<value>")
.build(),
DatasourceProfile.builder()
.datasource("github")
.handle("<value>")
.build()))
.querySuggestions(QuerySuggestionList.builder()
.suggestions(List.of(
QuerySuggestion.builder()
.query("app:github type:pull author:mortimer")
.label("Mortimer's PRs")
.datasource("github")
.build()))
.build())
.inviteInfo(InviteInfo.builder()
.invites(List.of(
ChannelInviteInfo.builder()
.build(),
ChannelInviteInfo.builder()
.build()))
.build())
.badges(List.of(
Badge.builder()
.key("deployment_name_new_hire")
.displayName("New hire")
.iconConfig(IconConfig.builder()
.color("#343CED")
.key("person_icon")
.iconType(IconType.GLYPH)
.name("user")
.build())
.build()))
.build())
.build())
.build()))
.audienceFilters(List.of(
FacetFilter.builder()
.fieldName("type")
.values(List.of(
FacetFilterValue.builder()
.value("Spreadsheet")
.relationType(RelationType.EQUALS)
.build(),
FacetFilterValue.builder()
.value("Presentation")
.relationType(RelationType.EQUALS)
.build()))
.build()))
.build();
CreatecollectionResponse res = sdk.client().collections().create()
.request(req)
.call();
if (res.createCollectionResponse().isPresent()) {
// handle response
}
}
}
The default server https://{instance}-be.glean.com
contains variables and is set to https://instance-name-be.glean.com
by default. To override default values, the following builder methods are available when initializing the SDK client instance:
Variable | BuilderMethod | Default | Description |
---|---|---|---|
instance |
instance(String instance) |
"instance-name" |
The instance name (typically the email domain without the TLD) that determines the deployment backend. |
package hello.world;
import com.glean.api_client.glean_api_client.Glean;
import com.glean.api_client.glean_api_client.models.components.*;
import com.glean.api_client.glean_api_client.models.operations.ActivityResponse;
import java.lang.Exception;
import java.time.OffsetDateTime;
import java.util.List;
public class Application {
public static void main(String[] args) throws Exception {
Glean sdk = Glean.builder()
.instance("<value>")
.apiToken("<YOUR_BEARER_TOKEN_HERE>")
.build();
Activity req = Activity.builder()
.events(List.of(
ActivityEvent.builder()
.action(ActivityEventAction.HISTORICAL_VIEW)
.timestamp(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
.url("https://example.com/")
.build(),
ActivityEvent.builder()
.action(ActivityEventAction.SEARCH)
.timestamp(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
.url("https://example.com/search?q=query")
.params(ActivityEventParams.builder()
.query("query")
.build())
.build(),
ActivityEvent.builder()
.action(ActivityEventAction.VIEW)
.timestamp(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
.url("https://example.com/")
.params(ActivityEventParams.builder()
.duration(20L)
.referrer("https://example.com/document")
.build())
.build()))
.build();
ActivityResponse res = sdk.client().activity().report()
.request(req)
.call();
// handle response
}
}
The default server can be overridden globally using the .serverURL(String serverUrl)
builder method when initializing the SDK client instance. For example:
package hello.world;
import com.glean.api_client.glean_api_client.Glean;
import com.glean.api_client.glean_api_client.models.components.*;
import com.glean.api_client.glean_api_client.models.operations.ActivityResponse;
import java.lang.Exception;
import java.time.OffsetDateTime;
import java.util.List;
public class Application {
public static void main(String[] args) throws Exception {
Glean sdk = Glean.builder()
.serverURL("https://instance-name-be.glean.com")
.apiToken("<YOUR_BEARER_TOKEN_HERE>")
.build();
Activity req = Activity.builder()
.events(List.of(
ActivityEvent.builder()
.action(ActivityEventAction.HISTORICAL_VIEW)
.timestamp(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
.url("https://example.com/")
.build(),
ActivityEvent.builder()
.action(ActivityEventAction.SEARCH)
.timestamp(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
.url("https://example.com/search?q=query")
.params(ActivityEventParams.builder()
.query("query")
.build())
.build(),
ActivityEvent.builder()
.action(ActivityEventAction.VIEW)
.timestamp(OffsetDateTime.parse("2000-01-23T04:56:07.000Z"))
.url("https://example.com/")
.params(ActivityEventParams.builder()
.duration(20L)
.referrer("https://example.com/document")
.build())
.build()))
.build();
ActivityResponse res = sdk.client().activity().report()
.request(req)
.call();
// handle response
}
}
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.