Skip to main content

API Integration

TrendGate provides comprehensive APIs for integrating quality monitoring into your existing workflows and tools.

🔑 Authentication

API Keys

Generate API keys in the TrendGate dashboard:

# Set as environment variable
export TRENDGATE_API_KEY=tg_live_xxxxx

# Or pass in headers
curl -H "Authorization: Bearer tg_live_xxxxx" \
https://api.trendgate.ai/v1/projects

OAuth 2.0

For user-context operations:

const auth = await trendgate.oauth.authorize({
clientId: 'your_client_id',
redirectUri: 'https://your-app.com/callback',
scopes: ['read:metrics', 'write:results']
});

📡 REST API

Base URL

https://api.trendgate.ai/v1

Common Endpoints

Submit Test Results

POST /test-results
Content-Type: application/json

{
"project": "my-app",
"branch": "feature/new-feature",
"commit": "abc123",
"results": {
"framework": "jest",
"tests": 150,
"passed": 145,
"failed": 5,
"duration": 45.2
}
}

Query Quality Metrics

GET /projects/{projectId}/metrics?branch=main&range=7d

Response:
{
"metrics": {
"testPassRate": 95.2,
"coverage": 82.5,
"trends": {
"daily": [...]
}
}
}

Manage Policies

PUT /projects/{projectId}/policies
{
"testPassRate": {
"threshold": 95,
"enforce": true
}
}

🔄 GraphQL API

Endpoint

https://api.trendgate.ai/graphql

Example Queries

# Get project quality overview
query ProjectQuality($projectId: ID!, $branch: String) {
project(id: $projectId) {
name
quality(branch: $branch) {
score
testPassRate
coverage
trends(range: LAST_7_DAYS) {
date
metrics {
testPassRate
coverage
}
}
}
}
}

# Submit test results
mutation SubmitResults($input: TestResultInput!) {
submitTestResults(input: $input) {
id
status
qualityGate {
passed
details
}
}
}

🪝 Webhooks

Configure Webhooks

POST /webhooks
{
"url": "https://your-app.com/webhooks/trendgate",
"events": [
"quality_gate.failed",
"test_run.completed",
"policy.violated"
],
"secret": "your_webhook_secret"
}

Webhook Payload

{
"event": "quality_gate.failed",
"timestamp": "2024-01-20T10:30:00Z",
"data": {
"project": "my-app",
"branch": "feature/payment",
"pr": 123,
"failures": [
{
"policy": "test_pass_rate",
"expected": 95,
"actual": 92
}
]
}
}

🔧 SDK Integration

JavaScript/TypeScript

npm install @trendgate/sdk
import { TrendGate } from '@trendgate/sdk';

const trendgate = new TrendGate({
apiKey: process.env.TRENDGATE_API_KEY
});

// Submit results
await trendgate.submitTestResults({
framework: 'jest',
results: testResults,
coverage: coverageData
});

// Query metrics
const metrics = await trendgate.getMetrics({
project: 'my-app',
branch: 'main',
range: '30d'
});

Python

pip install trendgate
from trendgate import TrendGate

client = TrendGate(api_key="tg_live_xxxxx")

# Submit results
client.submit_test_results(
framework="pytest",
results=test_results,
coverage=coverage_data
)

# Query metrics
metrics = client.get_metrics(
project="my-app",
branch="main",
range="30d"
)

📊 Data Formats

Test Results Schema

interface TestResults {
framework: 'jest' | 'pytest' | 'playwright' | 'custom';
version?: string;
timestamp: string;
duration: number;
summary: {
total: number;
passed: number;
failed: number;
skipped: number;
};
tests: TestCase[];
coverage?: CoverageData;
}

interface TestCase {
name: string;
suite: string;
status: 'passed' | 'failed' | 'skipped';
duration: number;
error?: {
message: string;
stack?: string;
};
}

🛡️ Rate Limits

Default Limits

  • Read operations: 1000/hour
  • Write operations: 500/hour
  • Webhook deliveries: 10,000/hour

Rate Limit Headers

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 950
X-RateLimit-Reset: 1642694400

🚀 Best Practices

1. Batch Operations

// ❌ Multiple API calls
for (const result of results) {
await trendgate.submit(result);
}

// ✅ Single batched call
await trendgate.submitBatch(results);

2. Error Handling

try {
await trendgate.submitResults(data);
} catch (error) {
if (error.code === 'RATE_LIMITED') {
await sleep(error.retryAfter);
await trendgate.submitResults(data);
}
}

3. Webhook Security

// Verify webhook signature
const signature = request.headers['x-trendgate-signature'];
const isValid = trendgate.verifyWebhook(
signature,
request.body,
webhookSecret
);

Start integrating TrendGate into your workflow today!