[POST] .../v1/target/add
Creates a target. Use this method to create a firm or personal target before adding optional target settings or tracking target history. It returns new_id and validates target type, owner, period type, positive period and value, firm_id, optional stock and currency references and the active-target limit for the same owner, type, firm and user scope. start_date is optional Unix time in seconds for the first target period. When it is omitted or zero, the first period starts at the current server date. Backdated start dates cannot create an already finished first period. user_id is required only when owner is User. currency_id is required only for CrmDealWonAmount targets. Target settings are added afterwards with TargetSetting/AddSingle or TargetSetting/Add. Missing body, invalid enum values, invalid start_date values, invalid references, denied permissions, stock/firm mismatch, active-target limit errors and storage errors are returned as HTTP 200 ErrorResult business errors.
Request Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| currency_id | Int64 | Optional | Target currency ID. Required only when type is CrmDealWonAmount. |
| firm_id | Int64 | Required | Company ID. Required for all targets. |
| name | String | Optional | Target name. Optional; if omitted, it is generated from the target type name and created target ID. Maximum length is 200 characters. |
| owner | String | Required | Target owner scope: Firm creates a global target, User creates a personal target. Allowed values: Default, Firm, User. |
| period | Int32 | Optional | Period value in units from period_type. Must be positive; the current service accepts values from 1 to 99. |
| period_type | String | Required | Period type: Day, Week or Month. Allowed values: Default, Day, Week, Month. |
| repeateable | Boolean | Optional | Indicates whether a new history period should be created after the current period ends. |
| start_date | Int64 | Optional | Optional first period start date as Unix time in seconds. If omitted or zero, the current server date is used; backdated values cannot create an already finished first period. |
| stock_id | Int64 | Optional | Optional stock ID. When provided, the stock must belong to firm_id. |
| type | String | Required | Target type: ReceiptCount, UnitCount, AverageReceipt, SalesAmount or CrmDealWonAmount. Allowed values: Default, ReceiptCount, UnitCount, AverageReceipt, SalesAmount, CrmDealWonAmount. |
| user_id | Int64 | Optional | User ID. Required only when owner is User; ignored for Firm-owned targets. |
| value | Decimal | Required | Target value to reach during the period. Must be greater than zero. |
Request Example
{
"name": "Monthly sales amount",
"type": "SalesAmount",
"owner": "Firm",
"period_type": "Month",
"period": 1,
"value": 50000000.00,
"repeateable": true,
"start_date": 1711929600,
"firm_id": 2,
"stock_id": 8
}
Response Parameters
| Name | Type | Description |
|---|---|---|
| ok | Boolean | Indicates whether the request completed successfully. |
| result | Insert | Created record result. |
Response Example
{
"ok": true,
"result": {
"new_id": 12
}
}