> For the complete documentation index, see [llms.txt](https://docs.tnid.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tnid.com/authentication/accessing-via-postman-graphql-schema-examples.md).

# Accessing via Postman / GraphQL Schema examples

Browse the live GraphQL schema in Postman with your Bearer token, or fetch it programmatically with the gql Python client.

## Postman

Once you have generated your Bearer token, you can access the GraphQL schema easily using Postman. Simply take your generated token, and create a new request using the GraphQL feature:

<figure><img src="https://218732174-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfPazwA5iPiTPgaPvkQZx%2Fuploads%2FvLHFwqwTq4ERIzyWwC2Q%2Fimage.png?alt=media&#x26;token=6f47b718-da6d-41aa-9c4b-563ed5e1b6a6" alt=""><figcaption><p>Select GraphQL from the dropdown.</p></figcaption></figure>

<figure><img src="https://218732174-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfPazwA5iPiTPgaPvkQZx%2Fuploads%2F2dROSXRXFbIztkzNl1mn%2FScreenshot%202024-10-16%20at%208.18.19%E2%80%AFAM.png?alt=media&#x26;token=0b525ce5-d3c6-48a0-ad9d-a9422c10ad78" alt=""><figcaption><p>Authenticate using your generated Bearer token.</p></figcaption></figure>

Load the GraphQL schema by entering the URL (`https://api.staging.v2.tnid.com/company` for the company endpoints, or `/user` for the user endpoints), and then press "Use GraphQL Introspection" on the Schema tab.

<figure><img src="https://218732174-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfPazwA5iPiTPgaPvkQZx%2Fuploads%2F7uUbUnlsrZF76S7rYped%2FScreenshot%202024-10-16%20at%208.20.13%E2%80%AFAM.png?alt=media&#x26;token=63f2ffb6-eec2-400b-a6e9-ca581f5793c8" alt=""><figcaption><p>Press "Use GraphQL Introspection" to load the schema.</p></figcaption></figure>

<figure><img src="https://218732174-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfPazwA5iPiTPgaPvkQZx%2Fuploads%2FP2FchM9frYc6trduqiuJ%2FScreenshot%202024-10-16%20at%208.20.26%E2%80%AFAM.png?alt=media&#x26;token=e1c8e760-8fc5-4000-801b-f0d96d6dcdfb" alt=""><figcaption></figcaption></figure>

The schema should now be accessible via Postman. A rendered version of the same schema, with request and response examples for every operation, is published in the [API Reference](https://docs.tnid.com/api-reference/).

## Example Code to access GraphQL Schema

{% tabs %}
{% tab title="Python" %}

```python
import pprint
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport

# Please note that this basic example won't work if you have an asyncio event loop running.
# In some python environments (as with Jupyter which uses IPython) an asyncio event loop is created for you.
# In that case you should use instead https://gql.readthedocs.io/en/latest/async/async_usage.html#async-usage
def get_full_company_endpoint_schema(bearer_token):
    transport = AIOHTTPTransport(
        url="https://api.staging.v2.tnid.com/company",
        headers={"Authorization": f"Bearer {bearer_token}"}
    )
    # fetch_schema_from_transport=True makes gql run the introspection query for you
    client = Client(transport=transport, fetch_schema_from_transport=True)

    # Any valid query triggers the schema fetch
    query = gql("query ($name: String, $limit: Int) { companies(name: $name, limit: $limit) { id legalName } }")

    try:
        response = client.execute(query, {"name": "schema query", "limit": 1})
        print(f"Response OK: {response}")
        print("Schema: ")
        pprint.pp(client.introspection)
        return response
    except Exception as e:
        print(f"Exception: {e}")


def get_full_user_endpoint_schema(bearer_token):
    transport = AIOHTTPTransport(
        url="https://api.staging.v2.tnid.com/user",
        headers={"Authorization": f"Bearer {bearer_token}"}
    )
    client = Client(transport=transport, fetch_schema_from_transport=True)

    query = gql("query ($limit: Int) { spamReports(limit: $limit) { id } }")

    try:
        response = client.execute(query, {"limit": 1})
        print(f"Response OK: {response}")
        print("Schema: ")
        pprint.pp(client.introspection)
        return response
    except Exception as e:
        print(f"Exception: {e}")


# Example usage:
token = "your_company_token"
get_full_company_endpoint_schema(token)

# OR
# token = "your_user_token"
# get_full_user_endpoint_schema(token)
```

{% endtab %}
{% endtabs %}
