# HTTP | Subscribe and Notify Mechanism

**Prerequisites**

1. Have NGROK software. If you don't have it yet, please go to the following [link NGROK](https://ngrok.com/download).
2. Have Node JS. If you don't have it yet, please go to the following[ link Node JS.](https://nodejs.org/en)
3. Have POSTMAN. If you don't have it yet, please go to the following[ link POSTMAN.](https://www.postman.com/downloads/)

#### Steps <a href="#langkah" id="langkah"></a>

1. Login to your Antares account via Antares Console [https://console.antares.id](https://console.antares.id/)<br>

   <figure><img src="/files/rW47tXKAFXqgwYIpoweb" alt=""><figcaption></figcaption></figure>
2. Create an App, if you already have one, ignore it to proceed to the next process.

<figure><img src="/files/kLuivQn9dp3hi45s1kQm" alt=""><figcaption></figcaption></figure>

3. Create Device, if you already have one, ignore it to proceed to the next process.

<figure><img src="/files/bRmISr4DH4JCaCvY6IiA" alt=""><figcaption></figcaption></figure>

1. Start by writing the programme code to get data from ANTARES. You can use the following programme code: Copy the program code to your computer's local storage then save it in **.js extension** format. In this tutorial, we save it with monitor.js

   <pre class="language-javascript" data-line-numbers><code class="lang-javascript">var express = require('express');
   var app = express();
   var server = require('http').createServer(app);
   var bodyParser = require('body-parser');
   var util = require('util')

   app.use(bodyParser.json());
   app.use(bodyParser.urlencoded({ extended: false }));

   app.post('/monitor', function(req, res, next) {
     console.log(util.inspect(req.body, false, null));
     res.send('ack');
   });


   server.listen(9000, function() {
     console.log('App listening on port 9000');
   });
   </code></pre>

   <figure><img src="/files/7OZ9aCPnpE0bkVeGr3n2" alt=""><figcaption></figcaption></figure>
2. Open a command prompt (windows) or terminal (linux)

   <figure><img src="/files/m1EysWxA5gsp3nQ7Ewoi" alt=""><figcaption></figcaption></figure>

   Enter the directory of the programme code file you saved earlier

   <figure><img src="/files/yIb8JlPKcKVUxfBh9CWz" alt=""><figcaption></figcaption></figure>
3. Run the programme code according to the image below.<br>

   <figure><img src="/files/xm7DUsp6eGIffa4gGnuQ" alt=""><figcaption></figcaption></figure>

   The **successful programme code** can be seen as in the following image.

   <figure><img src="/files/wN2PXoUwc7iNKZGGNRjv" alt=""><figcaption></figcaption></figure>

   Having problems? If yes, execute the following syntax. Otherwise, **ignore this process.**

   <figure><img src="/files/NT8LCBQZM0tS5M0NteL9" alt=""><figcaption></figcaption></figure>

   Install packages that are not yet installed.

   <figure><img src="/files/UL53zbFRTyATB1VYCDXT" alt=""><figcaption></figcaption></figure>

   Allow Access when running the programme code.

   <figure><img src="/files/fydx5cSPmmLbFiDzMIkm" alt=""><figcaption></figcaption></figure>
4. Start running **NGROK. NGROK** will help you to open your localhost to the public domain. Firstly, go to the NGROK directory. **Make sure you have extracted it, so that it is in .exe file format.**

   ```java
   cd download-path/
   ```

   Run **NGROK** using port 9000 in the following way:

   ```java
   ngrok.exe port 9000
   ```
5. Open the Device that you have created earlier. Click the Subscribe button and a pop up menu will appear.

<figure><img src="/files/ejGMLdnbfVGYXGOqGOxg" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/msFQjQBBn7GimSdLNu9z" alt=""><figcaption></figcaption></figure>

**Add /monitor** to the end of the NGROK URL as below.

<figure><img src="/files/mrDKUCSRu3n4xgkOd1dv" alt=""><figcaption></figcaption></figure>

When you have successfully subscribed to it, a pop up will appear.<br>

<figure><img src="/files/IUl9LmJMuQAz7ja022rG" alt=""><figcaption></figcaption></figure>

1. Let's check if your server is getting notifications with an emulator device using POSTMAN. Please open POSTMAN, and fill in all the parameters with the following information.

<table data-header-hidden><thead><tr><th width="111"></th><th width="569.3333333333334"></th></tr></thead><tbody><tr><td><strong>Field</strong></td><td><strong>Value</strong></td></tr><tr><td>URL</td><td><mark style="color:red;"><code>https://platform.antares.id:8443/~/antares-cse/antares-id/your-project-name/your-device-name</code></mark><br>or<br><mark style="color:red;"><code>https://platform.antares.id:8443/~/antares-cse/your-device-ID</code></mark><br><br>Note: <mark style="color:red;"><code>your-device-ID</code></mark> must be starting with <mark style="color:red;"><code>CNT</code></mark>. e.g. <mark style="color:red;"><code>CNT-842419289</code></mark></td></tr><tr><td>Method</td><td><code>POST</code></td></tr></tbody></table>

Let's check if your server is getting notifications with an emulator device using POSTMAN. Please open POSTMAN, and fill in all the parameters with the following information.

<table data-header-hidden><thead><tr><th width="111"></th><th width="569.3333333333334"></th></tr></thead><tbody><tr><td><strong>Field</strong></td><td><strong>Value</strong></td></tr><tr><td>URL</td><td><code>https://platform.antares.id:8443/~/antares-cse/antares-id/your-project-name/your-device-name</code><br>or<br><code>https://platform.antares.id:8443/~/antares-cse/your-device-ID</code><br><br>Note: <code>your-device-ID</code> must be starting with <code>CNT</code>. e.g. <code>CNT-842419289</code></td></tr><tr><td>Method</td><td><code>POST</code></td></tr></tbody></table>

**Header**

|              |                                                         |
| ------------ | ------------------------------------------------------- |
| **Key**      | Value                                                   |
| X-M2M-Origin | <mark style="color:red;">`your-access-key`</mark>       |
| Content-Type | <mark style="color:red;">`application/json;ty=4`</mark> |
| Accept       | <mark style="color:red;">`application/json`</mark>      |

**Body**

```json
{
  {
  "m2m:cin": {
    "xmlns:m2m": "http://www.onem2m.org/xml/protocols",
    "cnf": "application/json",
    "con": "{\"temperature\":30.3, \"humidity\":35.1}"
  }
}
```

As long as you send data, your monitor server application will get the data that the server gets. The data can be seen as follows.

**Congratulations! You have just received a data notification.**


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.antares.id/en/code-and-library-examples/http-or-subscribe-and-notify-mechanism.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
