Skip to content

Quick Start Guide

Get up and running with the Attivita API in minutes!

Prerequisites

Before you begin, make sure you have:

  • ✅ An active Attivita customer account
  • ✅ Your API access token
  • ✅ A way to make HTTP requests (curl, Postman, or your programming language)

Step 1: Test Your Connection

Let's verify your API token works by fetching products:

bash
curl -X GET https://api.attivita.de/api/products \
  -H "Authorization: Bearer YOUR_API_ACCESS_TOKEN"
javascript
const response = await fetch('https://api.attivita.de/api/products', {
  headers: {
    'Authorization': 'Bearer YOUR_API_ACCESS_TOKEN'
  }
});

if (response.ok) {
  const products = await response.json();
  console.log(`Found ${products.length} products`);
} else {
  console.error('Authentication failed');
}
python
import requests

headers = {'Authorization': 'Bearer YOUR_API_ACCESS_TOKEN'}
response = requests.get('https://api.attivita.de/api/products', headers=headers)

if response.status_code == 200:
    products = response.json()
    print(f"Found {len(products)} products")
else:
    print("Authentication failed")

Step 2: Enable Sandbox Mode

Before creating real orders, test with sandbox mode:

bash
curl -X POST https://api.attivita.de/api/orders \
  -H "Authorization: Bearer YOUR_API_ACCESS_TOKEN" \
  -H "X-Sandbox-Mode: true" \
  -H "Content-Type: application/json" \
  -d '{
    "products": [{
      "productId": "PRODUCT_ID_HERE",
      "amount": 1
    }]
  }'

Look for the sandboxNotice in the response to confirm sandbox mode is active.

Step 3: Create Your First Order

Once you're comfortable with sandbox mode, create a real order:

javascript
async function createOrder(productId, quantity) {
  const order = {
    products: [{
      productId: productId,
      amount: quantity
    }]
  };

  const response = await fetch('https://api.attivita.de/api/orders', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_ACCESS_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(order)
  });

  if (response.ok) {
    const result = await response.json();
    console.log('Order created:', result.orderNumber);
    console.log('Licenses:', result.items[0].licenses);
  } else {
    const error = await response.json();
    console.error('Order failed:', error);
  }
}

// Example usage
createOrder('507f1f77bcf86cd799439011', 2);
python
import requests
import json

def create_order(product_id, quantity):
    url = 'https://api.attivita.de/api/orders'
    headers = {
        'Authorization': 'Bearer YOUR_API_ACCESS_TOKEN',
        'Content-Type': 'application/json'
    }
    
    order_data = {
        'products': [{
            'productId': product_id,
            'amount': quantity
        }]
    }
    
    response = requests.post(url, headers=headers, json=order_data)
    
    if response.status_code == 200:
        result = response.json()
        print(f"Order created: {result['orderNumber']}")
        print(f"Licenses: {result['items'][0]['licenses']}")
    else:
        print(f"Order failed: {response.json()}")

# Example usage
create_order('507f1f77bcf86cd799439011', 2)

Step 4: Set Up Notifications (Optional)

Choose your preferred notification method:

Option A: Webhooks

bash
curl -X POST https://api.attivita.de/api/webhooks \
  -H "Authorization: Bearer YOUR_API_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://your-server.com/webhook",
    "events": {
      "productOutOfStock": true,
      "productBackInStock": true,
      "productPriceChanged": true
    }
  }'

Option B: Telegram Bot

  1. Open Telegram and search for @attivita_price_stock_bot
  2. Send /start and then /subscribe
  3. Enter your API token when prompted

Complete Example: Order Workflow

Here's a complete example showing the full order workflow:

javascript
class AttivitaAPI {
  constructor(apiToken) {
    this.apiToken = apiToken;
    this.baseUrl = 'https://api.attivita.de/api';
  }

  async request(endpoint, options = {}) {
    const response = await fetch(`${this.baseUrl}${endpoint}`, {
      ...options,
      headers: {
        'Authorization': `Bearer ${this.apiToken}`,
        'Content-Type': 'application/json',
        ...options.headers
      }
    });

    if (!response.ok) {
      const error = await response.json();
      throw new Error(error.error || 'Request failed');
    }

    return response.json();
  }

  async getProducts() {
    return this.request('/products');
  }

  async getProduct(productId) {
    return this.request(`/products/${productId}`);
  }

  async createOrder(products, sandbox = false) {
    const headers = sandbox ? { 'X-Sandbox-Mode': 'true' } : {};
    
    return this.request('/orders', {
      method: 'POST',
      headers,
      body: JSON.stringify({ products })
    });
  }

  async getOrders() {
    return this.request('/orders');
  }

  async getOrder(orderNumber) {
    return this.request(`/orders/${orderNumber}`);
  }
}

// Usage example
async function main() {
  const api = new AttivitaAPI('YOUR_API_ACCESS_TOKEN');

  try {
    // 1. Get available products
    console.log('Fetching products...');
    const products = await api.getProducts();
    console.log(`Found ${products.length} products`);

    // 2. Select a product
    const product = products[0];
    console.log(`\nSelected: ${product.displayName}`);
    console.log(`Price: €${product.price}`);
    console.log(`Stock: ${product.availableStock}`);

    // 3. Test with sandbox first
    console.log('\nTesting with sandbox mode...');
    const sandboxOrder = await api.createOrder(
      [{ productId: product._id, amount: 1 }],
      true
    );
    console.log('Sandbox order successful!');

    // 4. Create real order
    console.log('\nCreating real order...');
    const order = await api.createOrder([
      { productId: product._id, amount: 2 }
    ]);
    
    console.log(`\nOrder #${order.orderNumber} created!`);
    console.log('Licenses received:');
    order.items[0].licenses.forEach(license => {
      console.log(`- ${license.licenseKey}`);
    });

    // 5. Verify order
    const orderDetails = await api.getOrder(order.orderNumber);
    console.log(`\nOrder status: ${orderDetails.status}`);
    
  } catch (error) {
    console.error('Error:', error.message);
  }
}

main();

What's Next?

Now that you've made your first API calls:

  1. Explore the endpoints

  2. Implement best practices

  3. Advanced features

Need Help?

The usage of this API is at your own risk. Attivita GmbH is not responsible for any damages or losses.