Skip to content

k.utils.CRM ​

Kooboo CRM customer and order pulling

Execution ContextPrerequisitesTypical Use
KScript API, scheduled sync jobsValid crmKey and access to Kooboo CRM endpoints; property name CRM is uppercaseSyncing 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 crmKey in URL query strings: Reading a privileged secret via k.request.queryString leaks it into access logs, proxy logs, browser history, and Referer headers. Store crmKey on the server (for example, in k.DB.keyValue or module/site settings).
  • Enforce authentication and authorization: k.utils.CRM has no built-in route auth checks. Any k.api.* endpoint calling getCustomers() or getOrders() must verify caller authentication and authorization (such as checking k.account.isLogin and 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.

ParameterTypeRequiredDescription
startDateDateYesStart date; submitted as local time
crmKeystringYesCRM 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.

ParameterTypeRequiredDescription
startDateDateYesStart date; submitted as local time
crmKeystringYesCRM 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 ​

PropertyTypeDescription
idstringCustomer ID
kRefstringKooboo reference key
usernamestringUsername
emailstringEmail
registerDateDateRegistration date
registerIPstringRegistration IP
lastModifiedDateLast modified timestamp

CRMOrder Properties ​

PropertyTypeDescription
idstringOrder ID
userIdstringUser ID
typestringOrder type (domain, membership, bandwidth, service, server, topup, apiMarketUsage, AppMarket, domainRenew)
amountnumberOrder amount
creationDateDateCreation date
lastModifiedDateLast modified timestamp
paidbooleanWhether 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;
}