k.utils.CRM
Kooboo CRM customer and order pulling
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
| KScript API, scheduled sync jobs | Valid crmKey and access to Kooboo CRM endpoints; property name CRM is uppercase | Syncing Kooboo internal CRM customer profiles and billing orders |
k.utils.CRM pulls customer and order records from the Kooboo CRM service by start date (attribute name CRM, case-sensitive).
Scope Note
This module targets Kooboo internal CRM billing/customer synchronization and requires a valid crmKey plus access to the Kooboo account CRM endpoint.
Security Note
- Never pass
crmKeyin URL query strings: Reading a privileged secret viak.request.queryStringleaks it into access logs, proxy logs, browser history, andRefererheaders. StorecrmKeyon the server (for example, ink.DB.keyValueor module/site settings). - Enforce authentication and authorization:
k.utils.CRMhas no built-in route auth checks. Anyk.api.*endpoint callinggetCustomers()orgetOrders()must verify caller authentication and authorization (such as checkingk.account.isLoginand admin permissions) before querying CRM data.
Quick Start
js
k.api.get("crmCustomers", () => {
if (!k.account.isLogin) {
k.response.statusCode(401)
return { error: "Unauthorized" }
}
const crmKey = k.DB.keyValue.get("crmKey")?.toString()
if (!crmKey) {
throw new Error("crmKey is not configured")
}
const startDate = new Date("2024-01-01")
const list = k.utils.CRM.getCustomers(startDate, crmKey)
return { count: list.length, customers: list.slice(0, 10) }
})getCustomers()
Pull Kooboo CRM customer records modified or created starting from startDate.
| Parameter | Type | Required | Description |
|---|---|---|---|
startDate | Date | Yes | Start date; submitted as local time |
crmKey | string | Yes | CRM key |
Returns: CRMCustomer[].
js
const crmKey = k.DB.keyValue.get("crmKey")?.toString()
if (!crmKey) {
throw new Error("crmKey is not configured")
}
const startDate = new Date("2024-01-01")
const list = k.utils.CRM.getCustomers(startDate, crmKey)
return {
count: list.length,
customers: list.slice(0, 10)
}getOrders()
Pull Kooboo CRM order records starting from startDate.
| Parameter | Type | Required | Description |
|---|---|---|---|
startDate | Date | Yes | Start date; submitted as local time |
crmKey | string | Yes | CRM key |
Returns: CRMOrder[].
js
const crmKey = k.DB.keyValue.get("crmKey")?.toString()
if (!crmKey) {
throw new Error("crmKey is not configured")
}
const startDate = new Date("2024-01-01")
const orders = k.utils.CRM.getOrders(startDate, crmKey)
return {
count: orders.length,
orders: orders.slice(0, 10)
}Return Structures
CRMCustomer Properties
| Property | Type | Description |
|---|---|---|
id | string | Customer ID |
kRef | string | Kooboo reference key |
username | string | Username |
email | string | |
registerDate | Date | Registration date |
registerIP | string | Registration IP |
lastModified | Date | Last modified timestamp |
CRMOrder Properties
| Property | Type | Description |
|---|---|---|
id | string | Order ID |
userId | string | User ID |
type | string | Order type (domain, membership, bandwidth, service, server, topup, apiMarketUsage, AppMarket, domainRenew) |
amount | number | Order amount |
creationDate | Date | Creation date |
lastModified | Date | Last modified timestamp |
paid | boolean | Whether paid |
TypeScript Definitions
ts
interface KCRM {
getCustomers(startDate: Date, crmKey: string): CRMCustomer[];
getOrders(startDate: Date, crmKey: string): CRMOrder[];
}
interface CRMCustomer {
id: string;
kRef: string;
username: string;
email: string;
registerDate: Date;
registerIP: string;
lastModified: Date;
}
interface CRMOrder {
id: string;
userId: string;
type: string;
amount: number;
creationDate: Date;
lastModified: Date;
paid: boolean;
}