# Client Contact API - TypeScript Examples

This document provides TypeScript usage examples for the Client Contact API API using the Repzo SDK.

## Installation

```bash
npm install repzo
```

## Basic Setup

```typescript
import { Service } from "repzo";

// Initialize with your API key
const apiKey = "your-api-key";
const baseURL = "https://api.repzo.me/v1";
```

## API Usage Examples

### Get all client contacts

Retrieve a list of all client contacts with optional filtering and pagination

```typescript
// GET /client-contact

const params = {
  page: 1, // Page number for pagination

  per_page: 1, // Number of items per page

  sort: "example-value", // Sort field

  _id: null, // Filter by contact ID(s)

  search: "example-value", // Search text for contact name

  name: null, // Filter by contact name(s)

  from_updatedAt: 1, // Filter contacts updated after this timestamp

  to_updatedAt: 1, // Filter contacts updated before this timestamp

  from__id: "example-value", // Filter contacts with ID greater than this value

  to__id: "example-value", // Filter contacts with ID less than this value

  sortBy: null, // Advanced sorting options
};

const result = await fetch(
  `${baseURL}/client-contact?${new URLSearchParams(params)}`,
  {
    method: "GET",
    headers: {
      Authorization: `Bearer ${apiKey}`,
      "Content-Type": "application/json",
    },
  },
);

const data = await result.json();
console.log(data);
```

**Expected Response:**

```json
{
  "success": true,
  "data": {
    // Response data structure based on API specification
  }
}
```

---

### Create a new client contact

Create a new client contact

```typescript
// POST /client-contact

const requestBody = {
  // Add your request body properties here
  // Based on the API schema
};

const result = await fetch(`${baseURL}/client-contact`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${apiKey}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify(requestBody),
});

const data = await result.json();
console.log(data);
```

---

### Get a specific client contact

Retrieve a specific client contact by ID

```typescript
// GET /client-contact/{id}

const params = {
  id: "example-value", // Client contact ID
};

const result = await fetch(
  `${baseURL}/client-contact/{id}?${new URLSearchParams(params)}`,
  {
    method: "GET",
    headers: {
      Authorization: `Bearer ${apiKey}`,
      "Content-Type": "application/json",
    },
  },
);

const data = await result.json();
console.log(data);
```

**Expected Response:**

```json
{
  "success": true,
  "data": {
    // Response data structure based on API specification
  }
}
```

---

### Update a client contact

Update an existing client contact

```typescript

```

**Expected Response:**

```json
{
  "success": true,
  "data": {
    // Response data structure based on API specification
  }
}
```

---

### Delete a client contact

Delete an existing client contact

```typescript
// DELETE /client-contact/{id}

const id = "your-resource-id";
const deletePath = "/client-contact/{id}".replace("{id}", id);

const result = await fetch(`${baseURL}${deletePath}`, {
  method: "DELETE",
  headers: {
    Authorization: `Bearer ${apiKey}`,
    "Content-Type": "application/json",
  },
});

const data = await result.json();
console.log(data);
```

**Expected Response:**

```json
{
  "success": true,
  "data": {
    // Response data structure based on API specification
  }
}
```

---

## Using with Repzo SDK Service Types

The Repzo SDK provides TypeScript interfaces for type safety:

```typescript
import { Service } from "repzo";

// Example using SDK types

async function example() {
  // Use the Service.Clientcontact types for better type safety
  // This provides intellisense and compile-time type checking
}
```

## Error Handling

```typescript
try {
  const result = await fetch(`${baseURL}/endpoint`, {
    method: "GET",
    headers: {
      Authorization: `Bearer ${apiKey}`,
      "Content-Type": "application/json",
    },
  });

  if (!result.ok) {
    throw new Error(`HTTP error! status: ${result.status}`);
  }

  const data = await result.json();

  if (!data.success) {
    throw new Error(data.error || "API request failed");
  }

  return data.data;
} catch (error) {
  console.error("API request failed:", error);
  throw error;
}
```

## Pagination

Many API endpoints support pagination:

```typescript
const params = {
  page: 1,
  per_page: 25,
  // other filters...
};

const result = await fetch(
  `${baseURL}/endpoint?${new URLSearchParams(params)}`,
  {
    method: "GET",
    headers: {
      Authorization: `Bearer ${apiKey}`,
      "Content-Type": "application/json",
    },
  },
);

const data = await result.json();

// Access pagination info
console.log("Total items:", data.paging.total);
console.log("Current page:", data.paging.page);
console.log("Total pages:", data.paging.pages);
```
