{"info":{"_postman_id":"41c2de83-48e2-46bb-9073-2a9fbe4fc5c3","name":"NGSI-LD Subscriptions","description":"<html><head></head><body><p>This tutorial teaches NGSI-LD users about how to create and manage context data subscriptions. The tutorial builds on the\nentities and <a href=\"https://github.com/FIWARE/tutorials.Getting-Started/tree/NGSI-LD\">Smart Farm</a>\napplication created in the previous examples to enable users to\nunderstand the <a href=\"https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.03.01_60/gs_cim009v010301p.pdf\">NGSI-LD</a> Subscribe/Notify paradigm and how to\nuse NGSI subscriptions within their own code.</p>\n<p>The tutorial refers to devices and actions made within the browser combined with <a href=\"https://ec.haxx.se/\">cUrl</a>\ncommands. The cUrl commands are also available as\n<a href=\"https://github.com/FIWARE/tutorials.Subscriptions/tree/NGSI-LD\">Postman documentation</a>.</p>\n<p>The <code>docker-compose</code> file for this tutorial can be found on GitHub: </p>\n<p><img src=\"https://fiware.github.io/tutorials.Subscriptions/icon/GitHub-Mark-32px.png\" alt=\"GitHub\"> <a href=\"https://github.com/FIWARE/tutorials.Subscriptions/tree/NGSI-LD\">FIWARE 106: Subscribing to Changes in Context</a></p>\n<h1 id=\"subscribing-to-changes-of-state\">Subscribing to Changes of State</h1>\n<blockquote>\n<p>'Another sandwich!' said the King.</p>\n<p>'There's nothing but hay left now,' the Messenger said, peeping into the bag.</p>\n<p>'Hay, then,' the King murmured in a faint whisper.</p>\n<p>Alice was glad to see that it revived him a good deal. 'There's nothing like eating hay when you're faint,' he remarked to her, as he munched away.</p>\n<p>— Lewis Carroll (Through the Looking-Glass and What Alice Found There)</p>\n</blockquote>\n<p>Within the FIWARE platform, an entity represents the state of a physical or conceptual object which exists in the real\nworld. Every smart solution needs to know the current state of these object at any given moment in time.</p>\n<p>The context of each of these entities is constantly changing. For example, within the smart farm example, the\ncontext will change as animals and vehicles move, soil dries out, tasks are allocated on the farm and completed and so on. For a smart solution based on IoT\nsensor data, this issue is even more pressing as the system will constantly be reacting to changes in the real world.</p>\n<p>Until now all the operations we have used to change the state of the system have been <strong>synchronous</strong> - changes have\nbeen made by directly by a user or application and they have been informed of the result. The Orion Context Broker\noffers also an <strong>asynchronous</strong> notification mechanism - applications can subscribe to changes of context information so\nthat they can be informed when something happens. This means the application does not need to continuously poll or\nrepeat query requests.</p>\n<p>Use of the subscription mechanism will therefore reduce both the volume of requests and amount of data being passed\nbetween components within the system. This reduction in network traffic will improve the overall responsiveness.</p>\n<h2 id=\"entities-within-a-smart-agrifood-system\">Entities within a smart Agrifood system</h2>\n<p>The relationship between our entities is defined as shown:</p>\n<p><img src=\"https://fiware.github.io/tutorials.Subscriptions/img/ngsi-ld-entities.png\" alt=\"\"></p>\n<h2 id=\"farm-management-information-system-frontend\">Farm Management Information System frontend</h2>\n<p>In a previous tutorial, a simple Node.js Express application\nwas created. This tutorial will use the monitor page to watch the status of recent requests, and the devices page to alter the machines on the farm. Once the services are running these pages can be accessed from the following URLs:</p>\n<h4 id=\"event-monitor\">Event Monitor</h4>\n<p>The event monitor can be found at: <code>http://localhost:3000/app/monitor</code></p>\n<p><img src=\"https://fiware.github.io/tutorials.Subscriptions/img/monitor.png\" alt=\"FIWARE Monitor\"></p>\n<h4 id=\"device-monitor\">Device Monitor</h4>\n<p>For the purpose of this tutorial, a series of dummy agricultural IoT devices have been created, which will be attached\nto the context broker. Details of the architecture and protocol used can be found in the\n<a href=\"https://github.com/FIWARE/tutorials.IoT-Sensors/tree/NGSI-LD\">IoT Sensors tutorial</a> The state of each device can be\nseen on the UltraLight device monitor web page found at: <code>http://localhost:3000/device/monitor</code></p>\n<p><img src=\"https://fiware.github.io/tutorials.Subscriptions/img/farm-devices.png\" alt=\"FIWARE Monitor\"></p>\n<h1 id=\"architecture\">Architecture</h1>\n<p>This application will make use of two FIWARE components - the\n<a href=\"https://fiware-orion.readthedocs.io/en/latest/\">Orion-LD Context Broker</a>and the\n<a href=\"https://fiware-iotagent-ul.readthedocs.io/en/latest/\">IoT Agent for UltraLight 2.0</a>. Usage of any NGSI-LD Context Broker is sufficient\nfor an application to qualify as <em>“Powered by FIWARE”</em>.</p>\n<p>Currently, the Orion-LD Context Broker relies on open source <a href=\"https://www.mongodb.com/\">MongoDB</a> technology to keep\npersistence of the context data it holds. To request context data from external sources, a simple <strong>Context Provider\nNGSI proxy</strong> has also been added. To visualize and interact with the Context we will add a simple Express <strong>Frontend</strong>\napplication</p>\n<p>Therefore, the architecture will consist of four elements:</p>\n<ul>\n<li>The <a href=\"https://fiware-orion.readthedocs.io/en/latest/\">Orion Context Broker</a> which will receive requests using\n<a href=\"https://forge.etsi.org/swagger/ui/?url=https://forge.etsi.org/gitlab/NGSI-LD/NGSI-LD/raw/master/spec/updated/full_api.json\">NGSI-LD</a></li>\n<li>The FIWARE <a href=\"https://fiware-iotagent-ul.readthedocs.io/en/latest/\">IoT Agent for UltraLight 2.0</a> which will receive\nsouthbound requests using\n<a href=\"https://forge.etsi.org/swagger/ui/?url=https://forge.etsi.org/gitlab/NGSI-LD/NGSI-LD/raw/master/spec/updated/full_api.json\">NGSI-LD</a>\nand convert them to\n<a href=\"https://fiware-iotagent-ul.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual\">UltraLight 2.0</a>\ncommands for the devices</li>\n<li>The underlying <a href=\"https://www.mongodb.com/\">MongoDB</a> database:<ul>\n<li>Used by the Orion Context Broker to hold context data information such as data entities, subscriptions and\nregistrations</li>\n</ul>\n</li>\n<li>The <strong>Tutorial Application</strong> does the following:<ul>\n<li>Offers static <code>@context</code> files defining the context entities within the system.</li>\n<li>Acts as set of dummy <a href=\"https://github.com/FIWARE/tutorials.IoT-Sensors/tree/NGSI-LD\">agricultural IoT devices</a>\nusing the\n<a href=\"https://fiware-iotagent-ul.readthedocs.io/en/latest/usermanual/index.html#user-programmers-manual\">UltraLight 2.0</a>\nprotocol running over HTTP.</li>\n</ul>\n</li>\n</ul>\n<p>Since all interactions between the elements are initiated by HTTP requests, the entities can be containerized and run\nfrom exposed ports.</p>\n<p><img src=\"https://fiware.github.io/tutorials.Subscriptions/img/architecture-ld.png\" alt=\"\"></p>\n<p>The necessary configuration information can be seen in the services section of the associated <code>docker-compose.yml</code> file.\nIt has been described in a previous tutorial</p>\n<h1 id=\"prerequisites\">Prerequisites</h1>\n<h2 id=\"docker\">Docker</h2>\n<p>To keep things simple both components will be run using <a href=\"https://www.docker.com\">Docker</a>. <strong>Docker</strong> is a container\ntechnology which allows to different components isolated into their respective environments.</p>\n<ul>\n<li>To install Docker on Windows follow the instructions <a href=\"https://docs.docker.com/docker-for-windows/\">here</a></li>\n<li>To install Docker on Mac follow the instructions <a href=\"https://docs.docker.com/docker-for-mac/\">here</a></li>\n<li>To install Docker on Linux follow the instructions <a href=\"https://docs.docker.com/install/\">here</a></li>\n</ul>\n<p><strong>Docker Compose</strong> is a tool for defining and running multi-container Docker applications. A\n<a href=\"https://raw.githubusercontent.com/Fiware/tutorials.Entity-Relationships/master/docker-compose.yml\">YAML file</a> is used\nconfigure the required services for the application. This means all container services can be brought up in a single\ncommand. Docker Compose is installed by default as part of Docker for Windows and Docker for Mac, however Linux users\nwill need to follow the instructions found <a href=\"https://docs.docker.com/compose/install/\">here</a></p>\n<p>You can check your current <strong>Docker</strong> and <strong>Docker Compose</strong> versions using the following commands:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-console\">docker-compose -v\ndocker version\n</code></pre>\n<p>Please ensure that you are using Docker version 18.03 or higher and Docker Compose 1.21 or higher and upgrade if\nnecessary.</p>\n<h2 id=\"cygwin\">Cygwin</h2>\n<p>We will start up our services using a simple bash script. Windows users should download <a href=\"http://www.cygwin.com/\">cygwin</a>\nto provide a command-line functionality similar to a Linux distribution on Windows.</p>\n<h1 id=\"start-up\">Start Up</h1>\n<p>All services can be initialized from the command-line by running the bash script provided within the repository. Please\nclone the repository and create the necessary images by running the commands as shown:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-console\">git clone https://github.com/FIWARE/tutorials.Subscriptions.git\ncd tutorials.Subscriptions\ngit checkout NGSI-LD\n\n./services create;\n./services orion;\n</code></pre>\n<p>This command will also import seed data from the previous\nFarm Management Information System example on startup, and provision a series of dummy devices on the farm.</p>\n<blockquote>\n<p>:information_source: <strong>Note:</strong> If you want to clean up and start over again you can do so with the following command:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-console\">./services stop\n</code></pre>\n</blockquote>\n<h1 id=\"using-subscriptions\">Using Subscriptions</h1>\n<p>To follow the tutorial correctly please ensure you have the follow two pages available on separate tabs in your browser before you\nenter any cUrl commands.</p>\n<h4 id=\"fmis-system\">FMIS System</h4>\n<p>Details of various buildings around the farm can be found in the tutorial application. Open <code>http://localhost:3000/app/farm/urn:ngsi-ld:Building:farm001</code> to display a building with an associated filling sensor and thermostat.</p>\n<p><img src=\"https://fiware.github.io/tutorials.Subscriptions/img/fmis.png\" alt=\"\"></p>\n<h4 id=\"event-monitor-1\">Event Monitor</h4>\n<p>The event monitor can be found at: <code>http://localhost:3000/app/monitor</code>.</p>\n<p><img src=\"https://fiware.github.io/tutorials.Subscriptions/img/low-stock-farm.png\" alt=\"\"></p>\n</body></html>","schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json","toc":[{"content":"Subscribing to Changes of State","slug":"subscribing-to-changes-of-state"},{"content":"Architecture","slug":"architecture"},{"content":"Prerequisites","slug":"prerequisites"},{"content":"Start Up","slug":"start-up"},{"content":"Using Subscriptions","slug":"using-subscriptions"}],"owner":"513743","collectionId":"41c2de83-48e2-46bb-9073-2a9fbe4fc5c3","publishedId":"TVspkVQc","public":true,"customColor":{"top-bar":"FFFFFF","right-sidebar":"303030","highlight":"233C68"},"publishDate":"2020-12-15T12:16:51.000Z"},"item":[{"name":"Setting up a simple Subscription","item":[{"name":"Key-Values Payload","id":"b38b758c-0b3c-4bbf-ac05-22fbfbac9ce8","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"Content-Type","value":"application/ld+json","type":"text"},{"key":"NGSILD-Tenant","value":"openiot","type":"text"}],"body":{"mode":"raw","raw":"{\n    \"description\": \"Notify me of low feedstock on Farm:001\",\n    \"type\": \"Subscription\",\n    \"entities\": [\n        {\n            \"type\": \"FillingLevelSensor\"\n        }\n    ],\n    \"watchedAttributes\": [\n        \"filling\"\n    ],\n    \"q\": \"filling>0.6;filling<0.8\",\n    \"notification\": {\n        \"attributes\": [\n            \"filling\",\n            \"controlledAsset\"\n        ],\n        \"format\": \"keyValues\",\n        \"endpoint\": {\n            \"uri\": \"http://tutorial:3000/subscription/low-stock-farm001\",\n            \"accept\": \"application/json\"\n        }\n    },\n    \"@context\": \"http://context/user-context.jsonld\"\n}"},"url":"http://localhost:1026/ngsi-ld/v1/subscriptions/","description":"<p>A new subscription can be added by making a POST request to the <code>/ngsi-ld/v1/subscriptions/</code> endpoint as shown below.</p>\n<p>The body of the POST request consists of two parts, the first section of the request (consisting of <code>entities</code>, <code>type</code>, <code>watchedAttributes</code> and\n<code>q</code>)states that the subscription will be checked whenever the <code>filling</code>  attribute of  a <strong>FillingSensor</strong> entity is altered. This is further refined by the <code>q</code> parameter so that the actual subscription is only fired for any <strong>FillingSensor</strong> entity linked to the <strong>Building</strong> <code>urn:ngsi-ld:Building:farm001</code>  and only when the <code>filling</code> attribute drops below 0.8</p>\n<p>The notification section of the body states that once the conditions of the subscription have been met, a POST\nrequest containing all affected <strong>FillingSensor</strong> entities will be sent to the URL\n<code>http://tutorial:3000/subscription/low-stock-farm001</code> which is handled by the contractor's own system.</p>\n<p>It should be noted that the subscription is using the <code>NGSILD-Tenant</code> header because the IoT Devices have been provisioned using a separate tenant to the buildings for now. Tenants allow for context data to be distributed across separate databases and allow multiple application clients to access the same context broker but keep their own data sets apart.</p>\n<p>Go to the Device Monitor <code>http://localhost:3000/app/farm/urn:ngsi-ld:Building:farm001</code> and start removing hay from the barn. Nothing happens until the barn is half-empty, then a request is sent to\n<code>subscription/low-stock-farm001</code> as shown:</p>\n<h4 id=\"httplocalhost3000appmonitor\"><code>http://localhost:3000/app/monitor</code></h4>\n<p><img src=\"https://fiware.github.io/tutorials.Subscriptions/img/low-stock-farm.png\" alt /></p>\n<h4 id=\"subscription-payload\">Subscription Payload:</h4>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-json\">{\n \"id\": \"urn:ngsi-ld:Notification:5fd0f3824eb81930c97005d8\",\n \"type\": \"Notification\",\n \"subscriptionId\": \"urn:ngsi-ld:Subscription:5fd0ee554eb81930c97005c1\",\n \"notifiedAt\": \"2020-12-09T15:55:46.520Z\",\n \"data\": [\n  {\n   \"id\": \"urn:ngsi-ld:Device:filling001\",\n   \"type\": \"FillingSensor\",\n   \"controllingAsset\": \"urn:ngsi-ld:Building:farm001\",\n   \"filling\": 0.59\n  }\n ]\n}\n</code></pre>\n<p>Code within the Farm Management Information System handles received the POST request as shown:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-javascript\">const NOTIFY_ATTRIBUTES = ['controllingAsset', 'type', 'filling', 'humidity', 'temperature'];\n\nrouter.post('/subscription/:type', (req, res) =&gt; {\n    monitor('notify', req.params.type + ' received', req.body);\n    _.forEach(req.body.data, (item) =&gt; {\n        broadcastEvents(req, item, NOTIFY_ATTRIBUTES);\n    });\n    res.status(204).send();\n});\n\nfunction broadcastEvents(req, item, types) {\n    const message = req.params.type + \" received\";\n    _.forEach(types, (type) =&gt; {\n        if (item[type]) {\n            req.app.get(\"io\").emit(item[type], message);\n        }\n    });\n}\n</code></pre>\n<p>This business logic emits socket I/O events to any registered parties (such as the contractor who will then refill the barn.)</p>\n","urlObject":{"protocol":"http","path":["ngsi-ld","v1","subscriptions",""],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"b38b758c-0b3c-4bbf-ac05-22fbfbac9ce8"},{"name":"NGSI-LD normalized Payload","id":"def367e0-b846-45ad-adc4-7d3536baf72e","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"Content-Type","value":"application/ld+json","type":"text"},{"key":"NGSILD-Tenant","value":"openiot","type":"text"}],"body":{"mode":"raw","raw":"{\n    \"description\": \"Notify me of low feedstock on Farm:001\",\n    \"type\": \"Subscription\",\n    \"entities\": [\n        {\n            \"type\": \"FillingLevelSensor\"\n        }\n    ],\n    \"watchedAttributes\": [\n        \"filling\"\n    ],\n    \"q\": \"filling>0.4;filling<0.6;controlledAsset==%22urn:ngsi-ld:Building:farm001%22\",\n    \"notification\": {\n        \"attributes\": [\n            \"filling\",\n            \"controlledAsset\"\n        ],\n        \"format\": \"normalized\",\n        \"endpoint\": {\n            \"uri\": \"http://tutorial:3000/subscription/low-stock-farm001-ngsild\",\n            \"accept\": \"application/json\"\n        }\n    },\n    \"@context\": \"http://context/user-context.jsonld\"\n}"},"url":"http://localhost:1026/ngsi-ld/v1/subscriptions/","description":"<p>This second subscription will fire when the <code>filling</code> level is between 0.6 and 0.4. The <code>format</code> attribute has been altered to inform the subscriber using NGSI-LD normalized format.</p>\n<h4 id=\"subscription-payload\">Subscription Payload:</h4>\n<p>When a <code>low-stock-farm001-ngsild</code> event is fired, the response is as shown:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-json\">{\n \"id\": \"urn:ngsi-ld:Notification:5fd0fa684eb81930c97005f3\",\n \"type\": \"Notification\",\n \"subscriptionId\": \"urn:ngsi-ld:Subscription:5fd0f69b4eb81930c97005db\",\n \"notifiedAt\": \"2020-12-09T16:25:12.193Z\",\n \"data\": [\n  {\n   \"id\": \"urn:ngsi-ld:Device:filling001\",\n   \"type\": \"FillingSensor\",\n   \"filling\": {\n    \"type\": \"Property\",\n    \"value\": 0.25,\n    \"unitCode\": \"C62\",\n    \"observedAt\": \"2020-12-09T16:25:12.000Z\"\n   },\n   \"controllingAsset\": {\n    \"type\": \"Relationship\",\n    \"object\": \"urn:ngsi-ld:Building:farm001\",\n    \"observedAt\": \"2020-12-09T16:25:12.000Z\"\n   }\n  }\n ]\n}\n</code></pre>\n<p>Because the <code>accept</code> attribute has been set to <code>application/json</code>, the <code>@context</code> is sent as a <code>Link</code> header rather than an attribute within the payload body.</p>\n","urlObject":{"protocol":"http","path":["ngsi-ld","v1","subscriptions",""],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"def367e0-b846-45ad-adc4-7d3536baf72e"},{"name":"NGSI-v2 normalized Payload Copy","id":"71288f8c-ab23-4ed2-98e5-11cd0a6ef70d","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"Content-Type","value":"application/ld+json","type":"text"},{"key":"NGSILD-Tenant","value":"openiot","type":"text"}],"body":{"mode":"raw","raw":"{\n    \"description\": \"Notify me of low feedstock on Farm:001\",\n    \"type\": \"Subscription\",\n    \"entities\": [\n        {\n            \"type\": \"FillingLevelSensor\"\n        }\n    ],\n    \"watchedAttributes\": [\n        \"filling\"\n    ],\n    \"q\": \"filling<0.4;controlledAsset==%22urn:ngsi-ld:Building:farm001%22\",\n    \"notification\": {\n        \"attributes\": [\n            \"filling\",\n            \"controlledAsset\"\n        ],\n        \"format\": \"x-ngsiv2-normalized\",\n        \"endpoint\": {\n            \"uri\": \"http://tutorial:3000/subscription/low-stock-farm001-ngsiv2\",\n            \"accept\": \"application/json\"\n        }\n    },\n    \"@context\": \"http://context/user-context.jsonld\"\n}"},"url":"http://localhost:1026/ngsi-ld/v1/subscriptions/","description":"<p>Context brokers may offer additional custom payload formats (typically prefixed with an <code>x-</code>). The Orion-LD broker offers a backwards compatible <strong>NGSI-v2</strong> payload option for legacy systems.</p>\n<p>This third subscription will fire when the <code>filling</code> level is below 0.4. The <code>format</code> attribute has been altered to inform the subscriber using NGSI-v2 normalized format.</p>\n<h4 id=\"subscription-payload\">Subscription Payload:</h4>\n<p>When a <code>low-stock-farm001-ngsiv2</code> event is fired, the response is a normalzed NGSI-v2 payload as shown:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-json\">{\n \"subscriptionId\": \"urn:ngsi-ld:Subscription:5fd1f31e8b9b83697b855a5d\",\n \"data\": [\n  {\n   \"id\": \"urn:ngsi-ld:Device:filling001\",\n   \"type\": \"https://uri.etsi.org/ngsi-ld/default-context/FillingSensor\",\n   \"https://w3id.org/saref#fillingLevel\": {\n    \"type\": \"Property\",\n    \"value\": 0.33,\n    \"metadata\": {\n     \"unitCode\":  \"C62\",\n     \"accuracy\": {\n      \"type\": \"Property\",\n      \"value\": 0.05\n     },\n     \"observedAt\": \"2020-12-10T10:11:57.000Z\"\n    }\n   },\n   \"https://uri.etsi.org/ngsi-ld/default-context/controllingAsset\": {\n    \"type\": \"Relationship\",\n    \"value\": \"urn:ngsi-ld:Building:farm001\",\n    \"metadata\": {\n     \"observedAt\": \"2020-12-10T10:11:57.000Z\"\n    }\n   }\n  }\n ]\n}\n</code></pre>\n<p>As can be seen, by default the attributes are returned using URN long names. It is also possible to request that the Orion-LD context broker pre-applies a compaction operation to the payload.</p>\n<ul>\n<li><code>x-nsgiv2-keyValues</code> - Key Value pairs with URN attribute names</li>\n<li><code>x-nsgiv2-keyValues-compacted</code> - Key Value pairs with short name attribute aliases</li>\n<li><code>x-ngsiv2-normalized</code> - NGSI-v2 normalized payload with URN attribute names</li>\n<li><code>x-ngsiv2-normalized-compacted</code>- NGSI-v2 normalized payload pairs with short name attribute aliases</li>\n</ul>\n<p>The set of available custom formats will vary between Context Brokers.</p>\n","urlObject":{"protocol":"http","path":["ngsi-ld","v1","subscriptions",""],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"71288f8c-ab23-4ed2-98e5-11cd0a6ef70d"}],"id":"c6c1b6d9-dd40-4daf-8e47-a019091ce8b0","description":"<p>Within the Farm Management Information System, imagine that the farmer wants a contractor to refill his barn with hay when the level has reduced below a set level. It would be possible\nto set up the system so that the contractor was constantly polling for new information, however hay is not removed very\nfrequently so this would be a waste of resources and create a lot of unnecessary data traffic.</p>\n<p>The alternative is to create a subscription which will POST a payload to a \"well-known\" URL whenever a value has\nchanged.</p>\n","_postman_id":"c6c1b6d9-dd40-4daf-8e47-a019091ce8b0"},{"name":"Subscription CRUD Actions","item":[{"name":"Create a Subscription (Product)","id":"4743f5ce-d7d8-4b0d-aa1c-b1868e05d4b4","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"POST","header":[{"key":"content-type","value":"application/ld+json"}],"body":{"mode":"raw","raw":"{\n  \"description\": \"Notify me of all product price changes\",\n  \"type\": \"Subscription\",\n  \"entities\": [{\"type\": \"Product\"}],\n  \"watchedAttributes\": [\"price\"],\n  \"notification\": {\n    \"format\": \"keyValues\",\n    \"endpoint\": {\n      \"uri\": \"http://tutorial:3000/subscription/price-change\",\n      \"accept\": \"application/json\"\n    }\n  },\n   \"@context\": \"http://context-provider:3000/data-models/ngsi-context.jsonld\"\n}"},"url":"http://localhost:1026/ngsi-ld/v1/subscriptions/","description":"<p>This example creates a new subscription. The subscription will fire an asynchronous notification to a URL whenever the\ncontext is changed and the conditions of the subscription - Any Changes to Product prices - are met.</p>\n<p>New subscriptions can be added by making a POST request to the <code>/ngsi-ld/v1/subscriptions/</code> endpoint.</p>\n<p>The subject section of the request states that the subscription will be fired whenever the price attribute of any\nProduct entity is altered.</p>\n<p>The notification section of the body states that a POST request containing all affected entities will be sent to the\n<code>http://tutorial:3000/subscription/price-change</code> endpoint.</p>\n","urlObject":{"protocol":"http","path":["ngsi-ld","v1","subscriptions",""],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"4743f5ce-d7d8-4b0d-aa1c-b1868e05d4b4"},{"name":"Delete a Subscription","id":"953427de-ebf0-4140-a359-f2c6d4146f69","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"DELETE","header":[],"body":{"mode":"raw","raw":""},"url":"http://localhost:1026/ngsi-ld/v1/subscriptions/urn:ngsi-ld:Subscription:5fd8a6ff9d82fd9d6ab1ce75","description":"<p>This example deletes the Subscription with <code>id=urn:ngsi-ld:Subscription:5fd8a6ff9d82fd9d6ab1ce75</code> from the context.</p>\n<p>Subscriptions can be deleted by making a DELETE request to the <code>/ngsi-ld/v1/subscriptions/&lt;subscription-id&gt;</code> endpoint.</p>\n","urlObject":{"protocol":"http","path":["ngsi-ld","v1","subscriptions","urn:ngsi-ld:Subscription:5fd8a6ff9d82fd9d6ab1ce75"],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"953427de-ebf0-4140-a359-f2c6d4146f69"},{"name":"Amend an Existing Subscription","id":"e30fa425-c151-4620-8130-0d8340831c0c","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"PATCH","header":[{"key":"content-type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n    \"notification\": {\n        \"format\": \"normalized\",\n        \"endpoint\": {\n            \"uri\": \"http://tutorial:3000/subscription/price-change\",\n            \"accept\": \"application/json\"\n        }\n    }\n}"},"url":"http://localhost:1026/ngsi-ld/v1/subscriptions/urn:ngsi-ld:Subscription:5fd8a7259d82fd9d6ab1ce76","description":"<p>This example amends an existing subscription with the ID <code>urn:ngsi-ld:Subscription:5fd8a6ff9d82fd9d6ab1ce75</code> and updates the notification URL.</p>\n<p>Subscriptions can be updated making a PATCH request to the <code>/ngsi-ld/v1/subscriptions/&lt;subscription-id&gt;</code> endpoint.</p>\n","urlObject":{"protocol":"http","path":["ngsi-ld","v1","subscriptions","urn:ngsi-ld:Subscription:5fd8a7259d82fd9d6ab1ce76"],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"e30fa425-c151-4620-8130-0d8340831c0c"},{"name":"List all Subscriptions","id":"5ce03a61-042a-474d-b2b0-e7ccfd62e12f","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[{"key":"NGSILD-Tenant","value":"openiot","type":"text"},{"key":"Link","value":"<http://context/ngsi-context.jsonld>; rel=\"http://www.w3.org/ns/json-ld#context\"; type=\"application/ld+json\"","type":"text"}],"url":"http://localhost:1026/ngsi-ld/v1/subscriptions/","description":"<p>This example lists all subscriptions by making a GET request to the <code>/ngsi-ld/v1/subscriptions/</code> endpoint. The list of subscriptions is limited to the tenant defined by the <code>NGSILD-Tenant</code> header (or the default tenant if  the <code>NGSILD-Tenant</code> header is not sent )</p>\n<p>The notification section of each subscription will also include the last time the conditions of the subscription were\nmet, and whether associated the POST action was successful.</p>\n","urlObject":{"protocol":"http","path":["ngsi-ld","v1","subscriptions",""],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"5ce03a61-042a-474d-b2b0-e7ccfd62e12f"},{"name":"Read the detail of a Subscription","id":"7131ded4-51d1-47f5-82a2-a5c0b2702a31","protocolProfileBehavior":{"disableBodyPruning":true},"request":{"method":"GET","header":[],"url":"http://localhost:1026/ngsi-ld/v1/subscriptions/urn:ngsi-ld:Subscription:5fd8a7259d82fd9d6ab1ce76","description":"<p>This example obtains the full details of a subscription with a given ID.</p>\n<p>The response includes additional details in the notification section showing the last time the conditions of the\nsubscription were met, and whether associated the POST action was successful.</p>\n<p>Subscription details can be read by making a GET request to the <code>/ngsi-ld/v1/subscriptions/&lt;subscription-id&gt;</code> endpoint.</p>\n","urlObject":{"protocol":"http","path":["ngsi-ld","v1","subscriptions","urn:ngsi-ld:Subscription:5fd8a7259d82fd9d6ab1ce76"],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"7131ded4-51d1-47f5-82a2-a5c0b2702a31"}],"id":"7ff64579-3710-4bbf-bb97-fc678eab7121","description":"<p>The <strong>CRUD</strong> operations for subscriptions map on to the expected HTTP verbs under the <code>/ngsi-ld/v1/subscriptions/</code> endpoint.</p>\n<ul>\n<li><strong>Create</strong> - HTTP POST</li>\n<li><strong>Read</strong> - HTTP GET</li>\n<li><strong>Update</strong> - HTTP PATCH</li>\n<li><strong>Delete</strong> - HTTP DELETE</li>\n</ul>\n<p>The <code>&lt;subscription-id&gt;</code> is auto generated when the subscription is created and returned in Header of the POST response\nto be used by the other operation thereafter.</p>\n","event":[{"listen":"prerequest","script":{"id":"d95c9bf6-6839-41d6-acd2-4e0b1bf686f0","type":"text/javascript","exec":[""]}},{"listen":"test","script":{"id":"5dcbce8a-d48b-4e69-aaee-f36464b9fb97","type":"text/javascript","exec":[""]}}],"_postman_id":"7ff64579-3710-4bbf-bb97-fc678eab7121"}],"event":[{"listen":"prerequest","script":{"id":"09407533-7a4b-4205-bbfa-c6a43e91dc21","type":"text/javascript","exec":[""]}},{"listen":"test","script":{"id":"1f6e2500-2daf-4dc8-9866-2d7034ef9b3c","type":"text/javascript","exec":[""]}}],"variable":[{"key":"orion","value":"localhost:1026"},{"key":"ngsi-context.jsonld","value":"http://context/ngsi-context.jsonld"}]}