Skip to content

Export manual

Working with Factory Data

Available inEdgeCloudEnterprise

Data in Tier0 unified namespace can be altered and managed through MQTT and APIs with authorization.

MQTT clients can connect to the UNS broker with credentials generated on Tier0.

Generate MQTT credentials in Connect > Source > MQTT Device and make a note of it.

  1. Install and open MQTTX.
  2. Add a connection with the information of the UNS broker and the generated credentials.
    Terminal window
    {
    "Host": "mqtt.tier0.dev",
    "Port": 1883,
    "Client ID": "<generated client ID>",
    "Username": "<generated username>",
    "Password": "<generated password>"
    }
  1. Make sure the client status is normal.
  2. Copy a UNS model topic and publish a message to it through the client.
  • Base URL: https://<your-tier0-host>/openapi/v2
  • Authentication: Send the API key obtained from Tier0 in the x-api-key header.
  • POST /uns/metadata:find — List collections and get the collection ID

    Terminal window
    const base = "https://your-tier0-host/openapi/v2";
    const response = await fetch(`${base}/uns/metadata:find`, {
    method: "POST",
    headers: { "content-type": "application/json", "x-api-key": "your-api-key" },
    body: JSON.stringify({"kind": "collection", "filter": {}, "page": {"mode": "offset", "page": 1, "size": 20}}),
    });
    const result = await response.json();
    if (!response.ok || result.code !== 0) throw new Error(result.error?.code || result.msg);
    console.log(result.data.items);
  • POST /uns/collections/{collectionId}/records:find — List records and get the record ID

    Terminal window
    const base = "https://your-tier0-host/openapi/v2";
    const collectionId = "your-collection-id";
    const response = await fetch(`${base}/uns/collections/${encodeURIComponent(collectionId)}/records:find`, {
    method: "POST",
    headers: { "content-type": "application/json", "x-api-key": "your-api-key" },
    body: JSON.stringify({"limit": 20}),
    });
    const result = await response.json();
    if (!response.ok || result.code !== 0) throw new Error(result.error?.code || result.msg);
    console.log(result.data);
  • POST /uns/collections/{collectionId}/samples:latest — Get the latest sample for a record

    Terminal window
    const base = "https://your-tier0-host/openapi/v2";
    const collectionId = "your-collection-id";
    const response = await fetch(`${base}/uns/collections/${encodeURIComponent(collectionId)}/samples:latest`, {
    method: "POST",
    headers: { "content-type": "application/json", "x-api-key": "your-api-key" },
    body: JSON.stringify({"recordIds": ["record_123"]}),
    });
    const result = await response.json();
    if (!response.ok || result.code !== 0) throw new Error(result.error?.code || result.msg);
    console.log(result.data);
  • POST /uns/collections/{collectionId}/samples:find — Get samples in a time range

    Terminal window
    const base = "https://your-tier0-host/openapi/v2";
    const collectionId = "your-collection-id";
    const response = await fetch(`${base}/uns/collections/${encodeURIComponent(collectionId)}/samples:find`, {
    method: "POST",
    headers: { "content-type": "application/json", "x-api-key": "your-api-key" },
    body: JSON.stringify({"recordIds": ["record_123"], "from": 1792454400000, "to": 1792540800000, "filter": {"temperature": {"$gt": 20}}, "limit": 20}),
    });
    const result = await response.json();
    if (!response.ok || result.code !== 0) throw new Error(result.error?.code || result.msg);
    console.log(result.data);