Skip to content

Latest commit

 

History

History
306 lines (230 loc) · 32.4 KB

File metadata and controls

306 lines (230 loc) · 32.4 KB

Answers

(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
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
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
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] The parent board ID of this Answer, or 0 if it's a floating Answer.
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
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.

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
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 */*