Writing data to Clarify

This call inserts data for one or more signals. Each signal is uniquely identified by its Input ID in combination with the Integration ID. If no signal with the given combination exists, a new signal is created.

curl --request POST \
  --url '<<apiURL>>rpc' \
  --header 'content-type: application/json' \
  --header 'Authorization: Bearer <YOUR ACCESS TOKEN>' \
  --header 'X-API-Version: 1.0' \
  --data \
  '
    {
      "jsonrpc" : "2.0",
      "method": "integration.Insert",
      "id": "1",
      "params": {
        "integration": "<YOUR INTEGRATION ID>",
        "data":{
          "times" : ["2021-03-11T21:49:06Z","2021-03-11T21:50:06Z"],
          "series": {
            "<YOUR INPUT ID>" : [1337,1338]
          }
        }
      }
    }
  '
package main

import (
    "bytes"
    "context"
    "encoding/json"
    "fmt"
    "net/http"
    "net/url"
    "time"

    "golang.org/x/oauth2/clientcredentials"
)

type RPCRequest struct {
    Jsonrpc string
    Method  string
    ID      int
    Params  Params
}

type RPCReponse struct {
    Jsonrpc string
    ID      int
    Error   *RPCError              `json:"error,omitempty"`
    Result  map[string]interface{} `json:"result,omitempty"`
}

type RPCError struct {
    Code    int
    Message string
}

type Params struct {
    Integration string
    Inputs      map[string]Signal `json:"inputs,omitempty"`
    Data        Data              `json:"data,omitempty"`
}

type Data struct {
    Times  []string             `json:"times,omitempty"`
    Series map[string][]float64 `json:"series,omitempty"`
}

type Signal struct {
    Name string
}

var (
    clientID      = "<YOUR CLIENT ID>"
    clientSecret  = "<YOUR CLIENT SECRET>"
    integrationID = "<YOUR INTEGRATION ID>"
)

func main() {
    config := &clientcredentials.Config{
        ClientID:       clientID,
        ClientSecret:   clientSecret,
        TokenURL:       "<<tokenURL>>",
        EndpointParams: url.Values{
            "audience": []string{"<<apiURL>>"}
        },
    }

    ctx := context.Background()
    client := config.Client(ctx)
  
    reqBody := RPCRequest{
        Jsonrpc: "2.0",
        Method:  "integration.Insert",
        ID:      1,
        Params: Params{
            Integration: integrationID,
            // Replace the data below with your time series data
            Data: Data{
                Times:  []string{time.Now().Format(time.RFC3339)},
                Series: map[string][]float64{"test12345": {6.5}},
            },
        },
    }

    payloadBuf := new(bytes.Buffer)
    err := json.NewEncoder(payloadBuf).Encode(reqBody)
    if err != nil {
        // TODO: Proper error handling
        fmt.Println(err)
        return
    }

    req, err := http.NewRequest("POST", 
                              "<<apiURL>>rpc", 
                              payloadBuf)
    if err != nil {
        // TODO: Proper error handling
        fmt.Println(err)
        return
    }

    req.Header.Add("X-API-Version", "1.0")
    req.Header.Add("Content-Type", "application/json")

    resp, err := client.Do(req)
    if err != nil {
        // TODO: Proper error handling
        fmt.Println(err)
        return
    }

    // If response code is 200 it was successful
    if resp.StatusCode != 200 {
        fmt.Println("Could not perform request to the endpoint. Response below:")
        fmt.Println(resp.Status)
        return
    }

    rpcResp := RPCReponse{}
    err = json.NewDecoder(resp.Body).Decode(&rpcResp)
    if err != nil {
        // TODO: Proper error handling
        fmt.Println(err)
        return
    }

    if rpcResp.Error != nil {
        fmt.Println("The request was unsucessful. Response below:")
        fmt.Println(rpcResp.Error.Code)
        fmt.Println(rpcResp.Error.Message)
        return
    }

    fmt.Println("The request was successful. Response below:")
    fmt.Println(rpcResp.Result)

}

Meta-data for the signal can be provided either through the admin panel or using the 'integration.SaveSignals' call.

👍

Your decide your Input IDs

The Input ID is decided by you or your program. It can contain up to 40 letters consistent of lower case ASCII characters (a-z), numbers (0-9), dash (-) and underscore (_). This means it's compatible with many hash generation methods, including MD5 or SHA1. It is also compatible with globally unique ID formats such as UUID. However, a more human readable ID such as "banana-stand-temperature" is also fine, as long as your integration can tell the difference.


Did this page help you?