Usage Limit Update¶
POST /api/v1/workspace/{workspace_uuid}/usage_limit/update
Overview¶
Updates the usage limit configuration for the specified workspace as a whole.
Before Calling and Usage Steps¶
-
Use Usage Limit Query to read the current configuration and prepare the complete updated config. This API replaces the old configuration as a whole; omitting a data type removes the existing configuration item.
-
Use the External API write permission of the current site to submit JSON. After the workspace configuration is written, the service synchronizes it to the data service.
-
If the response is an error or times out, first query the saved config for the workspace to determine whether it was persisted, then handle it according to the target complete configuration. When a success response is received, content is the saved configuration record.
Set DF_EXTERNAL_API_URL, DF_EXTERNAL_ACCESS_KEY, and DF_EXTERNAL_SECRET_KEY, then run the example. Replace the example workspace UUID, brand, and configuration values with actual values. The signature version is v20240417.
Route Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
| workspace_uuid | string | Y | Must be a valid workspace UUID for the target site. Example: wksp_exampleHow to obtain or enter: Get content.data[].uuid from the Workspace List. |
Request Headers¶
| Parameter | Type | Required | Description |
|---|---|---|---|
| X-Df-SVersion | string | Signature version. The following example uses v20240417. Example: v20240417How to obtain or enter: Enter it exactly as shown in the example; it corresponds to the signature algorithm. |
|
| X-Df-Access-Key | string | Y | AK information for the request Example: <access-key>How to obtain or enter: Assigned by the External API administrator. |
| X-Df-Signature | string | Y | Signature information Example: <hex-signature>How to obtain or enter: Calculate HMAC-SHA256 over the method, nonce, path, timestamp, and actual JSON bytes sent, as shown in the example. |
| X-Df-Timestamp | string | Y | Timestamp at request time Example: 1785456000How to obtain or enter: Enter the current Unix seconds at the time of the call, for example, run date +%s. |
| X-Df-Nonce | string | Y | Temporary code generated for the request Example: b53b47e12e514616ad8cb1f17cb66dceHow to obtain or enter: Generate a new random value for each request, for example, uuid.uuid4().hex. |
Body Request Parameters¶
| Parameter | Type | Required | Description |
|---|---|---|---|
| config | json | Y | Available keys are logging (Logs), tracing (Traces), rum (RUM), dialing (Synthetic Testing), profile (Profiling), network (Network), session_replay (Session Replay), keyevent (Events), siem (Security Analytics), backup_log (Log Backup), data_forwarding (Data Forwarding), and metric (Metrics). For each item, openLimit is a required boolean, and value is an optional integer. Passing {} saves an empty configuration. Null allowed: False Example: {"logging": {"openLimit": true, "value": 1000}}How to obtain or enter: Read the existing configuration from Usage Limit Query, merge the business requirements, and submit the complete object. The tenant quota plan is confirmed by the site administrator. |
Additional Notes on Parameters¶
You can enter quota values for the target data types. Different data types use different metering units; actual enforcement is subject to the target site configuration.
Request Example¶
import hmac
import json
import os
import time
import uuid
import requests
server = os.environ["DF_EXTERNAL_API_URL"].rstrip("/")
path = "/api/v1/workspace/wksp_example/usage_limit/update"
method = "POST"
body = json.dumps({'config': {'logging': {'openLimit': True, 'value': 1000}}}, ensure_ascii=False, separators=(',', ':')).encode('utf-8')
timestamp = str(int(time.time()))
nonce = uuid.uuid4().hex
payload = f"{method} {nonce} {path} {timestamp} ".encode("utf-8") + body
signature = hmac.digest(os.environ["DF_EXTERNAL_SECRET_KEY"].encode(), payload, "sha256").hex()
headers = {
"X-Df-Access-Key": os.environ["DF_EXTERNAL_ACCESS_KEY"],
"X-Df-Timestamp": timestamp,
"X-Df-Nonce": nonce,
"X-Df-SVersion": "v20240417",
"X-Df-Signature": signature,
"Content-Type": "application/json",
}
try:
response = requests.request(method, server + path, headers=headers, data=body, timeout=15)
except requests.RequestException:
print('请求结果未知,请先核对目标当前状态及是否已经写入,再决定是否重新签名重试;不要自动重复写请求。')
raise SystemExit(1)
if not 200 <= response.status_code < 300:
print("HTTP", response.status_code, response.text) # Keep errorCode, content, and traceId; do not output AK/SK.
raise SystemExit(1)
data = response.json()["content"]
Response¶
HTTP 200, application/json.
| Field | Type | Description |
|---|---|---|
| content.workspaceUUID | string | Workspace to which the configuration belongs. |
| content.keyCode | string | Configuration key, fixed to UsageLimit. |
| content.config | object | Complete saved configuration. |
| content.config[data type].openLimit | boolean | Whether the quota is enabled for the data type. |
| content.config[data type].value | integer | Optional quota value, interpreted according to the data type and the site's actual metering rules. |
{
"code": 200,
"content": {
"workspaceUUID": "wksp_example",
"keyCode": "UsageLimit",
"config": {
"logging": {
"openLimit": true,
"value": 1000
}
}
},
"errorCode": "",
"message": "",
"success": true,
"traceId": "TRACE-EXAMPLE"
}
Error Response¶
For authentication, rate limiting, and common request errors, see Common Error Definitions.
| HTTP Status | errorCode | Trigger Condition | Message or Response Description | Handling |
|---|---|---|---|---|
| 406 | ft.ParameterValidationFailed | Field type, required status, or constraints do not match the parameter table | Request field validation failed; the message indicates the field or rule. | Check the field, type, and constraints. |
| 400 | ft.RequestJsonFormatError | Invalid request JSON syntax | Request JSON format error. | Read reason, line, and column in content, then correct the request. |
| 400 | ft.JsonFormatError | JSON is valid, but the entire Body is not a JSON object | JSON format error. | Place the parameters in a JSON object enclosed in braces. |
| 400 | ft.ParamsValidateError | The configuration object contains an unknown data type or key, or a field is missing openLimit / has a type mismatch | Parameter validation failed; the message contains field details. | Check each item of config according to the parameter description. |
| 406 | ft.KodoCommonApiErr | Synchronization or daily usage query did not return 200 and is not directly mapped to another status. Some upstream errors retain the upstream HTTP status. | Internal system error; may include an upstream error description. | First query the saved configuration, then check the synchronization status. |