admin.publishSignals
Require access to Admin namespace
For an integration to access this method, it must have been granted access to the Admin namespace.
A resource save method that create or update items from signals.
Method parameters
Parameter | Properties | Description |
---|---|---|
integration Integration ID | required | The integration to publish signals from. |
itemsBySignal map(Signal ID => Item save view) | required | Map of signal IDs to item meta-data. |
createOnly bool | default=false | If set to true , skip update of for existing items. |
Result
The result contain a map that links each signal ID in the request to an item save summary, which include a globally unique item ID.
type: object
Field | Description |
---|---|
itemsBySignal map(Signal ID => Save summary) | Save summary for items mapped by signal ID. |
Example
- cURL
- Python
- Go
The curl example uses Basic Auth for simplicity.
# BASIC_AUTH_USERNAME=<Username from Basic Auth credentials>
# BASIC_AUTH_PASSWORD=<Password from Basic Auth credentials>
# INTEGRATION_ID=${BASIC_AUTH_USERNAME}
# SIGNAL_ID=<id from admin.selectSignals result>
# SIGNAL_HASH=<meta.attributesHash from admin.selectSignals result>
curl -u ${BASIC_AUTH_USERNAME}:${BASIC_AUTH_PASSWORD} \
--request POST \
--url 'https://api.clarify.io/v1/rpc' \
--header 'content-type: application/json' \
--header 'X-API-Version: 1.1' \
--data '
{
"jsonrpc": "2.0",
"method": "admin.publishSignals",
"id": "1",
"params": {
"integration": "'${INTEGRATION_ID}'",
"itemsBySignal": {
"'${SIGNAL_ID}'" : {
"annotations": {
"docs-clarify-io/example/source-signal/attributes-hash": "'${SIGNAL_HASH}'",
"docs-clarify-io/example/source-signal/id": "'${SIGNAL_ID}'"
},
"name": "Building status",
"description": "Overall building status, aggregated from environmental sensors."
"labels": {
"data-source": ["Manual"],
"location": ["Banana stand", "Pier"]
},
"sourceType": "aggregation"
"valueType": "enum".
"enumValues": {
"0": "✅",
"1": "🔥"
},
"sampleInterval": "PT15M",
"gapDetection": "PT2H"
}
},
"createOnly": false
}
}'
from pyclarify import Client, Item
client = Client("./clarify-credentials.json")
item = Item(
annotations={
"annotations.docs-clarify-io/example/name: "save_signals",
"annotations.docs-clarify-io/example/publish": "true",
},
name="Building status",
description="Overall building status, aggregated from environmental sensors.",
labels={
"data-source": ["Environmental Sensors"],
"location": ["Banana Stand", "Pier"]
},
sourceType="aggregation",
valueType="enum",
enumValues={
0: "✅",
1: "🔥",
},
sampleInterval="PT15M",
gapDetection="PT2H"
)
items_dict = {
"SIGNAL_ID": item
}
response = client.publish_signals(items_by_signal=item_dict)
This example is for reference only. For a full example of how to select multiple signals and publish using transforms see examples/publish_signals in the clarify-go repo.
package main
import (
"context"
"encoding/json"
"os"
"time"
clarify "github.com/clarify/clarify-go"
"github.com/clarify/clarify-go/query"
"github.com/clarify/clarify-go/views"
)
func main() {
// To select or publish signals, you must grant the integration access to
// the "admin" namespace in the Clarify admin panel.
creds, err := clarify.CredentialsFromFile("clarify-credentials.json")
if err != nil {
panic(err)
}
ctx := context.Background()
client := creds.Client(ctx)
// For this example, the signals we want to publish are created by the same
// integration that we are using to select them. Note that this isn't a
// requirement; for production cases, you may want this integration ID to be
// configured to be something else.
integrationID := creds.Integration
// This example assume SIGNAL_ID is set in the environment; normally you would
// do a client.SelectSignals call instead.
signalID := os.Getenv("SIGNAL_ID")
result, err := client.Admin().PublishSignals(integrationID, map[string]views.ItemSave{
signalID: views.ItemSave{
MetaSave: views.MetaSave{
Annotations: fields.Annotations{
// Annotation keys should be prefixed to avoid collision.
"annotations.docs-clarify-io/example/name": "save_signals",
"annotations.docs-clarify-io/example/publish": "true",
},
},
ItemSaveAttributes: views.ItemSaveAttributes{
Name: "Building status",
Description: "Overall building status, aggregated from environmental sensors.",
Labels: fields.Labels{
// Label keys generally does not need to be prefixed.
"data-source": {"Environmental Sensors"},
"location": {"Banana Stand", "Pier"},
},
SourceType: views.Aggregation,
ValueType: views.Enum,
EnumValues: fields.EnumValues{
0: "✅",
1: "🔥",
},
SampleInterval: fields.AsFixedDuration(15 * time.Minute),
GapDetection: fields.AsFixedDuration(2 * time.Hour),
},
},
}).Do(ctx)
if err != nil {
panic(err)
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
enc.Encode(result)
}