Team Metadata API

Overview

The Team Metadata API is an extension-callable Cloud Function that provides comprehensive access to all teams and their associated metadata, including custom fields, stage configurations, and data models. This API is designed for external integrations, automation tools, and administrative workflows.

Function: getAllTeamsMetadata

Description

Retrieves all teams from the database along with their complete metadata structure, including:

Authentication

Required: Admin authentication

Only users with admin: true in their user document can call this function. The function verifies authentication and admin status before returning data.

Request

Method: Callable Cloud Function

Parameters: None

Example (JavaScript/TypeScript):

import { getFunctions, httpsCallable } from 'firebase/functions';
const functions = getFunctions();
const getAllTeamsMetadata = httpsCallable(functions, 'getAllTeamsMetadata');
try {
const result = await getAllTeamsMetadata();
const data = result.data;
console.log(`Retrieved ${data.count} teams`);
console.log(data.teams);
} catch (error) {
console.error('Error:', error.message);
}

Example (Flutter/Dart):

import 'package:cloud_functions/cloud_functions.dart';
final functions = FirebaseFunctions.instance;
final callable = functions.httpsCallable('getAllTeamsMetadata');
try {
final result = await callable.call();
final data = result.data as Map<String, dynamic>;
final count = data['count'] as int;
final teams = data['teams'] as List;
print('Retrieved $count teams');
} catch (e) {
print('Error: $e');
}

Response Structure

{
"success": true,
"count": 2,
"teams": [
{
"id": "teamId123",
"name": "Sales Team",
"category": "sales",
"nextTeam": "teamId456",
"bigQuerySyncEnabled": true,
"mcp": true,
"groups": {
"sales-group": "G1",
"managers": "O1"
},
"webhooks": {
"s0": {
"url": "https://example.com/webhook",
"token": "bearer-token"
}
},
"stages": {
"s0": {
"label": "Initial Contact",
"activities": [
"Schedule discovery call",
"Qualify opportunity"
],
"webhook": {
"url": "https://example.com/webhook",
"token": "bearer-token"
}
},
"s1": {
"label": "Qualification",
"activities": [
"Review requirements",
"Prepare proposal"
],
"webhook": null
},
"s2": {
"label": "Proposal",
"activities": [],
"webhook": null
},
"s3": {
"label": "Negotiation",
"activities": [],
"webhook": null
},
"s4": {
"label": "Closed",
"activities": [],
"webhook": null
}
},
"customFields": {
"account": {
"industry": {
"type": "string",
"label": "Industry",
"required": false
},
"annualRevenue": {
"type": "number",
"label": "Annual Revenue",
"required": false
}
},
"contact": {
"jobTitle": {
"type": "string",
"label": "Job Title",
"required": false
}
},
"deal": {
"contractType": {
"type": "string",
"label": "Contract Type",
"required": false,
"options": ["Annual", "Monthly", "One-time"]
}
},
"activity": {
"priority": {
"type": "string",
"label": "Priority",
"required": false,
"options": ["Low", "Medium", "High"]
}
}
},
"subCollections": {
"documents": {
"name": "Documents",
"fields": {
"title": { "type": "string", "required": true },
"url": { "type": "string", "required": true }
}
}
}
}
]
}

Response Fields

Root Level

Team Object

Stage Object (s0-s4)

Custom Fields Structure

Custom fields are organized by entity type (account, contact, deal, activity). Each field definition includes:

Error Handling

The function may throw the following errors:

Use Cases

  1. External Integrations: Third-party systems can fetch team configurations to understand data models and workflows

  2. Automation Tools: MCP servers and automation agents can use this to understand team-specific custom fields and stage activities

  3. Data Migration: Export team metadata for backup or migration purposes

  4. Administrative Dashboards: Build custom admin interfaces that display team configurations

  5. Workflow Automation: Understand stage activities and webhook configurations for automated workflows

Notes

Example: Processing Team Metadata

const result = await getAllTeamsMetadata();
const teams = result.data.teams;
// Find a specific team
const salesTeam = teams.find(t => t.name === "Sales Team");
// Access stage information
console.log(salesTeam.stages.s0.label); // "Initial Contact"
console.log(salesTeam.stages.s0.activities); // ["Schedule discovery call", "Qualify opportunity"]
// Access custom fields
const dealCustomFields = salesTeam.customFields.deal;
Object.keys(dealCustomFields).forEach(fieldKey => {
const field = dealCustomFields[fieldKey];
console.log(`${field.label} (${field.type})`);
});
// Check webhook configuration
if (salesTeam.stages.s0.webhook) {
console.log(`Webhook URL: ${salesTeam.stages.s0.webhook.url}`);
}

Published with Nuclino