Mobile API

Mobile API

React Native / Expo integration guide

A dedicated API layer for connecting React Native and Expo mobile apps to the TechSosten platform. Includes authentication, user management, device tracking, repairs, orders, support tickets, and more.

Base URL
https://your-domain.com/api/mobile
Response Format
{ success, data }
Auth Method
Bearer Token
Token Expiry
90 days

Getting Started

Integrate the TechSosten Mobile API into your React Native or Expo app in minutes.

1Copy the API client

Copy src/mobile-sdk/api-client.ts into your React Native project. It provides a fully typed, ready-to-use client.

typescript
import { TechSostenClient } from './api-client';

const api = new TechSostenClient('https://your-domain.com');

2Install dependencies

The client uses the built-in fetch API — no external HTTP libraries needed. For secure token storage, install:

bash
# Store auth tokens securely
npx expo install expo-secure-store

Authentication

Login

MethodPathDescription
POST/auth/loginAuthenticate with email and password

Request Body

json
{
  "email": "user@example.com",
  "password": "your-password",
  "deviceName": "iPhone 15",
  "devicePlatform": "ios"
}

Response

json
{
  "success": true,
  "data": {
    "token": "<bearer-token>",
    "expiresAt": "2026-09-13T12:00:00.000Z",
    "user": {
      "id": "...",
      "email": "user@example.com",
      "name": "John Doe",
      "role": "user",
      "userType": "individual",
      "phone": "+2348000000000",
      "emailVerified": true,
      "plan": {
        "id": "basic",
        "name": "Basic"
      },
      "wallet": {
        "balance": 150,
        "currency": "USD"
      }
    }
  }
}

Register

MethodPathDescription
POST/auth/registerCreate a new account

Request Body

json
{
  "email": "user@example.com",
  "password": "secure-password",
  "fullName": "John Doe",
  "userType": "individual",
  "phone": "+2348000000000",
  "deviceName": "Expo Go",
  "devicePlatform": "android"
}

User Types

individualorganisation

A 6-digit verification code is sent to the email address. Users must verify their email before accessing certain features. Registration automatically returns a bearer token (auto-login).

Authorization

After login or registration, include the bearer token in the Authorization header on every request.

Authorization: Bearer <your-token>

Secure Token Storage (Expo)

typescript
import * as SecureStore from 'expo-secure-store';

// Save token after login
await SecureStore.setItemAsync('authToken', token);

// Retrieve token on app launch
const token = await SecureStore.getItemAsync('authToken');
if (token) {
  api.setToken(token);
}

// Clear token on logout
await SecureStore.deleteItemAsync('authToken');
api.setToken(null);

Security best practice: Never store tokens in AsyncStorage — always use expo-secure-store or react-native-keychain. Tokens are valid for 90 days and are automatically refreshed by re-authenticating.

API Client (TypeScript)

The TechSostenClient class provides a fully typed interface to all mobile endpoints. Copy src/mobile-sdk/api-client.ts into your project.

Quick Start

typescript
import { TechSostenClient } from './api-client';

// Initialize the client
const api = new TechSostenClient('https://your-domain.com');

// 1. Login
const loginRes = await api.auth.login('user@example.com', 'password', 'iPhone 15', 'ios');
const { token, user } = loginRes.data;

// 2. Store and set the token
api.setToken(token);

// 3. Fetch dashboard data
const dashboard = await api.dashboard.get();

// 4. List devices
const devices = await api.devices.list({ page: 1, limit: 20, search: 'Samsung' });

// 5. Create a support ticket
const ticket = await api.tickets.create({
  subject: 'Device not charging',
  description: 'My phone stopped charging after the latest update.',
  priority: 'high',
});

Client API Reference

MethodDescription
api.setToken(token)Set the bearer token for subsequent requests
api.getToken()Get the current bearer token
api.isAuthenticated()Check if a token is set
api.auth.login(email, password)Authenticate and receive a token
api.auth.register(data)Create a new account
api.profile.get()Get current user profile
api.profile.update(data)Update profile fields
api.dashboard.get()Get dashboard summary stats
api.devices.list(params)List devices (paginated)
api.devices.get(id)Get device details
api.clients.list(params)List clients
api.orders.list(params)List orders
api.repairs.list(params)List repairs
api.tickets.list(params)List support tickets
api.tickets.addMessage(id, msg)Add a message to a ticket
api.notifications.list(params)List notifications
api.notifications.markAsRead(id)Mark a notification as read
api.billing.get()Get wallet & billing info

