Skip to content

cxRest

Auto-generated documentation from JSDoc comments

cxRest

HTTP client for communicating with the ConnexCS REST API. Provides programmatic access to the full ConnexCS platform through the OpenAPI specification.

Authentication

Authentication is handled automatically via JWT tokens. Simply call cxRest.auth() with your API username to create an authenticated client instance.

API Structure

The ConnexCS API follows RESTful conventions with these standard operations: - GET /{resource} - List all records - GET /{resource}/{id} - Read a specific record - POST /{resource} - Create a new record - PUT /{resource}/{id} - Update a record - DELETE /{resource}/{id} - Delete a record

Common API Resources

Resource Description API Docs
customer Manage customer accounts Customer API
carrier Manage carrier/provider accounts Carrier API
did Manage DID/phone numbers DID API
routing Configure call routing Routing API
switch/user Manage SIP users SIP User API
switch/ip Manage IP authentication Switch API
invoice Billing and invoices Invoice API
payment Payment records Payment API
cdr Call Detail Records CDR API
scriptforge ScriptForge scripts ScriptForge API
class5/ivr Class 5 IVR configuration IVR API
class5/group Ring groups Group API
class5/conference Conference rooms Conference API

Example - Basic CRUD Operations

import cxRest from 'cxRest';

export async function main() {
  const api = cxRest.auth('[email protected]');

  // List all customers (GET /api/cp/customer)
  const customers = await api.get('customer');

  // Get a specific customer (GET /api/cp/customer/{id})
  const customer = await api.get('customer/1234');

  // Create a new customer (POST /api/cp/customer)
  const newId = await api.post('customer', {
    name: 'Acme Corp',
    currency: 'USD',
    status: 'Active'
  });

  // Update a customer (PUT /api/cp/customer/{id})
  await api.put('customer/1234', { name: 'Acme Corporation' });

  // Delete a customer (DELETE /api/cp/customer/{id})
  await api.delete('customer/1234');

  return customers;
}

Example - Working with DIDs

import cxRest from 'cxRest';

export async function main() {
  const api = cxRest.auth('[email protected]');

  // List all DIDs (GET /api/cp/did)
  const dids = await api.get('did');

  // Create a new DID (POST /api/cp/did)
  await api.post('did', {
    did: '441onal234567890',
    customer_id: 1234,
    destination: 'internal:1001'
  });

  // Export DIDs as CSV (GET /api/cp/did.csv)
  const csv = await api.get('did.csv', {}, 'text');

  return dids;
}

Example - Managing SIP Users

import cxRest from 'cxRest';

export async function main() {
  const api = cxRest.auth('[email protected]');

  // List SIP users (GET /api/cp/switch/user)
  const users = await api.get('switch/user');

  // Create a SIP user (POST /api/cp/switch/user)
  await api.post('switch/user', {
    username: '1001',
    password: 'securePassword123',
    customer_id: 1234
  });

  return users;
}

Kind: global class
See

cxRest.baseURL : string

Base URL for the ConnexCS API

Kind: instance property of cxRest

~~cxRest.knex()~~

Use Kysely instead

Kind: instance method of cxRest
Throws:

  • Error Always throws - Knex has been deprecated

cxRest.auth(username) ⇒ cxRest

Authenticate with the ConnexCS API

Kind: static method of cxRest
Returns: cxRest - An authenticated cxRest instance

Param Type Description
username string API username (e.g., '[email protected]')

Example

const api = cxRest.auth('[email protected]');

cxRest.get(path, [params], [responseType]) ⇒ Promise.<(object|Array|string|Blob)>

Retrieve records from the API (GET request)

Use this method to list resources or fetch a specific record by ID.

Kind: static method of cxRest
Returns: Promise.<(object|Array|string|Blob)> - The response data
Throws:

  • Error If the request fails or returns an error status (401, 404, etc.)
