> For the complete documentation index, see [llms.txt](https://docs.scaleconnect.com.au/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.scaleconnect.com.au/api/rest-api/scaleapp-rest-api/broker-users.md).

# Broker Users

Broker-user relationship management and access control

## Get client user IDs grouped by team tree

> Returns all client user IDs the authenticated broker can access, nested by team and sub-team. Sub-teams are included when traversing the tree from every team the broker owns or has joined via an accepted invite.

```json
{"openapi":"3.0.0","info":{"title":"ScaleApp API","version":"1.0.0"},"tags":[{"name":"Broker Users","description":"Broker-user relationship management and access control"}],"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"JWT","type":"http"}}},"paths":{"/v1/broker-users/users/by-team":{"get":{"description":"Returns all client user IDs the authenticated broker can access, nested by team and sub-team. Sub-teams are included when traversing the tree from every team the broker owns or has joined via an accepted invite.","operationId":"BrokerUserController_getUserIdsGroupedByTeamForBroker_v1","parameters":[],"responses":{"200":{"description":"Successfully retrieved nested team client tree","content":{"application/json":{"schema":{"type":"object","properties":{"brokerId":{"type":"string"},"teams":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string","nullable":true},"name":{"type":"string"},"viewerRole":{"type":"string","nullable":true},"inviteToken":{"type":"string","nullable":true},"clients":{"type":"array","items":{"type":"string"}},"teams":{"type":"array","items":{"type":"object"}}}}}}}}}},"401":{"description":"Unauthorized"}},"summary":"Get client user IDs grouped by team tree","tags":["Broker Users"]}}}}
```

## Get all user IDs for the authenticated broker

> Retrieves all user IDs that the authenticated broker has access to.

```json
{"openapi":"3.0.0","info":{"title":"ScaleApp API","version":"1.0.0"},"tags":[{"name":"Broker Users","description":"Broker-user relationship management and access control"}],"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"JWT","type":"http"}}},"paths":{"/v1/broker-users/users":{"get":{"description":"Retrieves all user IDs that the authenticated broker has access to.","operationId":"BrokerUserController_getUserIdsForBroker_v1","parameters":[],"responses":{"200":{"description":"Successfully retrieved user IDs","content":{"application/json":{"schema":{"type":"object","properties":{"brokerId":{"type":"string"},"userIds":{"type":"array","items":{"type":"string"}}}}}}},"401":{"description":"Unauthorized"}},"summary":"Get all user IDs for the authenticated broker","tags":["Broker Users"]}}}}
```

## Check if authenticated broker has access to a user

> Checks if the authenticated broker has access to a specific user.

```json
{"openapi":"3.0.0","info":{"title":"ScaleApp API","version":"1.0.0"},"tags":[{"name":"Broker Users","description":"Broker-user relationship management and access control"}],"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"JWT","type":"http"}}},"paths":{"/v1/broker-users/access/{userId}":{"get":{"description":"Checks if the authenticated broker has access to a specific user.","operationId":"BrokerUserController_brokerHasAccessToUser_v1","parameters":[{"name":"userId","required":true,"in":"path","description":"The user ID to check access for","schema":{"type":"string"}}],"responses":{"200":{"description":"Access check result","content":{"application/json":{"schema":{"type":"object","properties":{"brokerId":{"type":"string"},"userId":{"type":"string"},"hasAccess":{"type":"boolean"}}}}}},"401":{"description":"Unauthorized"}},"summary":"Check if authenticated broker has access to a user","tags":["Broker Users"]}}}}
```

## Create a broker-user relationship

> Creates a relationship between a broker and a user. If brokerId is provided in the body, uses that (admin only). Otherwise, uses the authenticated broker's ID.

```json
{"openapi":"3.0.0","info":{"title":"ScaleApp API","version":"1.0.0"},"tags":[{"name":"Broker Users","description":"Broker-user relationship management and access control"}],"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"JWT","type":"http"}},"schemas":{"CreateBrokerUserDto":{"type":"object","properties":{"brokerId":{"type":"string","description":"The broker identifier (Clerk user ID or database user ID). Optional - if not provided, uses the authenticated user's Clerk ID to find the broker's database user ID."},"userId":{"type":"string","description":"The user ID to link to the broker"},"teamId":{"type":"string","description":"The team the client is added to. Optional - defaults to the broker's primary team. Must be a team the broker owns or is a member of."}},"required":["userId"]}}},"paths":{"/v1/broker-users":{"post":{"description":"Creates a relationship between a broker and a user. If brokerId is provided in the body, uses that (admin only). Otherwise, uses the authenticated broker's ID.","operationId":"BrokerUserController_createBrokerUserRelationship_v1","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateBrokerUserDto"}}}},"responses":{"201":{"description":"Successfully created broker-user relationship","content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string"},"brokerId":{"type":"string"},"userId":{"type":"string"},"createdAt":{"type":"string","format":"date-time"},"updatedAt":{"type":"string","format":"date-time"}}}}}},"401":{"description":"Unauthorized"}},"summary":"Create a broker-user relationship","tags":["Broker Users"]}}}}
```

## Remove a broker-user relationship

> Removes the relationship between the authenticated broker and a user, revoking the broker's access to the user.

```json
{"openapi":"3.0.0","info":{"title":"ScaleApp API","version":"1.0.0"},"tags":[{"name":"Broker Users","description":"Broker-user relationship management and access control"}],"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"JWT","type":"http"}}},"paths":{"/v1/broker-users/users/{userId}":{"delete":{"description":"Removes the relationship between the authenticated broker and a user, revoking the broker's access to the user.","operationId":"BrokerUserController_removeBrokerUserRelationship_v1","parameters":[{"name":"userId","required":true,"in":"path","description":"The user ID to remove access for","schema":{"type":"string"}}],"responses":{"200":{"description":"Successfully removed broker-user relationship","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"message":{"type":"string"}}}}}},"401":{"description":"Unauthorized"}},"summary":"Remove a broker-user relationship","tags":["Broker Users"]}}}}
```

## Link existing ScaleApp users to broker by phone number

> Looks up existing users by phone number and creates broker-user relationships. Accepts one or two phone numbers (for joint accounts).

```json
{"openapi":"3.0.0","info":{"title":"ScaleApp API","version":"1.0.0"},"tags":[{"name":"Broker Users","description":"Broker-user relationship management and access control"}],"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"scheme":"bearer","bearerFormat":"JWT","type":"http"}},"schemas":{"LinkByPhoneDto":{"type":"object","properties":{"phone1":{"type":"string","description":"Primary client phone number in E.164 format"},"phone2":{"type":"string","description":"Secondary client phone number in E.164 format (optional, for joint accounts)"}},"required":["phone1"]}}},"paths":{"/v1/broker-users/link-by-phone":{"post":{"description":"Looks up existing users by phone number and creates broker-user relationships. Accepts one or two phone numbers (for joint accounts).","operationId":"BrokerUserController_linkByPhone_v1","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/LinkByPhoneDto"}}}},"responses":{"200":{"description":"Link results with successfully linked users and any errors"},"401":{"description":"Unauthorized"}},"summary":"Link existing ScaleApp users to broker by phone number","tags":["Broker Users"]}}}}
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.scaleconnect.com.au/api/rest-api/scaleapp-rest-api/broker-users.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
