# Getting Started

> **Quick guide to start using the API**

**Estimated time:** 10 minutes

***

## Prerequisites

* Replenit account (Request invitation email from your Customer Success Manager)
* Your **Tenant ID** and **API Key** from Panel → Settings → API

***

## Step 1: Make Your First API Call

Choose your preferred programming language:

<details>

<summary>🔧 cURL (Terminal)</summary>

```bash
# Replace YOUR_TENANT_ID and YOUR_API_KEY
curl -X POST "https://api.replen.it/customers/YOUR_TENANT_ID" \
  -H "Content-Type: application/json" \
  -H "x-replenit-auth-key: YOUR_API_KEY" \
  -d '[{
    "CustomerId": "test-001",
    "Email": "test@example.com",
    "Name": "Test",
    "Surname": "User",
    "EmailOptin": true,
    "GdprOptin": true
  }]'
```

**Expected output:**

```json
{
  "success": true,
  "message": "Customers saved.",
  "data": {
    "count": 1,
    "processedAt": "2025-12-22T15:00:00Z"
  }
}
```

</details>

<details>

<summary>🐍 Python</summary>

**Install dependencies:**

```bash
pip install requests python-dotenv
```

**Create `test_api.py`:**

```python
import os
import requests
from dotenv import load_dotenv

# Load credentials from .env
load_dotenv()

API_KEY = os.getenv('REPLENIT_API_KEY')
TENANT_ID = os.getenv('REPLENIT_TENANT_ID')

# Validate credentials
if not API_KEY or not TENANT_ID:
    raise ValueError("Missing credentials! Check your .env file")

# API endpoint
url = f"https://api.replen.it/customers/{TENANT_ID}"

# Headers
headers = {
    "Content-Type": "application/json",
    "x-replenit-auth-key": API_KEY
}

# Data (must be an array)
customers = [{
    "CustomerId": "test-001",
    "Email": "test@example.com",
    "Name": "Test",
    "Surname": "User",
    "EmailOptin": True,
    "GdprOptin": True
}]

# Make API call
try:
    response = requests.post(url, headers=headers, json=customers)
    response.raise_for_status()  # Raise error for bad status codes
    
    result = response.json()
    
    if result.get("success"):
        print(f"✅ Success! Created {result['data']['count']} customer(s)")
        print(f"Processed at: {result['data']['processedAt']}")
    else:
        print(f"❌ Error: {result.get('message')}")
        
except requests.exceptions.HTTPError as e:
    print(f"❌ HTTP Error: {e}")
    print(f"Response: {e.response.text}")
except Exception as e:
    print(f"❌ Error: {e}")
```

**Run:**

```bash
python test_api.py
```

</details>

<details>

<summary>🟢 Node.js</summary>

**Install dependencies:**

```bash
npm install axios dotenv
```

**Create `test_api.js`:**

```javascript
require('dotenv').config();
const axios = require('axios');

// Load credentials from .env
const API_KEY = process.env.REPLENIT_API_KEY;
const TENANT_ID = process.env.REPLENIT_TENANT_ID;

// Validate credentials
if (!API_KEY || !TENANT_ID) {
    throw new Error('Missing credentials! Check your .env file');
}

// API endpoint
const url = `https://api.replen.it/customers/${TENANT_ID}`;

// Data (must be an array)
const customers = [{
    CustomerId: 'test-001',
    Email: 'test@example.com',
    Name: 'Test',
    Surname: 'User',
    EmailOptin: true,
    GdprOptin: true
}];

// Make API call
axios.post(url, customers, {
    headers: {
        'Content-Type': 'application/json',
        'x-replenit-auth-key': API_KEY
    }
})
.then(response => {
    if (response.data.success) {
        console.log(`✅ Success! Created ${response.data.data.count} customer(s)`);
        console.log(`Processed at: ${response.data.data.processedAt}`);
    } else {
        console.log(`❌ Error: ${response.data.message}`);
    }
})
.catch(error => {
    if (error.response) {
        console.error('❌ HTTP Error:', error.response.status);
        console.error('Response:', error.response.data);
    } else {
        console.error('❌ Error:', error.message);
    }
});
```

**Run:**

```bash
node test_api.js
```

</details>

***

## Step 2: Verify Success

✅ **Success response:**

```json
{
  "success": true,
  "message": "Customers saved.",
  "data": {
    "count": 1,
    "processedAt": "2025-12-22T15:00:00Z"
  }
}
```

Verify in your Replenit panel → Customers → Search `test-001`

**Common issues:**

* **404**: Wrong tenant ID
* **401**: Check `x-replenit-auth-key` header
* **400**: Request must be an array `[{...}]`

***

## Step 3: Try Other Endpoints

**Import an Order:**

```bash
curl -X POST "https://api.replen.it/orders/YOUR_TENANT_ID" \
  -H "Content-Type: application/json" \
  -H "x-replenit-auth-key: YOUR_API_KEY" \
  -d '[{
    "OrderId": "O-001",
    "Email": "test@example.com",
    "Currency": "USD",
    "TotalRevenue": 99.99,
    "OrderDate": "2025-12-22T10:00:00Z",
    "OrderItems": [{
      "ProductId": "P-001",
      "Sku": "SKU-001",
      "Quantity": 1,
      "Price": 99.99
    }]
  }]'
```

**Sync a Product:**

```bash
curl -X POST "https://api.replen.it/products/YOUR_TENANT_ID" \
  -H "Content-Type: application/json" \
  -H "x-replenit-auth-key: YOUR_API_KEY" \
  -d '[{
    "ProductId": "P-001",
    "ProductName": "Premium Soap",
    "ProductVariants": [{
      "VariantId": "V-001",
      "Sku": "SKU-001",
      "Stock": 100,
      "OriginalPrice": 99.99,
      "Currency": "USD",
      "IsAvailable": true
    }]
  }]'
```

***

## Step 4: Production Tips

**Batch your requests** (recommended: 100-500 records)

```python
# ❌ Don't: 100 API calls
for customer in customers:
    api.post(url, [customer])

# ✅ Do: 1 API call
api.post(url, customers)
```

**Handle rate limits** (100 req/min)

```python
if response.status_code == 429:
    retry_after = int(response.headers.get('Retry-After', 60))
    time.sleep(retry_after)
```

**Secure your keys**

```bash
# Use .env file (add to .gitignore)
REPLENIT_API_KEY=your_key_here
REPLENIT_TENANT_ID=your_tenant_id
```

***

## Next Steps

* [👥 Customers API](/replenit-docs/customers.md) - Field reference
* [🛒 Orders API](/replenit-docs/orders.md) - Order details
* [📦 Products API](/replenit-docs/products.md) - Product catalog
* [🔐 Authentication](/replenit-docs/authentication.md) - Security guide
* [⚡ Rate Limits](/replenit-docs/rate-limits.md) - Limits & retry logic
* [🌟 Best Practices](/replenit-docs/best-practices.md) - Production tips

***

## Need Help?

Contact <support@replen.it>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://replenit.gitbook.io/replenit-docs/getting-started.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
