Skip to content

TypeScript SDK

v1.4.0

Official TypeScript/JavaScript client for the Fliinow API. Full type safety, built-in error handling, and modern promise-based API.

Simple API

Intuitive methods that map directly to API endpoints

100% typed

Full TypeScript support with exported types for everything

Async/await

Modern promise-based API with built-in error handling

Installation

Install the SDK using your favorite package manager:

npm install @fliinow-com/fliinow-partner-api
# or
yarn add @fliinow-com/fliinow-partner-api
# or
pnpm add @fliinow-com/fliinow-partner-api

Quick Start

Initialization

import { FliinowClient } from '@fliinow-com/fliinow-partner-api';

// Initialize the client with your API key
const fliinow = new FliinowClient({
  apiKey: 'your_sandbox_api_key',  // sandbox and production keys are different
  // Optional: use sandbox environment (default: false)
  sandbox: true,
});

Health Check

Verify API connectivity and get server information before starting your integration.

// Check API health and connectivity
const health = await fliinow.health();
console.log(`API Status: ${health.status}`);      // 'ok' or 'degraded'
console.log(`API Version: ${health.version}`);    // '1.13.0'
console.log(`Partner: ${health.partnerCode}`);    // Your partner code
console.log(`Server Time: ${health.timestamp}`);  // ISO 8601 timestamp

Get by External ID

Look up operations using your internal booking reference instead of storing Fliinow IDs.

// Look up operation by your external reference
const operation = await fliinow.operations.getByExternalId('BOOKING-12345');
console.log(`Fliinow ID: ${operation.id}`);      // Internal Fliinow ID
console.log(`Status: ${operation.status}`);      // Current operation status
console.log(`Financing URL: ${operation.financingUrl}`);

Create operation

Create an operation with customer and travel data. The response includes a financingUrl to redirect the customer.

// Create a new financing operation
const operation = await fliinow.operations.create({
  externalId: 'BOOK-2026-00123',
  client: {
    firstName: 'Juan',
    lastName: 'García López',
    email: 'juan@email.com',
    prefix: '+34',
    phone: '612345678',
    documentId: '12345678A',
    documentValidityDate: '31-12-2030',
    gender: 'MALE',
    birthDate: '15-03-1985',
    nationality: 'ESP',
    address: 'Calle Mayor 1',
    city: 'Madrid',
    postalCode: '28001',
    countryCode: 'ESP',
  },
  packageName: 'Viaje romántico a París',
  packageTravel: true,
  travelersNumber: 2,
  flights: [{
    origin: 'MAD',
    destination: 'CDG',
    flightType: 'ROUND_TRIP',
    startDate: '15-03-2026',
    endDate: '22-03-2026',
    price: 450.00,
    isRefundable: true,
    passengerList: [{
      firstName: 'Juan',
      lastName: 'García López',
      birthDate: '15-03-1985',
      gender: 'MALE',
      nationality: 'ESP',
      documentType: 'NATIONAL',
      documentNumber: '12345678A',
    }],
    segments: [{
      origin: 'MAD',
      destination: 'CDG',
      departureDate: '15-03-2026',
      segmentOrder: 1,
    }],
  }],
  hotels: [{
    hotelName: 'Hotel Le Marais',
    address: 'Rue de Rivoli 45',
    postalCode: '75001',
    city: 'París',
    country: 'FRA',
    guestsNumber: 2,
    checkInDate: '15-03-2026',
    checkOutDate: '22-03-2026',
    isRefundable: true,
    price: 1050.00,
  }],
  successRedirectUrl: 'https://yoursite.com/booking/success',  // Optional
  errorRedirectUrl: 'https://yoursite.com/booking/error',      // Optional
  webhookUrl: 'https://yoursite.com/webhooks/operations',      // Required
  totalPrice: 1500.00,
});

console.log(operation.id);           // "op-a0b1c2d4"
console.log(operation.financingUrl); // URL para redirigir al cliente

Check status

After the callback, always verify the actual operation status.

// Get operation status
const status = await fliinow.operations.getStatus('op-a0b1c2d4');

// Possible values: GENERATED | PENDING | CLIENT_REQUESTED | CONFIRMED | REFUSED | EXPIRED | CANCELLED | REFUNDED | ERROR
console.log(status.status);      // 'GENERATED' | 'PENDING' | 'CONFIRMED' | ...
console.log(status.operationId); // Operation ID
console.log(status.updatedAt);   // Last update timestamp

API Methods

The SDK provides methods for all Fliinow API operations:

health()

Check API health and connectivity

operations.create()

Create new financing operation

operations.getByExternalId()

Get operation by your external reference

operations.getStatus()

Get current operation status

operations.list()

List operations with pagination and filters

operations.cancel()

Cancel pending operation

financing.simulate()

Simulate financing offers for an amount (no operation)

financing.getOffers()

Get an operation's financing offers (advanced flow)

financing.create()

Create financing with the chosen offer (advanced flow)

webhooks.acknowledge()

Acknowledge (ACK) a received webhook event

operations.list()

Get a paginated list of your operations with optional filters.

