ruLog in to Senler

API SDK

Summary

For integrations, you can use the fetch SDK @aisenler/sdk-fetch. The package is generated from the public OpenAPI specification and provides the AiSenlerClient client with API groups as object properties.

Installation

Pin a version for reproducible builds:

npm install github:SenlerBot/Senler-io-sdk#v0.1.6

For the latest commit from main, use:

npm install github:SenlerBot/Senler-io-sdk

The SDK requires Node.js 18+ or another runtime with global fetch.

Basic call

import { AiSenlerClient } from "@aisenler/sdk-fetch";

const client = new AiSenlerClient({
  accessToken: "access_token",
});

const project = await client.projects.getMe();

Methods accept parameters as one camelCase object. For example:

const agents = await client.agents.list({
  projectId: "project_id",
  xSessionId: "session_id",
  limit: 20,
});

In version 0.1.6, the groups for working with segments are named client.segments and client.segmentsPublic. The former names client.leadGroups and client.leadGroupsPublic are no longer used. Agent assignment rules likewise use segmentId in SDK parameters and segment_id in the JSON API.

const segments = await client.segments.getSegments({ projectId });

Project operator

When a team member writes through an external account, chat, or channel that the system sees as a regular sender, an integration can mark the corresponding lead or space as a Project operator:

PATCH /api/leads/{leadId}/project-operator
Content-Type: application/json

{"is_project_operator": true}
PATCH /api/spaces/{spaceId}/project-operator
Content-Type: application/json

{"is_project_operator": true}

The lead endpoint requires permission to manage leads; the space endpoint requires permission to manage spaces. Pass false to remove the mark. It does not grant project access: its sole purpose is to tell automation that new messages and button clicks from this sender come from the project side and must not trigger the agent.

When creating or updating an agent, cancel_pending_response_on_project_operator_message controls a response that has already started. It defaults to true: if a project operator replies first, the pending AI response is canceled. With false, the response may arrive after the operator's message. To change a published agent, update its draft and publish a new version.

The user-facing scenario, entity selection, and safe verification are covered in Project Operator and Agent Replies.

Current mobile app build

This public request does not require a token and returns the current iPhone build available to external TestFlight testers:

GET /api/mobile-app-releases/ios

Example response when a build is available:

{
  "platform": "ios",
  "version_name": "1.8",
  "build_number": "9",
  "source_uploaded_at": "2026-07-15T12:00:00.000Z",
  "expires_at": "2026-10-13T12:00:00.000Z",
  "synced_at": "2026-07-16T00:00:00.000Z"
}

The response contains the platform, version, build number, upload date, expiration date, and the last data update time. While no current build is available, version and date fields may be null; this is a normal response and not a reason to substitute a stale value manually. The request returns build metadata, not an installation link: the user opens TestFlight from the mobile app download dialog in the cabinet.

OAuth token refresh

If the integration uses OAuth and stores a refresh token, pass refreshToken, clientId, and a handler for saving new tokens:

const client = new AiSenlerClient({
  accessToken: "access_token",
  refreshToken: "refresh_token",
  clientId: "client_id",
  onTokenRefreshed: (newAccess, newRefresh) => {
    saveTokens(newAccess, newRefresh);
  },
});

Auto-refresh is enabled only when both refreshToken and clientId are provided.

Support schedule

In version 0.1.6, the client includes the client.supportSchedules group. Developers can use it to work with the support schedule API: read the schedule, update settings, and create or update shifts and operator assignments.

Available methods:

  • getSupportSchedule - get settings, shifts, assignments, and operators;
  • updateSupportScheduleSettings - enable or disable schedule accounting;
  • supportScheduleShifts, updateSupportScheduleShifts, deleteSupportScheduleShifts - create, update, or delete a shift;
  • supportScheduleAssignments, updateSupportScheduleAssignments, deleteSupportScheduleAssignments - create, update, or delete an assignment.
await client.supportSchedules.updateSupportScheduleSettings({
  projectId,
  updateSupportScheduleSettingsDto: {
    enabled: true,
    timezone: "Europe/Moscow",
  },
});

await client.supportSchedules.supportScheduleAssignments({
  projectId,
  createSupportScheduleAssignmentDto: {
    projectMemberId,
    startsAt: new Date("2026-07-13T09:00:00+03:00"),
    endsAt: new Date("2026-07-13T18:00:00+03:00"),
  },
});

The enabled field is required when updating settings. The optional timezone field accepts an IANA time zone name such as Europe/Moscow; the schedule is created and displayed in that zone. A shift has a name, start and end as minutes from the start of the day, and an ends-on-next-day flag; shifts do not have a separate color field. Pass from and to together when requesting a date range. Assignment start and end must include a time zone offset, and the member must be an active support operator.

Management operations require rights to manage the schedule. If an assignment overlaps an existing interval for the same operator, the API returns a clear error: the operator already has an assignment that overlaps the selected interval. In that case, choose another interval, another operator, or edit the existing assignment. A member with current or future assignments cannot be unmarked as a support operator or removed until those assignments are deleted or moved.

Errors

Non-successful HTTP responses throw ResponseError with the original response.

import { ResponseError } from "@aisenler/sdk-fetch";

try {
  await client.projects.getMe();
} catch (error) {
  if (error instanceof ResponseError) {
    console.log(error.response.status);
  }
}

For diagnostics, check the response status, error body, API key or OAuth token permissions, selected project, and required projectId.