Skip to content

Modify Brand Key



POST /api/v1/workspace/change_brand_key

Overview

Set the site brand used by the specified workspaces in batches.

Prerequisites and Usage Steps

External API write permission is required. First, confirm the brand keys allowed for the target site, and obtain valid UUIDs from the workspace list. After submission, call Workspace Details for each workspace to verify content.brandKey. UUIDs that are not found and deleted workspaces are skipped. The response does not provide per-item update results.

Set DF_EXTERNAL_API_URL, DF_EXTERNAL_ACCESS_KEY, and DF_EXTERNAL_SECRET_KEY, then run the example. Replace the example workspace UUIDs, brand, and configuration values with actual values. The signature version is v20240417.

Request Headers

Parameter Name Type Required Description
X-Df-SVersion string Signature version. The following example uses v20240417.
Example: v20240417
How to obtain or enter: Enter it exactly as shown in the example, corresponding to the signature algorithm.
X-Df-Access-Key string Y Request AK information
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 the actual JSON bytes sent, as shown in the example.
X-Df-Timestamp string Y Timestamp at request time
Example: 1785456000
How to obtain or enter: Enter the current Unix time in seconds at the time of the call, for example by running date +%s.
X-Df-Nonce string Y Temporary code generated for the request
Example: b53b47e12e514616ad8cb1f17cb66dce
How to obtain or enter: Generate a new random value for each request, for example uuid.uuid4().hex.

Body Request Parameters

Parameter Name Type Required Description
brandKey string Y Brand key allowed by the site. For example, some sites allow guance or truewatch. Pass an empty string to use the current site's default brand.
Allows null: False
Example: truewatch
How to obtain or enter: The target site administrator provides an enabled brand key.
workspaceUUIDs array Y Array of workspace UUIDs. An empty array does not update any workspace.
Allows null: False
Example: ["wksp_example"]
How to obtain or enter: Copy the workspaces to adjust from content.data[].uuid in the workspace list. Submitting a non-empty array is recommended.

Additional Parameter Notes

Use the External API signing credentials assigned by the target site.

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/change_brand_key"
method = "POST"
body = json.dumps({'brandKey': 'truewatch', 'workspaceUUIDs': ['wksp_example']}, 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)  # Preserve 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 object A successful response is {}, with no per-item results.
{
  "code": 200,
  "content": {},
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

Error Responses

For authentication, rate limiting, and common request errors, see Common Error Definitions.

HTTP Status errorCode Trigger Condition Message or Response Description Resolution
406 ft.ParameterValidationFailed Field type, required status, or constraints do not conform to the parameter table Request field validation failed. The message indicates the field or rule. Verify the fields, types, 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 The JSON format is valid, but the entire body is not a JSON object JSON format error. Place the parameters in a JSON object enclosed in curly braces.
406 ft.InvalidBrandKey The brand key is not in the set allowed for the current site Invalid brand key. Ask the site administrator to verify the available brand keys, or use an empty string to restore the default.

Feedback

Is this page helpful?