Get started with Pixel Patrol in your application
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" }'
# .env file PIXELPATROL_SITE_KEY=site_xxxxxxxxxxxxxxxxxxxx
const apiKey = process.env.PIXELPATROL_SITE_KEY;
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);
// 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); }
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 }); } });
# 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())
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); } }
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"); }
const client = new PixelPatrolClient(process.env.PIXELPATROL_TEST_SITE_KEY, { baseUrl: "https://your-test-supabase-url.supabase.co/functions/v1", });
// __mocks__/pixelpatrol.js export const mockSubmitMedia = jest.fn().mockResolvedValue({ id: "media_123", status: "pending", message: "Media submitted successfully and queued for moderation.", });