// List operations with filters
const { content, totalElements, totalPages } = await fliinow.operations.list({
  status: 'CONFIRMED',  // Use actual status values
  from: '2026-01-01',
  to: '2026-01-31',
  page: 0,   // 0-based
  size: 20,  // Not 'limit'
});

for (const op of content) {  // Not 'data'
  console.log(`${op.id}: ${op.status}`);
}

operations.cancel()

Cancel an operation in GENERATED, PENDING or CLIENT_REQUESTED status.

// Cancel an operation (GENERATED, PENDING or CLIENT_REQUESTED)
await fliinow.operations.cancel('op-a0b1c2d4');

Advanced Flow

For partners who want to display the financing offers on their own website:

financing.simulate()

Simulate the available offers for an amount, without needing an operation.

// Simulate financing offers for an amount (no operation needed)
const { currency, financialOffers } = await fliinow.financing.simulate(1500.00);

for (const offer of financialOffers) {
  console.log(`${offer.installments} cuotas: ${offer.commonQuota} ${currency}/mes`);
  console.log(`  TAE: ${offer.tae}% · TIN: ${offer.tin}%`);
}

financing.getOffers()

Get the available financing offers to display on your website. Keep each offer's id.

// Get available financing offers for an operation (Advanced Flow)
const { financialOffers } = await fliinow.financing.getOffers('op-a0b1c2d4');

for (const offer of financialOffers) {
  console.log(`Offer #${offer.id} – ${offer.companyName}`);
  console.log(`  ${offer.installments} cuotas · ${offer.commonQuota}€/mes · TAE ${offer.tae}%`);
}

financing.create()

Start the financing with the customer's chosen offer (financialOfferId).

// Create financing with the chosen offer (Advanced Flow)
const result = await fliinow.financing.create({
  operationIdentifier: 'op-a0b1c2d4',
  financialOfferId: 1,  // id from getOffers() response
});

if (result.financingStatus === 'REQUESTED') {
  // Redirect the customer to the provider checkout
  window.location.href = result.paymentUrl;
} else if (result.hasAlternativeFinancialOffers) {
  // REFUSED / ERROR: fetch offers again and retry with another one
}

Webhooks

Receive status change notifications on your webhookUrl and acknowledge them with an ACK.

webhooks.acknowledge()

After processing the webhook Fliinow sends to your webhookUrl, acknowledge it with the same payload received.

// Acknowledge a status webhook (PUT /operations/webhook-events/ack)
// Fliinow POSTs { operationIdentifier, operationStatus, eventId } to your webhookUrl.
app.post('/webhooks/operations', async (req, res) => {
  const event = req.body;

  // ... process the status change ...

  // Confirm receipt with the same payload (idempotent)
  await fliinow.webhooks.acknowledge(event);
  res.sendStatus(200);
});

HTTP Caching with ETags

Use ETags to efficiently poll operation status without transferring unchanged data. Perfect for high-frequency status polling scenarios.

// Efficient status polling with ETags
let cachedStatus = null;
let etag = null;

async function pollOperationStatus(operationIdentifier: string) {
  const headers: Record<string, string> = {};

  // Include ETag from previous response
  if (etag) {
    headers['If-None-Match'] = etag;
  }

  const response = await fliinow.operations.getStatus(operationIdentifier, { headers });

  if (response.status === 304) {
    // Data unchanged, use cached version
    console.log('Status unchanged, using cache');
    return cachedStatus;
  }

  // Store new ETag and data
  etag = response.headers.etag;
  cachedStatus = response.data;
  return cachedStatus;
}

Error Handling

The SDK includes a FliinowError class with detailed error information:

import { FliinowClient, FliinowError } from '@fliinow-com/fliinow-partner-api';

try {
  const operation = await fliinow.operations.create({ ... });
} catch (error) {
  if (error instanceof FliinowError) {
    console.error(`API Error: ${error.code}`);
    console.error(`Message: ${error.message}`);

    switch (error.code) {
      case 'NOT_ACTIVE_OPERATION':
        // Operation is not in a financeable status (error.operationStatus has the current one)
        break;
      case 'NOT_ELIGIBLE_FOR_FINANCING':
        // No eligible financing offers available
        break;
    }
  }
}

TypeScript

All types are exported for use in your code:

// Full TypeScript support with exported types
import type {
  OperationResponse,
  OperationStatus,
  FinancingDetailsResponse,
  FinancialOffer,
  CreateFinancingRequest,
  CreateFinancingResponse,
  WebhookEvent,
  ClientDto,
  FlightDto,
  HotelDto,
  ServiceDto,
  ServiceType,  // ACTIVITY | CRUISE | INSURANCE | TRANSFER
  CreateOperationRequest,
  ListOperationsParams,
  PagedOperationsResponse,
  FinancingProviderInfo,
} from '@fliinow-com/fliinow-partner-api';

// Use types in your code
const handleOperation = (op: OperationResponse) => {
  const status: OperationStatus = op.status;
  // Full autocomplete and type checking
};

// Breaking changes in v1.3.0: CreateOperationRequest renames
// flights/hotels/services and successRedirectUrl/errorRedirectUrl,
// and adds the optional webhookUrl field.