Cumulocity事件语言-调用外部API [英] Cumulocity Event Language - call external API

查看:140
本文介绍了Cumulocity事件语言-调用外部API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我在您的文档中可以看到的内容,编写CEL时可以在数据库中查询其他数据,但是可以调用外部API吗?是否也可以更新度量以填充缺失值.

Form what I can see on your documentation, it's possible to query the database for additional data when writing CEL, but is it possible to call an external API? Is it also possible to update a Measurement to populate a missing value.

例如,如果我想通过调用特定的API通过添加"c8y_Position"分段的"alt"值来更新度量,请执行以下操作:

For example, if I want to update a measurement by adding the "alt" value of the "c8y_Position" segment by calling a specific API: https://maps.googleapis.com/maps/api/elevation/json?locations=40.714728,-73.998672

是否可以写这种语句:

expression string js:getElevation(lng, lat) [
    function request(lng, lat, callback) {
    var xobj = new XMLHttpRequest();
    // true parameter denotes asynchronous
    xobj.open('GET', 'https://maps.googleapis.com/maps/api/elevation/json?locations=' + lat + ', ' + lng + ', true);
    xobj.onreadystatechange = function () {
            if (xobj.readyState == 4 && xobj.status == "200") {
                callback(xobj.responseText);
            }
        };
        xobj.send(null);
    }
    request(lng, lat, function (data) {
        return data.results.elevation;
    });
]
insert into UpdateMeasurement
select
  e.id as id,
  getElevation(
    getNumber(e, "c8y_Position.lng.value"),
    getNumber(e, "c8y_Position.lat.value")
   ) as c8y_Position.alt
from MeasurementCreated e

是否可以进行这种处理.您是否有有关CEL的更多样本或文档?

Is it possible to make this kind of processing. Do you have more samples or documentation on CEL?

推荐答案

更新:

从现在起,有一段时间可以使用SendRequest流从CEL调用外部API( https://www .cumulocity.com/guides/event-language/data-model/#response-received )流.

It is since a while possible to call external APIs from CEL using the SendRequest stream (https://www.cumulocity.com/guides/event-language/data-model#sendrequest). Results can be received through the ResponseReceived (https://www.cumulocity.com/guides/event-language/data-model/#response-received) stream.

先前的回复:

您可以使用Cumulocity应用程序( https://zapier.com/zapbook/累积/),然后将其应用到许多其他应用程序中.除了Zapier中的500多个应用程序之外,还有一个通用的Webhooks应用程序( https://zapier.com/zapbook/webhook/),该功能允许根据Cumulocity事件发送任何类型的REST请求.

You can get realtime events into Zapier using the Cumulocity application (https://zapier.com/zapbook/cumulocity/) and from there into numerous other applications. Besides the 500+ applications in Zapier, there is also a generic Webhooks application (https://zapier.com/zapbook/webhook/) that allows to send any kind of REST request based on Cumulocity events.

它可能不适用于您的直接示例,但它仍然是一个非常有用的工具.

It may not work for your immediate example, but it's still a very useful tool.

(您无法在Cumulocity中更新度量,您必须创建一个新度量;还需要创建可在地图上显示的位置更新事件.)

(You cannot update measurements in Cumulocity, you would have to create a new one; also you need to create events for location updates that can be shown in maps.)

这篇关于Cumulocity事件语言-调用外部API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