# Example Implementations

{% hint style="danger" %}
When interacting with Datadome a good TLS Client is required
{% endhint %}

{% hint style="warning" %}
Note that **the interstitial challenge** will return a json, with other than the cookie, an url to follow. In case of hard-protection mode on datadome, you may get redirected to a captcha challenge that needs to be solved as well
{% endhint %}

{% tabs %}
{% tab title="Datadome Homepage" %}

```python
from tls_client import Session
from requests import post
from time import sleep

API_KEY = "TAKION_API_XXX"

if __name__ == "__main__":
    session = Session(
        client_identifier="chrome_136",
        random_tls_extension_order=True
    )

    while 1:
        print("(1) Loading page...")
        response = session.get(
            'https://datadome.co/', 
            headers={
                'Host': 'datadome.co',
                'sec-ch-ua': '"Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99"',
                '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/136.0.0.0 Safari/537.36',
                'sec-purpose': 'prefetch;prerender',
                'purpose': 'prefetch',
                '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': 'none',
                'sec-fetch-mode': 'navigate',
                'sec-fetch-user': '?1',
                'sec-fetch-dest': 'document',
                'accept-language': 'en-GB,en;q=0.9',
                'priority': 'u=0, i',
            }
        )
        print(response.text[:200])
        if response.status_code == 200:
            print("\033[1;32m" + f"Page loaded successfully: {response.status_code=}" + "\033[0m")
            break
        print("\033[1;33m" + f"Datadome detected! {response.status_code=}" + "\033[0m")

        build_response = post(
            "https://datadome.takionapi.tech/build",
            json={
                "html": response.text,
                "referer": "https://datadome.co/",
                "datadome": session.cookies.get("datadome")
            },
            headers={
                "x-api-key": API_KEY
            }
        ).json()
        if (error := build_response.get("error")):
            print(error)
            sleep(3)
            continue
        
        challenge_url, ctype = build_response["url"], build_response["challenge_type"]
        print(f"(2) Detected \033[1;35m{ctype}\033[0m challenge, loading...")

        challenge_page = session.get(
            challenge_url, 
            headers={
            'Host': 'geo.captcha-delivery.com',
            'sec-ch-ua': '"Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99"',
            '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/136.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': 'cross-site',
            'Sec-Fetch-Mode': 'navigate',
            'Sec-Fetch-Dest': 'iframe',
            'Sec-Fetch-Storage-Access': 'active',
            'Referer': 'https://datadome.co/',
            'Accept-Language': 'en-GB,en;q=0.9',
        })

        print("(3) Solving challenge...")
        solved_response = post(
            "https://datadome.takionapi.tech/solve",
            json={
                "html": challenge_page.text,
            },
            headers={
                'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36',
                "accept-language": "en-GB,en;q=0.9",
                "x-api-key": API_KEY
            }
        ).json()

        if (error := solved_response.get("error")):
            print(error)
            sleep(3)
            continue

        print("(4) Posting challenge...")
        if solved_response["method"] == "POST": # Interstitial
            response = session.post(
                solved_response["url"],
                headers={
                    'Host': 'geo.captcha-delivery.com',
                    'sec-ch-ua-platform': '"macOS"',
                    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36',
                    'sec-ch-ua': '"Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99"',
                    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
                    'sec-ch-ua-mobile': '?0',
                    'Accept': '*/*',
                    'Origin': 'https://geo.captcha-delivery.com',
                    'Sec-Fetch-Site': 'same-origin',
                    'Sec-Fetch-Mode': 'cors',
                    'Sec-Fetch-Dest': 'empty',
                    'Sec-Fetch-Storage-Access': 'active',
                    'Referer': 'https://geo.captcha-delivery.com/interstitial/',
                    'Accept-Language': 'en-GB,en;q=0.9',
                }, 
                data=solved_response["payload"]
            )
        else:
            response = session.get(
                solved_response["url"],
                headers={
                    'Host': 'geo.captcha-delivery.com',
                    'sec-ch-ua-platform': '"macOS"',
                    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36',
                    'sec-ch-ua': '"Chromium";v="136", "Google Chrome";v="136", "Not.A/Brand";v="99"',
                    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
                    'sec-ch-ua-mobile': '?0',
                    'Accept': '*/*',
                    'Sec-Fetch-Site': 'same-origin',
                    'Sec-Fetch-Mode': 'cors',
                    'Sec-Fetch-Dest': 'empty',
                    'Sec-Fetch-Storage-Access': 'active',
                    'Referer': 'https://geo.captcha-delivery.com/captcha/',
                    'Accept-Language': 'en-GB,en;q=0.9',
                }, 
                params=solved_response["payload"]
            )
        cookie = response.json()["cookie"].split("datadome=")[1].split(";")[0]
        print(f"\033[1;34m(5)Generated cookie: {cookie[:17]}...{cookie[-17:]}\033[0m")
        session.cookies.set("datadome", cookie)
        continue
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: 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:

```
GET https://docs.takionapi.tech/datadome/examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
