# Authentication (v1 - deprecated)

### Summary

API access is available to users via their JWT bearer token, or can be made available to a backend system via an M2M token issued by InnerSpace.

### Developer Access

Contact **<sales@innerspace.io>** for developer access.  They will provide you with a ClientID and ClientSecret.

They will need to know the usage of the credentials - whether it is needed for a backend service, a native application, a single-page web app or regular web app.

### Backend Services

Backend services should use the `/oauth/token` endpoint below, which behaves as documented in the [Auth0 machine-to-machine (m2m) Client Credentials Flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/client-credentials-flow).

### Examples

{% code title="Python Example" overflow="wrap" lineNumbers="true" %}

```python
# retrieve auth token (cache for reuse)
auth_data = {
    "client_id": 'Your Client ID',
    "client_secret": 'Your Client Secret' }

# auth credentials should be sent as form URL encoded
response = requests.post(url="https://metrics-api.innrspc.com/api/rest/oauth/token", data=auth_data, headers={'Content-Type': 'application/json'}
)
access_token = response.json()['access_token']

# call API using auth token
url_path = 'https://metrics-api.innrspc.com'
authorization = f'Bearer {access_token}'

sample_graphql = {
    "operationName": "sample_graphql",
    "variables": {},
    "query": "query sample_graphql {\n  data: building_features(\n    where: {_and: [{building_id: {_eq: 71}}, {feature_name: {_eq: \"weekly_frequency_dist\"}}, {granularity: {_eq: \"P1W\"}}, {group_id: {_eq: \"all-e707b3a8-0732-49ae-9156-13ff1138540e\"}}, {date_time_start: {_gte: \"2024-01-01T06:00:00.000Z\", _lt: \"2024-01-08T06:00:00.000Z\"}}]}\n  ) {\n    feature_value\n    date_time_start\n  }\n}"
}

response = requests.post(url_path, json=sample_graphql, headers={'Accept': 'application/json', 'Authorization': authorization})
```

{% endcode %}

{% code title="CURL Example" %}

```bash
# Retrieving token
curl --request POST \
     --url https://metrics-api.innrspc.com/api/rest/oauth/token \
     --header 'Content-Type: application/json' \
     --data 'client_id=Your%20Client%20ID&client_secret=Your%20Client%20Secret'

# Calling API
curl --request POST \
  --url https://metrics-api.innrspc.com \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer <Access Token>' \
  --data '{"operationName":"sample_graphql","variables":{},"query":"query sample_graphql {\n  data: building_features(\n    where: {_and: [{building_id: {_eq: 71}}, {feature_name: {_eq: \"weekly_frequency_dist\"}}, {granularity: {_eq: \"P1W\"}}, {group_id: {_eq: \"all-e707b3a8-0732-49ae-9156-13ff1138540e\"}}, {date_time_start: {_gte: \"2024-01-01T06:00:00.000Z\", _lt: \"2024-01-08T06:00:00.000Z\"}}]}\n  ) {\n    feature_value\n    date_time_start\n  }\n}"}'
```

{% endcode %}

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

```python
import logging
import sys
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)


def main(argv):
    # Select your transport with a defined url endpoint, using the auth token from above
    transport = AIOHTTPTransport(url="https://metrics-api.innrspc.com/", headers={"Authorization": "Bearer {access_token}"})

    # Create a GraphQL client using the defined transport
    client = Client(transport=transport, fetch_schema_from_transport=True)

    # Execute the query on the transport
    query = """
        query sample_graphql {
              data: building_features(
                 where: {_and: [{building_id: {_eq: 71}}, {feature_name: {_eq: "weekly_frequency_dist"}}, {granularity: {_eq: "P1W"}}, {group_id: {_eq: "all-e707b3a8-0732-49ae-9156-13ff1138540e"}}, {date_time_start: {_gte: "2024-01-01T06:00:00.000Z", _lt: "2024-01-08T06:00:00.000Z"}}]}
                  ) {
                    feature_value
                    date_time_start
                  }
            }
        """
    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/deprecated-api-2025-05-26/authentication-v1-deprecated.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.
