> For the complete documentation index, see [llms.txt](https://docs.takionapi.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.takionapi.tech/cognito/examples.md).

# Example Implementations

{% tabs %}
{% tab title="Ticketmaster SG Login" %}

```python
from tls_client import Session
from requests import get, post
from bs4 import BeautifulSoup

if __name__ == "__main__":
    API_KEY = "TAKION_API_XXX" # Fill it with your api key
    MAIL = "email" # Your TM SG Mail
    PASSWORD = "pw" # Your TM SG Password

    session = Session("chrome_112")
    headers = {
        'Host': 'ticketmaster.sg',
        'sec-ch-ua': '"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"macOS"',
        'upgrade-insecure-requests': '1',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
        'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
        'sec-fetch-site': 'same-origin',
        'sec-fetch-mode': 'navigate',
        'sec-fetch-user': '?1',
        'sec-fetch-dest': 'document',
        'referer': 'https://ticketmaster.sg/',
        'accept-language': 'en-GB,en;q=0.9',
    }

    # ------------------------- Generate reese84 ------------------------- #
    response = session.get("https://epsf.ticketmaster.sg/eps-d", headers={
        "accept": "application/json; charset=utf-8",
        "accept-language": "en-GB,en;q=0.9",
        "content-type": "text/plain; charset=utf-8",
        "origin": "null",
        "priority": "u=1, i",
        "sec-ch-ua": '"Chromium";v="125", "Google Chrome";v="125", "Not-A.Brand";v="99"',
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": "\"macOS\"",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "cross-site",
        "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
    })

    challenge_payload = post(
        "https://incapsula.takionapi.tech/reese84", 
        json={
            "script": response.text
        },
        headers={
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
            "x-api-key": API_KEY
        }
    ).json()['payload']

    response = session.post(
        "https://epsf.ticketmaster.sg/eps-d", 
        headers={
            "accept": "application/json; charset=utf-8",
            "accept-language": "en-GB,en;q=0.9",
            "content-type": "text/plain; charset=utf-8",
            "origin": "null",
            "priority": "u=1, i",
            "sec-ch-ua": '"Chromium";v="125", "Google Chrome";v="125", "Not-A.Brand";v="99"',
            "sec-ch-ua-mobile": "?0",
            "sec-ch-ua-platform": "\"macOS\"",
            "sec-fetch-dest": "empty",
            "sec-fetch-mode": "cors",
            "sec-fetch-site": "cross-site",
            "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
        }, 
        data=challenge_payload,
        params={"d":"www.ticketmaster.sg"}
    )
    response = response.json()
    
    # Set cookie
    session.cookies.set("reese84", response['token'])

    print("Starting...")
    
    # ------------------------- Load CSRF Token  ------------------------- #
    response = session.get('https://ticketmaster.sg/login', headers=headers)

    if (redirect := response.headers.get("Location")):
        response = session.get(redirect, headers=headers)

    headers = {
        'Host': 'main.login.ticketmaster.sg',
        'cache-control': 'max-age=0',
        'sec-ch-ua': '"Google Chrome";v="123", "Not:A-Brand";v="8", "Chromium";v="123"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"macOS"',
        'upgrade-insecure-requests': '1',
        'origin': 'https://main.login.ticketmaster.sg',
        'content-type': 'application/x-www-form-urlencoded',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
        'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
        'sec-fetch-site': 'same-origin',
        'sec-fetch-mode': 'navigate',
        'sec-fetch-user': '?1',
        'sec-fetch-dest': 'document',
        'referer': 'https://main.login.ticketmaster.sg/login?client_id=6vdm5j83n4tc6i0ul4nm9ms6dm&redirect_uri=https%3A%2F%2Fticketmaster.sg%2Flogin&response_type=code&scope=phone+email+openid+aws.cognito.signin.user.admin',
        'accept-language': 'en-GB,en;q=0.9',
    }

    # ------------------------- Generate cognito ------------------------- #
    response = get(
        "https://cognito.takionapi.tech/generate",
        params={
            "api_key": API_KEY,
            "website": "www.ticketmaster.sg",
            "username": MAIL
        },
        headers={
            "User-Agent": headers["user-agent"],
            "sec-ch-ua": headers["sec-ch-ua"]
        }
    ).json()["result"]

    # ------------------------- Login into acc.  ------------------------- #
    response = session.post(
        'https://main.login.ticketmaster.sg/login', 
        params={
            'client_id': '6vdm5j83n4tc6i0ul4nm9ms6dm',
            'redirect_uri': 'https://ticketmaster.sg/login',
            'response_type': 'code',
            'scope': 'phone email openid aws.cognito.signin.user.admin',
        },  
        headers=headers, 
        data={
            '_csrf': session.cookies.get_dict()["XSRF-TOKEN"],
            'username': MAIL,
            'password': PASSWORD,
            'cognitoAsfData': response,
            'signInSubmitButton': 'Sign in',
        }
    )
    if (redirect := response.headers.get("Location")):
        response = session.get(redirect, headers=headers)
    if (redirect := response.headers.get("Location")):
        response = session.get(redirect, headers=headers)
    
    soup = BeautifulSoup(response.text, "html.parser")
    if not (account_data := soup.find("div", {"id": "accountFunc"})):
        print(soup.find("p", {"id": "loginErrorMessage"}).text)
        exit(0)

    print("Logged in as " + account_data.find("div").text)
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.takionapi.tech/cognito/examples.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
