Swaloo Docs
API

Exemples de requetes

Exemples complets en cURL, PHP, JavaScript et Java pour les principaux endpoints.

Exemples de requetes

Tous les exemples ci-dessous utilisent la base URL https://api.swaloo.com/api/v1 et supposent que vous avez obtenu un token JWT via l'authentification.


Configuration client

Avant d'appeler les endpoints, configurez votre client HTTP avec le token JWT.

# Definir le token en variable d'environnement
export TOKEN="votre_jwt_token"

# Toutes les requetes utilisent :
curl -H "Authorization: Bearer $TOKEN" \
     -H "Content-Type: application/ld+json" \
     https://api.swaloo.com/api/v1/...
$token = 'votre_jwt_token';
$baseUrl = 'https://api.swaloo.com/api/v1';

function apiRequest(string $method, string $path, ?array $body = null): array {
    global $token, $baseUrl;
    $ch = curl_init($baseUrl . $path);
    curl_setopt_array($ch, [
        CURLOPT_CUSTOMREQUEST => $method,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [
            'Authorization: Bearer ' . $token,
            'Content-Type: application/ld+json',
        ],
        CURLOPT_POSTFIELDS => $body ? json_encode($body) : null,
    ]);
    $response = curl_exec($ch);
    curl_close($ch);
    return json_decode($response, true);
}
const TOKEN = 'votre_jwt_token';
const BASE_URL = 'https://api.swaloo.com/api/v1';

async function apiRequest(method, path, body = null) {
  const response = await fetch(`${BASE_URL}${path}`, {
    method,
    headers: {
      'Authorization': `Bearer ${TOKEN}`,
      'Content-Type': 'application/ld+json',
    },
    body: body ? JSON.stringify(body) : undefined,
  });
  return response.json();
}
import java.net.http.*;
import java.net.URI;

HttpClient client = HttpClient.newHttpClient();
String token = "votre_jwt_token";
String baseUrl = "https://api.swaloo.com/api/v1";

HttpResponse<String> apiRequest(String method, String path, String body) throws Exception {
    var builder = HttpRequest.newBuilder()
        .uri(URI.create(baseUrl + path))
        .header("Authorization", "Bearer " + token)
        .header("Content-Type", "application/ld+json");
    var req = body != null
        ? builder.method(method, HttpRequest.BodyPublishers.ofString(body)).build()
        : builder.method(method, HttpRequest.BodyPublishers.noBody()).build();
    return client.send(req, HttpResponse.BodyHandlers.ofString());
}

Creer une expedition

POST /shipments

curl -X POST https://api.swaloo.com/api/v1/shipments \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/ld+json" \
  -d '{
    "recipient": {
      "type": "individual",
      "firstName": "Awa",
      "lastName": "Diallo",
      "phoneNumber": "+221771234567",
      "email": "awa.diallo@example.com",
      "address": {
        "street": "12 Rue Carnot, Plateau",
        "city": "Dakar",
        "postalCode": "10200",
        "latitude": 14.6692,
        "longitude": -17.4436,
        "landmark": "Face au marche Sandaga"
      }
    },
    "pickupPoint": "/api/v1/pickup_points/9f1c7e2a-1b3d-4c5e-8a6f-2d4b6c8e0a12",
    "priority": "normal",
    "packageSize": "medium",
    "weight": 2.5,
    "codAmount": "25000.00",
    "handlingOptions": ["fragile", "id_check"],
    "notes": "Appeler avant la livraison.",
    "externalReference": "CMD-20260616-001",
    "items": [
      {"name": "Casque audio", "quantity": 1, "unitType": "unite", "unitPrice": "25000.00", "sku": "SKU-123"}
    ]
  }'

Reponse 201 Created

{
  "@id": "/api/v1/shipments/3fa85f64-5717-4562-b3fc-2c963f66afa6",
  "@type": "Shipment",
  "trackingNumber": "SWL-20260616-A1B2C3",
  "status": "pending",
  "priority": "normal",
  "codAmount": "25000.00",
  "deliveryFee": "2000.00",
  "totalCodToCollect": "27000.00"
}

Lister les expeditions

GET /shipments — Collection paginee avec filtres.

curl -X GET "https://api.swaloo.com/api/v1/shipments?page=1&itemsPerPage=30&status=in_transit" \
  -H "Authorization: Bearer $TOKEN"

Reponse 200 OK

{
  "totalItems": 128,
  "member": [
    {
      "@id": "/api/v1/shipments/3fa85f64-...",
      "@type": "Shipment",
      "trackingNumber": "SWL-20260616-A1B2C3",
      "status": "in_transit",
      "recipient": {"firstName": "Awa", "lastName": "Diallo"}
    }
  ],
  "view": {
    "first": "/api/v1/shipments?page=1",
    "last": "/api/v1/shipments?page=5",
    "next": "/api/v1/shipments?page=2"
  }
}

Modifier une expedition

PATCH /shipments/{id} — Seuls les champs envoyes sont modifies (merge-patch).

curl -X PATCH https://api.swaloo.com/api/v1/shipments/3fa85f64-5717-4562-b3fc-2c963f66afa6 \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/merge-patch+json" \
  -d '{"priority": "high", "codAmount": "30000.00"}'

Reponse 200 OK — Retourne l'expedition modifiee.


Approuver en masse

POST /shipments/bulk-approve

curl -X POST https://api.swaloo.com/api/v1/shipments/bulk-approve \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/ld+json" \
  -d '{"shipmentIds": ["3fa85f64-...", "9c2d1e4f-..."]}'

Reponse 200 OK

{"total": 2, "approved": 2, "failed": 0, "results": [{"id": "3fa85f64-...", "status": "approved"}]}

Import XLSX

POST /shipments/import — Envoi multipart (pas de Content-Type: application/ld+json).

curl -X POST https://api.swaloo.com/api/v1/shipments/import \
  -H "Authorization: Bearer $TOKEN" \
  -F "file=@/chemin/vers/colis.xlsx"

Reponse 200 OK

{"total": 50, "created": 48, "failed": 2, "results": [{"row": 27, "status": "error", "message": "recipient_phone manquant"}]}

Telecharger le bon de livraison (PDF)

GET /shipments/{id}/delivery-note

curl -X GET https://api.swaloo.com/api/v1/shipments/3fa85f64-.../delivery-note \
  -H "Authorization: Bearer $TOKEN" \
  -H "Accept: application/pdf" \
  -o bon-de-livraison.pdf

Retourne un fichier PDF binaire (content-type application/pdf).


API externe (cle API)

POST /external/shipments — Creation avec cle API (pas de JWT requis).

curl -X POST https://api.swaloo.com/api/v1/external/shipments \
  -H "X-API-KEY: votre_cle_api" \
  -H "Content-Type: application/json" \
  -d '{
    "recipient": {
      "firstName": "Awa",
      "lastName": "Diallo",
      "phoneNumber": "+221771234567",
      "address": {"street": "12 Rue Carnot", "city": "Dakar", "postalCode": "10200"}
    },
    "packageSize": "medium",
    "codAmount": "25000.00"
  }'

Reponse 202 Accepted

{"id": "550e8400-e29b-41d4-a716-446655440000", "status": "processing", "message": "Shipment accepted and queued for creation."}

Voir aussi : Endpoints | Authentification | API externe | Erreurs

Exemples de requetes | Documentation Swaloo