# Creating an 'Custom Apama Rule' application via REST Services

**URL:** <https://community.cumulocity.com/t/creating-an-custom-apama-rule-application-via-rest-services/7786>\
**Category:** Knowledge Base\
**Tags:** rest\_api, create\_application, apama\_cep\_rule, Streaming-Analytics-Apama, analytics, devops, cumulocity\
**Created:** [December 10, 2018, 2:07pm UTC](https://community.cumulocity.com/t/creating-an-custom-apama-rule-application-via-rest-services/7786 "2018-12-10T14:07:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chandra\_Babu\_Merla](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@Chandra\_Babu\_Merla](https://community.cumulocity.com/u/Chandra_Babu_Merla)\
**Post date:** [December 10, 2018, 2:07pm UTC](https://community.cumulocity.com/t/creating-an-custom-apama-rule-application-via-rest-services/7786/1 "2018-12-10T14:07:32Z")

</div>

This article describes how to create a Cumulocity application of type 'Custom Apama Rule' via REST calls rather than from GUI.

# Prerequisite

1. Install Postman

2. You need to have an access to cumulocity tenant having all permissions/subscriptions to features shown in this article.

# Create device and send measurements using Simulator

From Device Management, goto Devices \> Simulators. Click on 'New Simulator' and select 'Temperature Measurements' and click on Create.

 ![](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/f/f/ff8e56f553b1e4092e7e6f6f195695df01bd0ae2.png)

Once Simulator is created, select switch so that Simulator state changes from 'paused' to 'running'. Also one can verify that a device named 'Temperature #1' has been created under Devices \> 'All devices' and temperature&nbsp;measurements are appearing in measurements tab.

 ![](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/4/e/4e94301a3285096cb21ef3c85255bdad090a8ed6.png)

# Import REST collection to postman

Refer my other article ([http://techcommunity.softwareag.com/pwiki/-/wiki/Main/An+Example+showing+registration+and+usage+of+SMARTREST1.0+template](http://techcommunity.softwareag.com/pwiki/-/wiki/Main/An+Example+showing+registration+and+usage+of+SMARTREST1.0+template)) Section: Pre requisite (Setup Postman for Cumulocity REST calls), with only difference do not follow step #2, but instead&nbsp;click on Import button in postman and choose the attached .json file.

# Run REST services from imported collection to create 'Custom Apama Rule' application

## 1. Create Application

Run the first REST request providing name and key. Default names are already given, you can continue with same.

 ![](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/7/6/76ae9185aa23885841df4b68907ab1b1cb0842bc.png)

Once the request is successful, an application with the given name is GUI would be present at Administration \> Applications \> Own Applications. Note Application ID and in the Archives tab, there are no files.

 ![](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/1/4/144963f0adb1369114441fc7a4d823cee2ff5f37.png)

 ![](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/2X/a/a83cd9cb7717d4e42d66b7b27b119a0fea81c3be.png)

## 2. Get App ID

Run the second&nbsp;REST request providing App name in URL. Default names are already given, you can continue with the same. Make a note of Application ID from Response.

 ![](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/f/0/f074a2b81b09d783d19407f1519c9ba175a3050c.png)

## 3. Upload Monitor File

Run the third REST request providing Application ID in URL and choosing .mon file to be uploaded from body.&nbsp;Make a note of 'Activate Version&nbsp;ID' from&nbsp;Response headers.

 ![](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/a/a/aa1e5a22ed2eb3e3c5fee20c7f5356e0cee64ba6.png)

Verify now Archives tab of application has a uploaded .mon file, but file is&nbsp; **not&nbsp;active.&nbsp;**

 ![](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/2X/c/cc2297f5c6722639adef7a1a02976cf858b3d350.png)

## 4. Activate uploaded Monitor File

**Important Note:** &nbsp;This forth REST request has been extracted from backend calls happening on GUI, when service is being activated. This is a&nbsp; **NOT SUPPORTED REST API** &nbsp;either from Cumulocity RnD. So might change in future without any intimation.

Run the forth REST request providing Application ID in URL and 'Activate Version&nbsp;ID' noted from earlier response in body of this request.

 ![](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/9/6/969a51836aef400d64ff916873592b86dc2e3a1c.png)

On successful execution of this request, .mon file available in Archives tab of Apama application, it shows Active status.

 ![](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/2X/b/b26fc3510a9c048eb3eb4b4283298b207212e739.png)

Also once Rule becomes active, one could see new measurements 'c8y\_FarenMeasurement' this rule is generating from Device management \> All devices \>&nbsp;'Temperature #1' Farenheit&nbsp;measurements are appearing in measurements tab along with Temperature Measurements in celcius.

 ![](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/5/c/5c65277cd59afbff1765b98857898b51193f6ee7.png)

[TempRulesArchiveExtractIt.7z](https://community.cumulocity.com/uploads/short-url/dm5Rxa2fjAaBwXVsUnW8AUsIouI.7z) (659 Bytes)

[Postman REST Collection for Importing Extract It.7z](https://community.cumulocity.com/uploads/short-url/ws4YXr8nlID2lwEP26ONdmKocVH.7z) (1.22 KB)
