Customers

    Endpoints pour gérer les clients

    Customers API

    Endpoints pour consulter et créer des clients.

    Lister les clients

    GET /v1/public-api/customers

    Scope requis: read:customers

    Paramètres de requête

    ParamètreTypeDescription
    pagenumberNuméro de page (défaut: 1)
    limitnumberÉléments par page (défaut: 20, max: 100)

    Exemple de requête

    curl -X GET "https://api.nerpsuite.com/v1/public-api/customers" \
      -H "X-API-Key: sk_live_xxx"

    Réponse

    {
      "data": [
        {
          "id": "cust_001",
          "firstName": "Jean",
          "lastName": "Dupont",
          "email": "jean.dupont@email.com",
          "phone": "+33612345678",
          "loyaltyTier": "GOLD",
          "loyaltyPoints": 1500,
          "totalOrders": 25,
          "totalSpent": 4520.00,
          "createdAt": "2023-06-15T10:00:00Z"
        }
      ],
      "total": 1250,
      "page": 1,
      "limit": 20,
      "totalPages": 63
    }

    Obtenir un client

    GET /v1/public-api/customers/:id

    Scope requis: read:customers

    Paramètres de chemin

    ParamètreTypeDescription
    idstringID du client

    Exemple de requête

    curl -X GET "https://api.nerpsuite.com/v1/public-api/customers/cust_001" \
      -H "X-API-Key: sk_live_xxx"

    Réponse

    {
      "id": "cust_001",
      "firstName": "Jean",
      "lastName": "Dupont",
      "email": "jean.dupont@email.com",
      "phone": "+33612345678",
      "loyaltyTier": "GOLD",
      "loyaltyPoints": 1500,
      "totalOrders": 25,
      "totalSpent": 4520.00,
      "createdAt": "2023-06-15T10:00:00Z"
    }

    Créer un client

    POST /v1/public-api/customers

    Scope requis: write:customers

    Corps de la requête

    ChampTypeRequisDescription
    firstNamestringOuiPrénom
    lastNamestringOuiNom de famille
    emailstringNonAdresse email
    phonestringNonNuméro de téléphone

    Au moins un contact (email ou phone) est recommandé pour identifier le client.

    Exemple de requête

    curl -X POST "https://api.nerpsuite.com/v1/public-api/customers" \
      -H "X-API-Key: sk_live_xxx" \
      -H "Content-Type: application/json" \
      -d '{
        "firstName": "Marie",
        "lastName": "Martin",
        "email": "marie.martin@email.com",
        "phone": "+33698765432"
      }'

    Réponse

    {
      "id": "cust_002",
      "firstName": "Marie",
      "lastName": "Martin",
      "email": "marie.martin@email.com",
      "phone": "+33698765432",
      "loyaltyTier": "BRONZE",
      "loyaltyPoints": 0,
      "totalOrders": 0,
      "totalSpent": 0,
      "createdAt": "2024-01-25T14:30:00Z"
    }

    Champs de réponse

    ChampTypeDescription
    idstringIdentifiant unique
    firstNamestringPrénom
    lastNamestringNom
    emailstringAdresse email
    phonestringNuméro de téléphone
    loyaltyTierstringNiveau de fidélité (BRONZE, SILVER, GOLD, PLATINUM)
    loyaltyPointsnumberPoints de fidélité accumulés
    totalOrdersnumberNombre total de commandes
    totalSpentnumberMontant total dépensé
    createdAtstringDate de création (ISO 8601)

    Niveaux de fidélité

    NiveauSeuil
    BRONZE0 - 999 points
    SILVER1000 - 4999 points
    GOLD5000 - 9999 points
    PLATINUM10000+ points

    Cas d'usage

    Synchronisation CRM

    Importez vos clients depuis un CRM externe :

    async function syncCustomerFromCRM(crmCustomer) {
      const response = await fetch('/v1/public-api/customers', {
        method: 'POST',
        headers: {
          'X-API-Key': apiKey,
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          firstName: crmCustomer.first_name,
          lastName: crmCustomer.last_name,
          email: crmCustomer.email,
          phone: crmCustomer.mobile
        })
      });
    
      return response.json();
    }

    Vérification avant commande

    Vérifiez si un client existe avant de créer une commande :

    async function getOrCreateCustomer(email, customerData) {
      // Chercher le client existant
      const customers = await fetch(`/v1/public-api/customers?email=${email}`, opts)
        .then(r => r.json());
    
      if (customers.data.length > 0) {
        return customers.data[0];
      }
    
      // Créer si non trouvé
      return fetch('/v1/public-api/customers', {
        method: 'POST',
        headers: { 'X-API-Key': apiKey, 'Content-Type': 'application/json' },
        body: JSON.stringify(customerData)
      }).then(r => r.json());
    }