Skip to content

Latest commit

 

History

History
317 lines (240 loc) · 49.8 KB

File metadata and controls

317 lines (240 loc) · 49.8 KB

Client.Answers

Overview

Available Operations

create

Create a user-generated Answer that contains a question and answer.

Example Usage

from glean.api_client import Glean, models
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN", ""),
) as glean:

    res = glean.client.answers.create(data={
        "question": "Why is the sky blue?",
        "body_text": "From https://en.wikipedia.org/wiki/Diffuse_sky_radiation, the sky is blue because blue light is more strongly scattered than longer-wavelength light.",
        "audience_filters": [
            {
                "field_name": "type",
                "values": [
                    {
                        "value": "Spreadsheet",
                        "relation_type": models.RelationType.EQUALS,
                    },
                    {
                        "value": "Presentation",
                        "relation_type": models.RelationType.EQUALS,
                    },
                ],
            },
        ],
        "added_roles": [
            models.UserRoleSpecification(
                person=models.Person(
                    name="George Clooney",
                    obfuscated_id="abc123",
                ),
                role=models.UserRole.VIEWER,
            ),
        ],
        "removed_roles": [
            models.UserRoleSpecification(
                person=models.Person(
                    name="George Clooney",
                    obfuscated_id="abc123",
                ),
                role=models.UserRole.ANSWER_MODERATOR,
            ),
        ],
        "roles": [
            models.UserRoleSpecification(
                person=models.Person(
                    name="George Clooney",
                    obfuscated_id="abc123",
                ),
                role=models.UserRole.OWNER,
            ),
        ],
        "combined_answer_text": {
            "text": "From https://en.wikipedia.org/wiki/Diffuse_sky_radiation, the sky is blue because blue light is more strongly scattered than longer-wavelength light.",
        },
    })

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
data models.AnswerCreationData ✔️ N/A
locale Optional[str] The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.Answer

Errors

Error Type Status Code Content Type
errors.GleanError 4XX, 5XX */*

delete

Delete an existing user-generated Answer.

Example Usage

from glean.api_client import Glean
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN", ""),
) as glean:

    glean.client.answers.delete(id=3, doc_id="ANSWERS_answer_3")

    # Use the SDK ...

Parameters

Parameter Type Required Description Example
id int ✔️ The opaque ID of the Answer. 3
locale Optional[str] The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en.
doc_id Optional[str] Glean Document ID of the Answer. The Glean Document ID is supported for cases where the Answer ID isn't available. If both are available, using the Answer ID is preferred. ANSWERS_answer_3
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Errors

Error Type Status Code Content Type
errors.GleanError 4XX, 5XX */*

update

Update an existing user-generated Answer.

Example Usage

from glean.api_client import Glean, models
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN", ""),
) as glean:

    res = glean.client.answers.update(id=3, doc_id="ANSWERS_answer_3", question="Why is the sky blue?", body_text="From https://en.wikipedia.org/wiki/Diffuse_sky_radiation, the sky is blue because blue light is more strongly scattered than longer-wavelength light.", audience_filters=[
        {
            "field_name": "type",
            "values": [
                {
                    "value": "Spreadsheet",
                    "relation_type": models.RelationType.EQUALS,
                },
                {
                    "value": "Presentation",
                    "relation_type": models.RelationType.EQUALS,
                },
            ],
        },
    ], added_roles=[
        models.UserRoleSpecification(
            person=models.Person(
                name="George Clooney",
                obfuscated_id="abc123",
            ),
            role=models.UserRole.EDITOR,
        ),
    ], removed_roles=[
        models.UserRoleSpecification(
            person=models.Person(
                name="George Clooney",
                obfuscated_id="abc123",
            ),
            role=models.UserRole.OWNER,
        ),
    ], roles=[
        models.UserRoleSpecification(
            person=models.Person(
                name="George Clooney",
                obfuscated_id="abc123",
            ),
            role=models.UserRole.EDITOR,
        ),
    ], combined_answer_text={
        "text": "From https://en.wikipedia.org/wiki/Diffuse_sky_radiation, the sky is blue because blue light is more strongly scattered than longer-wavelength light.",
    })

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
id int ✔️ The opaque ID of the Answer. 3
locale Optional[str] The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en.
doc_id Optional[str] Glean Document ID of the Answer. The Glean Document ID is supported for cases where the Answer ID isn't available. If both are available, using the Answer ID is preferred. ANSWERS_answer_3
question Optional[str] N/A Why is the sky blue?
question_variations List[str] Additional ways of phrasing this question.
body_text Optional[str] The plain text answer to the question. From https://en.wikipedia.org/wiki/Diffuse_sky_radiation, the sky is blue because blue light is more strongly scattered than longer-wavelength light.
board_id Optional[int] : warning: ** DEPRECATED **: Deprecated on 2026-02-05, removal scheduled for 2026-10-15: Answer Boards no longer supported.

The parent board ID of this Answer, or 0 if it's a floating Answer. Adding Answers to Answer Boards is no longer permitted.
audience_filters List[models.FacetFilter] Filters which restrict who should see the answer. Values are taken from the corresponding filters in people search.
added_roles List[models.UserRoleSpecification] A list of user roles for the answer added by the owner.
removed_roles List[models.UserRoleSpecification] A list of user roles for the answer removed by the owner.
roles List[models.UserRoleSpecification] A list of roles for this answer explicitly granted by an owner, editor, or admin.
source_document_spec Optional[models.DocumentSpecUnion] N/A
source_type Optional[models.EditAnswerRequestSourceType] N/A
added_collections List[int] IDs of Collections to which a document is added.
removed_collections List[int] IDs of Collections from which a document is removed.
combined_answer_text Optional[models.StructuredTextMutableProperties] N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.Answer

Errors

Error Type Status Code Content Type
errors.GleanError 4XX, 5XX */*

retrieve

Read the details of a particular Answer given its ID.

Example Usage

from glean.api_client import Glean
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN", ""),
) as glean:

    res = glean.client.answers.retrieve(id=3, doc_id="ANSWERS_answer_3")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
locale Optional[str] The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en.
id Optional[int] The opaque ID of the Answer. 3
doc_id Optional[str] Glean Document ID of the Answer. The Glean Document ID is supported for cases where the Answer ID isn't available. If both are available, using the Answer ID is preferred. ANSWERS_answer_3
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.GetAnswerResponse

Errors

Error Type Status Code Content Type
errors.GleanError 4XX, 5XX */*

list

List Answers created by the current user.

⚠️ DEPRECATED: Deprecated on 2026-01-21, removal scheduled for 2026-10-15: Answer boards have been removed and this endpoint no longer serves a purpose.

Example Usage

from glean.api_client import Glean
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN", ""),
) as glean:

    res = glean.client.answers.list()

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
locale Optional[str] The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en.
board_id Optional[int] The Answer Board Id to list answers on.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.ListAnswersResponse

Errors

Error Type Status Code Content Type
errors.GleanError 4XX, 5XX */*