Overview
Pixel Patrol can be integrated into any application through our REST API. This guide covers installation options, authentication setup, and basic configuration.
Integration Methods
REST API
The primary integration method for all platforms:
curl -X POST https://api.pixelpatrol.net/functions/v1/submit-media \
-H "Content-Type: application/json" \
-d '{
"api_key": "site_xxxxxxxxxxxxxxxxxxxx",
"content_url": "https://example.com/image.jpg",
"app_media_id": "unique-media-id-123"
}'
SDKs (Coming Soon)
Official SDKs in development:
- JavaScript/TypeScript
- Python
- PHP
- Ruby
- Go
- Java
Authentication Setup
Getting Your Site Key
- Sign up at pixelpatrol.net
- Create your team
- Create a site
- Copy the site key from site settings
Storing Site Keys
Never expose site keys in client-side code or public repositories
Best practices for site key storage:
Environment Variables
Secrets Manager
Key Vault
# .env file
PIXELPATROL_SITE_KEY=site_xxxxxxxxxxxxxxxxxxxx
const apiKey = process.env.PIXELPATROL_SITE_KEY;
Basic Configuration
Initialize Client
Create a reusable client configuration:
class PixelPatrolClient {
constructor(apiKey, options = {}) {
this.apiKey = apiKey;
this.baseUrl = options.baseUrl || 'https://api.pixelpatrol.net/functions/v1';
this.timeout = options.timeout || 30000;
}
async submitMedia(mediaData) {
const response = await fetch(`${this.baseUrl}/submit-media`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
api_key: this.apiKey,
...mediaData
}),
timeout: this.timeout
});
if (!response.ok) {
throw new Error(`API error: ${response.status}`);
}
return response.json();
}
}
const client = new PixelPatrolClient(process.env.PIXELPATROL_SITE_KEY);
Framework Integration
Next.js
// app/api/moderate/route.js
import { NextResponse } from "next/server";
export async function POST(request) {
const body = await request.json();
const response = await fetch(
"https://api.pixelpatrol.net/functions/v1/submit-media",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
api_key: process.env.PIXELPATROL_SITE_KEY,
content_url: body.imageUrl,
app_media_id: body.mediaId,
metadata: body.metadata,
}),
}
);
const result = await response.json();
return NextResponse.json(result);
}
Express.js
const express = require("express");
const app = express();
app.post("/moderate", async (req, res) => {
try {
const response = await fetch(
"https://api.pixelpatrol.net/functions/v1/submit-media",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
api_key: process.env.PIXELPATROL_SITE_KEY,
...req.body,
}),
}
);
const result = await response.json();
res.json(result);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
Django
# views.py
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
import requests
import json
@csrf_exempt
def moderate_content(request):
if request.method == 'POST':
data = json.loads(request.body)
response = requests.post(
'https://api.pixelpatrol.net/functions/v1/submit-media',
headers={
'Content-Type': 'application/json'
},
json={
'api_key': settings.PIXELPATROL_SITE_KEY,
**data
}
)
return JsonResponse(response.json())
Error Handling
Common Errors
Implement proper error handling:
try {
const result = await client.submitMedia(mediaData);
} catch (error) {
if (error.status === 401) {
console.error("Invalid site key");
} else if (error.status === 429) {
console.error("Rate limit exceeded");
} else if (error.status === 400) {
console.error("Invalid request:", error.message);
} else {
console.error("Unexpected error:", error);
}
}
Retry Logic
Implement exponential backoff:
async function submitWithRetry(mediaData, maxRetries = 3) {
for (let i = 0; i < maxRetries; i++) {
try {
return await client.submitMedia(mediaData);
} catch (error) {
if (error.status === 429 || error.status >= 500) {
const delay = Math.pow(2, i) * 1000;
await new Promise((resolve) => setTimeout(resolve, delay));
} else {
throw error;
}
}
}
throw new Error("Max retries exceeded");
}
Testing
Test Environment
Use test mode for development:
const client = new PixelPatrolClient(process.env.PIXELPATROL_TEST_SITE_KEY, {
baseUrl: "https://your-test-supabase-url.supabase.co/functions/v1",
});
Mock Responses
For unit testing:
// __mocks__/pixelpatrol.js
export const mockSubmitMedia = jest.fn().mockResolvedValue({
id: "media_123",
status: "pending",
message: "Media submitted successfully and queued for moderation.",
});
Next Steps
After installation:
- Configure your first site
- Set up moderation rules
- Implement webhooks
- Test the integration
Support
Need help with installation?