Dokumentation

Willkommen bei der BrandUp API

Die BrandUp API ermöglicht es Ihnen, nahtlos mit unserer Plattform zu interagieren. Diese Dokumentation führt Sie durch alle verfügbaren Endpunkte, Integrationen und Best Practices.

Installation

Die BrandUp SDK kann über npm, yarn oder pnpm installiert werden. Stellen Sie sicher, dass Sie Node.js 14 oder höher installiert haben.

npm install @brandup/sdk
# oder
yarn add @brandup/sdk
# oder
pnpm add @brandup/sdk

Schnellstart

Mit nur wenigen Zeilen Code können Sie die BrandUp API nutzen. Hier ein vollständiges Beispiel für die ersten Schritte:

import { BrandUpClient } from '@brandup/sdk'

// Initialize the client
const client = new BrandUpClient({
  apiKey: process.env.BRANDUP_API_KEY,
  environment: 'production',
  timeout: 30000 // 30 seconds
})

// Fetch shop data
const shops = await client.shops.list({
  limit: 10,
  offset: 0,
  sortBy: 'createdAt',
  order: 'desc'
})

// Get shop details
const shop = await client.shops.get('shop-123')
console.log(shop)

Authentifizierung

Die BrandUp API unterstützt zwei Authentifizierungsmethoden: Bearer Token und API Key.

// Bearer Token Authentication
const response = await fetch('https://api.brandup.de/v1/shops', {
  headers: {
    'Authorization': 'Bearer YOUR_API_TOKEN',
    'Content-Type': 'application/json'
  }
})

// API Key Authentication
const client = new BrandUpClient({
  apiKey: 'YOUR_API_KEY',
  apiSecret: 'YOUR_API_SECRET' // Optional for enhanced security
})

Shop Management API

Verwalten Sie Ihre Shops programmatisch über unsere RESTful API.

// Create a new shop
const newShop = await client.shops.create({
  name: 'My New Shop',
  description: 'A brand new shop',
  location: {
    address: 'Hauptstraße 1',
    city: 'Hamburg',
    postalCode: '20095',
    country: 'DE'
  },
  settings: {
    currency: 'EUR',
    timezone: 'Europe/Berlin'
  }
})

// Update shop information
const updatedShop = await client.shops.update('shop-123', {
  name: 'Updated Shop Name',
  settings: {
    notifications: {
      email: true,
      sms: false
    }
  }
})

// Delete a shop
await client.shops.delete('shop-123')

BrandUp Weather Integration

Nutzen Sie unsere Weather API für wetterbasierte Produktempfehlungen und Alerts:

// BrandUp Weather Integration
const weather = await client.weather.getCurrent({
  shopId: 'shop-123',
  units: 'metric'
})

// Get weather-based recommendations
const recommendations = await client.weather.getRecommendations({
  shopId: 'shop-123',
  conditions: weather.conditions,
  temperature: weather.temperature,
  season: 'summer'
})

// Subscribe to weather alerts
const subscription = await client.weather.subscribeToAlerts({
  shopId: 'shop-123',
  alertTypes: ['storm', 'heatwave', 'frost'],
  webhookUrl: 'https://your-app.com/weather-alerts'
})

Webhooks

Empfangen Sie Echtzeit-Benachrichtigungen über Ereignisse in Ihrem BrandUp-Account.

// Register a webhook
const webhook = await client.webhooks.create({
  url: 'https://your-app.com/webhooks/brandup',
  events: ['shop.created', 'shop.updated', 'order.completed'],
  secret: 'your-webhook-secret'
})

// Verify webhook signature (in your webhook handler)
const signature = request.headers['x-brandup-signature']
const isValid = client.webhooks.verifySignature(
  signature,
  request.body,
  'your-webhook-secret'
)

if (!isValid) {
  throw new Error('Invalid webhook signature')
}

// Handle webhook events
switch (event.type) {
  case 'shop.created':
    console.log('New shop created:', event.data)
    break
  case 'order.completed':
    console.log('Order completed:', event.data)
    break
}

Fehlerbehandlung

Robuste Fehlerbehandlung ist essentiell für produktive Anwendungen.

// Error handling with try-catch
try {
  const shop = await client.shops.get('shop-123')
} catch (error) {
  if (error.code === 'SHOP_NOT_FOUND') {
    console.error('Shop does not exist')
  } else if (error.code === 'RATE_LIMIT_EXCEEDED') {
    console.error('Too many requests, retry after:', error.retryAfter)
  } else if (error.code === 'INVALID_API_KEY') {
    console.error('Invalid API credentials')
  } else {
    console.error('Unexpected error:', error.message)
  }
}

// Global error handler
client.on('error', (error) => {
  console.error('BrandUp SDK Error:', error)
  // Send to your error tracking service
})
Error CodeDescriptionHTTP Status
INVALID_API_KEYUngültiger oder fehlender API-Schlüssel401
RATE_LIMIT_EXCEEDEDZu viele Anfragen429
RESOURCE_NOT_FOUNDRessource nicht gefunden404

Sicherheit & Best Practices

API-Schlüssel sicher aufbewahren

  • • Niemals im Frontend-Code speichern
  • • Umgebungsvariablen verwenden
  • • Regelmäßig rotieren
  • • Zugriffsrechte minimieren

HTTPS erforderlich

  • • Alle API-Anfragen über HTTPS
  • • TLS 1.2 oder höher
  • • Zertifikatsvalidierung aktivieren
  • • HTTP-Anfragen werden abgelehnt

SDKs & Libraries

Weitere Ressourcen