A TypeScript client for the Pyrus API. The full documentation for API can be found here
- Install
npm install pyrus-api
- Import client
import {PyrusApiClient} from "pyrus-api";
- Create and authenticate API client
const client = new PyrusApiClient(
{
login: "[email protected]",
security_key: "security_key_from_profile"
}
);
- Get all form templates
const formsResponse = await client.forms.getAll();
const forms = formsResponse.forms;
- Get tasks list by form template
import {OperatorId, toDateString} from "pyrus-api";
const maxDate = new Date("2024-01-12");
const formId = 19963;
const formRegisterResponse = await client.forms.getTasks(
formId,
{
filters: [
{
operator_id: OperatorId.Equals,
field_id: 6,
values: ['555']
},
{
operator_id: OperatorId.LessThan,
field_id: 4,
values: [toDateString(maxDate)]
}
],
include_archived: "y"
}
);
const tasks = formRegisterResponse.tasks;
- Get task with all comments
const taskResponse = await client.tasks.get({id: 2512});
const task = taskResponse.task;
- Add task comment
import type {FormFieldTable} from "pyrus-api";
import {ApprovalChoice} from "pyrus-api";
const taskId = 2512;
const fieldToAdd: FormFieldTable = {
type: FormFieldType.Table,
value: [
{
row_id: 15,
cells: [
{
type: FormFieldType.Text,
name: "Comment",
value: "That's right"
}
]
}
]
};
const taskResponse = await client.tasks.addComment(
taskId,
{
approval_choice: ApprovalChoice.Approved,
field_updates: [fieldToAdd]
}
);
const task = taskResponse.task;
- Create a task
const taskResponse = await client.tasks.create(
{
text: "Help me",
participants: [
{id: 1731},
{email: "[email protected]"}
],
due_date: new Date("2024-11-03")
}
);
const task = taskResponse.task;
- Upload a file
const file = await fs.openAsBlob("C:\\path\\to\\file");
const fileResponse = await client.files.upload(file, "filename");
const fileId = fileResponse.guid;
- Get catalog with all items
const catalogResponse = await client.catalogs.get({id: 1525});
const items = catalogResponse.items;
- Create catalog
const catalogResponse = await client.catalogs.create(
{
name: "NewCatalog",
catalog_headers: ["Header1", "Header2"],
items: [
{values: ["A1", "A2"]},
{values: ["B1", "B2"]}
]
}
);
const catalogId = catalogResponse.catalog_id;
- Sync catalog (All unspecified catalog items and text columns will be deleted)
const catalogResponse = await client.catalogs.sync(
{
id: 1236,
apply: true,
catalog_headers: ["Header1", "Header3"],
items: [
{values: ["A1", "A3"]},
{values: ["C1", "C2"]}
]
}
);
- Get all available contacts
const contactsResponse = await client.contacts.getAll();
- Get all lists
const listsResponse = await client.lists.getAll();
- Get all tasks in list
const listId = 1322;
const listsResponse = await client.lists.getTasksInList(listId);
- Get all organization roles
const rolesResponse = await client.role.getAll();
- Create role
const roleResponse = await client.role.create(
{
name: "TechSupport",
member_add: [1732, 4368]
}
);
- Update role
const roleResponse = await client.role.update(
{
id: 6476,
member_add: [2434],
member_remove: [1732, 4368],
external_id: "CustomIdentifier"
}
);
- Get profile
const profileResponse = await client.profile.get();
- Get inbox
const inboxResponse = await client.lists.getInbox({item_count: 10});
- Get announcement with all comments
const announcementResponse = await client.announcements.get({id: 15353});
const announcement = announcementResponse.announcement;
- Get announcements with all comments
const announcementsResponse = await client.announcements.getAll();
const announcements = announcementsResponse.announcements;
- Add announcement comment
const announcementId = 15353;
const announcementResponse = await client.announcements.addComment(
announcementId,
{
text: "SomeText"
}
);
- Create an announcement
const announcementResponse = await client.announcements.create(
{
text: "New announcement"
}
);