from datetime import date
from glean import Glean, models
import os


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

    res = g_client.client.shortcuts.update(id=857478, added_roles=[
        models.UserRoleSpecification(
            person=models.Person(
                name="George Clooney",
                obfuscated_id="abc123",
                related_documents=[],
                metadata=models.PersonMetadata(
                    type=models.PersonMetadataType.FULL_TIME,
                    title="Actor",
                    department="Movies",
                    email="george@example.com",
                    location="Hollywood, CA",
                    phone="6505551234",
                    photo_url="https://example.com/george.jpg",
                    start_date=date.fromisoformat("2000-01-23"),
                    datasource_profile=[
                        models.DatasourceProfile(
                            datasource="github",
                            handle="<value>",
                        ),
                        models.DatasourceProfile(
                            datasource="github",
                            handle="<value>",
                        ),
                        models.DatasourceProfile(
                            datasource="github",
                            handle="<value>",
                        ),
                    ],
                    query_suggestions=models.QuerySuggestionList(
                        suggestions=[],
                    ),
                    invite_info=models.InviteInfo(
                        invites=[],
                    ),
                    custom_fields=[],
                    badges=[
                        models.Badge(
                            key="deployment_name_new_hire",
                            display_name="New hire",
                            icon_config=models.IconConfig(
                                color="#343CED",
                                key="person_icon",
                                icon_type=models.IconType.GLYPH,
                                name="user",
                            ),
                        ),
                    ],
                ),
            ),
            role=models.UserRole.ANSWER_MODERATOR,
        ),
        models.UserRoleSpecification(
            role=models.UserRole.EDITOR,
        ),
    ], removed_roles=[
        models.UserRoleSpecification(
            person=models.Person(
                name="George Clooney",
                obfuscated_id="abc123",
                metadata=models.PersonMetadata(
                    type=models.PersonMetadataType.FULL_TIME,
                    title="Actor",
                    department="Movies",
                    email="george@example.com",
                    location="Hollywood, CA",
                    phone="6505551234",
                    photo_url="https://example.com/george.jpg",
                    start_date=date.fromisoformat("2000-01-23"),
                    datasource_profile=[
                        models.DatasourceProfile(
                            datasource="github",
                            handle="<value>",
                        ),
                        models.DatasourceProfile(
                            datasource="github",
                            handle="<value>",
                        ),
                    ],
                    query_suggestions=models.QuerySuggestionList(),
                    invite_info=models.InviteInfo(),
                    badges=[
                        models.Badge(
                            key="deployment_name_new_hire",
                            display_name="New hire",
                            icon_config=models.IconConfig(
                                color="#343CED",
                                key="person_icon",
                                icon_type=models.IconType.GLYPH,
                                name="user",
                            ),
                        ),
                    ],
                ),
            ),
            role=models.UserRole.VIEWER,
        ),
        models.UserRoleSpecification(
            role=models.UserRole.OWNER,
        ),
        models.UserRoleSpecification(
            role=models.UserRole.VIEWER,
        ),
    ])

    # Handle response
    print(res)
{
  "shortcut": {
    "id": 123,
    "permissions": {
      "write": {
        "scopeType": "GLOBAL",
        "create": true,
        "update": true,
        "delete": true
      }
    },
    "createdBy": {
      "name": "George Clooney",
      "obfuscatedId": "abc123"
    },
    "createTime": "2023-11-07T05:31:56Z",
    "updatedBy": {
      "name": "George Clooney",
      "obfuscatedId": "abc123"
    },
    "updateTime": "2023-11-07T05:31:56Z",
    "destinationDocument": {},
    "intermediateUrl": "<string>",
    "viewPrefix": "<string>",
    "isExternal": true,
    "editUrl": "<string>",
    "alias": "<string>",
    "title": "<string>",
    "roles": [
      {}
    ]
  },
  "error": {
    "errorType": "NO_PERMISSION"
  }
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Headers

X-Glean-ActAs
string

Email address of a user on whose behalf the request is intended to be made (should be non-empty only for global tokens).

X-Glean-Auth-Type
string

Auth type being used to access the endpoint (should be non-empty only for global tokens).

Body

application/json
Shortcut content. Id need to be specified for the shortcut.

The body is of type object.

Response

200
application/json
OK

The response is of type object.