# API Reference (v2)

This is a graphql API.

Insights are published for buildings, floors (site) and zones (polygon on a floorplan).

All GraphQL APIs are available at `https://api.innerspace.io`

### Example

The following example uses `building_id` `71`, which is the DEMO building.

{% code title="Python GraphQL" lineNumbers="true" %}

```python
import sys
import logging
import requests
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
from gql.transport.aiohttp import log as requests_logger

requests_logger.setLevel(logging.WARNING)

API_BASE_URL = "https://api.innerspace.io"
AUDIENCE = "https://global-config.innerspace.io"
CLIENT_ID = "Your Client ID"
CLIENT_SECRET = "Your Client Secret"


def get_session_id():
    response = requests.post(
        url=f"{API_BASE_URL}/v2/oauth/token",
        json={
            "client_id": CLIENT_ID,
            "client_secret": CLIENT_SECRET,
            "audience": AUDIENCE,
        },
    )
    response.raise_for_status()
    return response.json()["session_id"]


def main(argv):
    session_id = get_session_id()

    transport = AIOHTTPTransport(
        url=f"{API_BASE_URL}/v2/api",
        headers={"X-Session-Id": session_id},
    )

    client = Client(transport=transport, fetch_schema_from_transport=False)

    query = """
        query sample_graphql {
            BUILDING_INSIGHTS(
                where: {
                      DATE_PARTITION: {_eq: 20250501},                                                                                                     
                      BUILDING_ID: {_eq: 71},
                      GRANULARITY: {_eq: "PT1H"},                                                                                                          
                      GROUP_ID: {_eq: "00000000-0000-0000-0000-000000000000"},
                      SITE_ID: {_eq: 900000222} 
                },
                order_by: {DATE_TIME_START: desc}
            ) {
                  BUILDING_ID                                                                                                                              
                  DATE_TIME_START
                  OCCUPANCY_MEAN                                                                                                                           
                  GRANULARITY                            
                  GROUP_ID
                  SITE_ID
            }
        }
    """
    print(client.execute(gql(query)))


if __name__ == "__main__":
    main(sys.argv)
```

{% endcode %}


---

# 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://developers.innerspace.io/api-reference-v2.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.