Endpoints

All available mobile API endpoints, organized by resource.

Profile

MethodPathDescription
GET/profileGet current user profile
PATCH/profileUpdate name, phone, language, or currency

Dashboard

MethodPathDescription
GET/dashboardGet summary stats (devices, clients, repairs, tickets, notifications, orders)

Devices

MethodPathDescription
GET/devicesList devices (paginated, searchable)
GET/devices/:idGet device details
POST/devicesRegister a new device
PATCH/devices/:idUpdate device
DELETE/devices/:idDelete device

Clients

MethodPathDescription
GET/clientsList clients (paginated, searchable)
GET/clients/:idGet client details with related data (repairs, orders, warranties)
POST/clientsCreate a new client
PATCH/clients/:idUpdate client
DELETE/clients/:idDelete client

Orders

MethodPathDescription
GET/ordersList orders (paginated, searchable)
GET/orders/:idGet order details
POST/ordersCreate a new order
PATCH/orders/:idUpdate order
DELETE/orders/:idDelete order

Repairs

MethodPathDescription
GET/repairsList repairs (paginated, searchable)
GET/repairs/:idGet repair details
POST/repairsCreate a new repair
PATCH/repairs/:idUpdate repair
DELETE/repairs/:idDelete repair

Tickets (Support)

MethodPathDescription
GET/ticketsList support tickets (paginated, searchable)
GET/tickets/:idGet ticket with messages
POST/ticketsCreate a new ticket
PATCH/tickets/:idUpdate ticket OR add a message

Add a message to a ticket: PATCH /api/mobile/tickets/:id with { "message": "...", "reopen": true }

Notifications

MethodPathDescription
GET/notificationsList notifications (?unreadOnly=true to filter)
PATCH/notificationsMark as read ({ "id": "..." } for one, empty body = all)

Warranties

MethodPathDescription
GET/warrantiesList warranties (paginated, searchable)
POST/warrantiesCreate a warranty

Trade-Ins

MethodPathDescription
GET/trade-insList user's trade-in submissions (paginated)
POST/trade-insSubmit a trade-in request

Inventory

MethodPathDescription
GET/inventoryList inventory items (paginated, searchable)
POST/inventoryAdd an inventory item

Billing

MethodPathDescription
GET/billingGet wallet balance, plan info, and transaction history

Pagination & Search

All list endpoints support these optional query parameters.

ParameterDefaultDescription
page1Page number
limit20Items per page (max 100)
search—Search across relevant fields
sortBycreatedAtField to sort by
sortOrderdescasc or desc

Paginated Response Format

json
{
  "success": true,
  "data": [
    "..."
  ],
  "pagination": {
    "page": 1,
    "limit": 20,
    "total": 50,
    "totalPages": 3
  }
}

Usage with API Client

typescript
// List with search and pagination
const result = await api.devices.list({
  page: 1,
  limit: 20,
  search: 'Samsung',
  sortBy: 'createdAt',
  sortOrder: 'desc',
});

console.log(result.data);        // Device[]
console.log(result.pagination);  // { page, limit, total, totalPages }

Error Handling

All errors follow a consistent format and can be caught using the built-in ApiError class.

json
{
  "success": false,
  "error": "Error message"
}

Error Handling with the API Client

typescript
import { ApiError } from './api-client';

try {
  const result = await api.devices.list();
} catch (error) {
  if (error instanceof ApiError) {
    console.error('Status:', error.status);  // 400, 401, 404, 500
    console.error('Message:', error.message);
    console.error('Body:', error.body);

    if (error.status === 401) {
      // Token expired — redirect to login
      await SecureStore.deleteItemAsync('authToken');
      api.setToken(null);
      navigation.navigate('Login');
    }
  }
}
StatusMeaning
400Bad Request — Invalid input
401Unauthorized — Missing or invalid token
404Not Found — Resource does not exist
500Internal Server Error