Param Type Default Description
path string API endpoint path (e.g., 'customer' or 'customer/1234')
[params] object {} Query parameters for filtering/pagination
[params._limit] number Limit number of results returned
[params._offset] number Offset for pagination
[params._sort] string Field to sort by
[params._order] string Sort order ('asc' or 'desc')
[responseType] string "'json'" Response format: 'json', 'text', or 'blob'

Example

// List all customers (GET /api/cp/customer)
const customers = await api.get('customer');
Example
// Get a specific customer by ID (GET /api/cp/customer/{id})
const customer = await api.get('customer/1234');
Example
// List with pagination and filtering
const page = await api.get('customer', {
  _limit: 10,
  _offset: 20,
  status: 'Active'
});
Example
// Export as CSV (many endpoints support .csv extension)
const csvData = await api.get('did.csv', {}, 'text');
Example
// Get call detail records for a customer
// See: https://api-docs.connexcs.com/#cdr
const cdrs = await api.get('cdr/customer/1234/2024-01-01/2024-01-31');

cxRest.post(path, [data]) ⇒ Promise.<(string|number)>

Create a new record (POST request)

Use this method to create new resources. The required fields vary by endpoint - refer to the API documentation for each resource.

Kind: static method of cxRest
Returns: Promise.<(string|number)> - The ID of the created record
Throws:

  • Error If the request fails or validation errors occur
Param Type Default Description
path string API endpoint path (e.g., 'customer', 'did', 'switch/user')
[data] object {} Data to send in the request body

Example

// Create a customer (POST /api/cp/customer)
// See: https://api-docs.connexcs.com/#customer
const customerId = await api.post('customer', {
  name: 'Acme Corp',
  currency: 'USD',
  status: 'Active',
  portal_access: true
});
Example
// Create a carrier (POST /api/cp/carrier)
// See: https://api-docs.connexcs.com/#carrier
const carrierId = await api.post('carrier', {
  name: 'My Carrier',
  status: 'Active'
});
Example
// Create a SIP user (POST /api/cp/switch/user)
// See: https://api-docs.connexcs.com/#sip-user
await api.post('switch/user', {
  username: '1001',
  password: 'securePass123',
  customer_id: 1234,
  server_id: 5678
});
Example
// Create a DID (POST /api/cp/did)
// See: https://api-docs.connexcs.com/#did
await api.post('did', {
  did: '441234567890',
  customer_id: 1234,
  destination: 'internal:1001'
});

cxRest.put(path, data) ⇒ Promise.<string>

Update an existing record (PUT request)

Use this method to modify existing resources. Only fields included in the request body will be updated - omitted fields remain unchanged.

Kind: static method of cxRest
Returns: Promise.<string> - Confirmation of the update
Throws:

  • Error If the request fails, record not found, or validation errors
Param Type Description
path string API endpoint path including ID (e.g., 'customer/1234')
data object Fields to update

Example

// Update customer name (PUT /api/cp/customer/{id})
// See: https://api-docs.connexcs.com/#customer
await api.put('customer/1234', {
  name: 'Acme Corporation',
  status: 'Active'
});
Example
// Update DID destination (PUT /api/cp/did/{id})
// See: https://api-docs.connexcs.com/#did
await api.put('did/5678', {
  destination: 'internal:2002'
});
Example
// Update SIP user password (PUT /api/cp/switch/user/{id})
await api.put('switch/user/9012', {
  password: 'newSecurePassword456'
});

cxRest.delete(path) ⇒ Promise.<object>

Delete a record (DELETE request)

Use this method to remove resources. This operation is typically irreversible.

Kind: static method of cxRest
Returns: Promise.<object> - Response status object with status and statusText
Throws:

  • Error If the request fails or record not found
Param Type Description
path string API endpoint path including ID (e.g., 'customer/1234')

Example

// Delete a customer (DELETE /api/cp/customer/{id})
const result = await api.delete('customer/1234');
console.log(result.status); // 200
Example
// Delete a DID (DELETE /api/cp/did/{id})
await api.delete('did/5678');
Example
// Delete a SIP user (DELETE /api/cp/switch/user/{id})
await api.delete('switch/user/9012');