{"info":{"_postman_id":"05e4b8a2-b7fd-4689-afd4-efb71cc2f17e","name":"FIWARE Entity Relationships","description":"<html><head></head><body><p>This tutorial builds on the data created in the previous <a href=\"http://fiware.github.io/tutorials.Getting-Started/\">store finder example</a> and creates and associates a series of related data entities to create a simple stock management system.</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.Entity-Relationships/icon/GitHub-Mark-32px.png\" alt=\"GitHub\"> <a href=\"https://github.com/Fiware/tutorials.Entity-Relationships\">FIWARE 102: Batch Commands and Entity Relationships</a></p>\n<h1 id=\"data-entities\">Data Entities</h1>\n<p>Within the FIWARE platform, an entity represents the state of a physical or conceptural object which exists in the real world.</p>\n<h2 id=\"entities-within-a-stock-management-system\">Entities within a stock management system</h2>\n<p>For a simple stock management system, we will only need four types of entity. The relationship between our entities is defined as shown:</p>\n<p><img src=\"https://fiware.github.io/tutorials.Entity-Relationships/img/entities.png\" alt=\"\"></p>\n<ul>\n<li>A <strong>Store</strong> is a real world bricks and mortar building. Stores would have properties such as:<ul>\n<li>A name of the store e.g. \"Checkpoint Markt\"</li>\n<li>An address \"Friedrichstraße 44, 10969 Kreuzberg, Berlin\"</li>\n<li>A phyiscal location  e.g. <em>52.5075 N, 13.3903 E</em></li>\n</ul>\n</li>\n<li>A <strong>Shelf</strong> is a real world device to hold objects which we wish to sell. Each shelf would have properties such as:<ul>\n<li>A name of the shelf e.g. \"Wall Unit\"</li>\n<li>A phyiscal location  e.g. <em>52.5075 N, 13.3903 E</em></li>\n<li>A maximum capacity</li>\n<li>An association to the store in which the shelf is present</li>\n</ul>\n</li>\n<li>A <strong>Product</strong> is defined as something that we sell - it is conceptural object. Products would have properties such as:<ul>\n<li>A name of the product e.g. \"Vodka\"</li>\n<li>A price e.g. 13.99 Euros</li>\n<li>A size e.g. Small</li>\n</ul>\n</li>\n<li>An <strong>Inventory Item</strong> is another conceptural entity, used to assocate products, stores, shelves and physical objects. It would have properties such as:<ul>\n<li>An assocation to the product being sold</li>\n<li>An association to the store in which the product is being sold</li>\n<li>An association to the shelf where the product is being displayed</li>\n<li>A stock count of the quantity of the product available in the warehouse</li>\n<li>A stock count of the quantity of the product available on the shelf</li>\n</ul>\n</li>\n</ul>\n<p>As you can see, each of the entities defined above contain some properties which are liable to change. A product could change its price, stock could be sold and the shelf count of stock could be reduced and so on.</p>\n<h1 id=\"architecture\">Architecture</h1>\n<p>This application will only make use of one FIWARE component - the <a href=\"https://catalogue.fiware.org/enablers/publishsubscribe-context-broker-orion-context-broker\">Orion Context Broker</a>. Usage of the Orion Context Broker is sufficient for an application to qualify as <em>“Powered by FIWARE”</em>.</p>\n<p>Currently, the Orion Context Broker relies on open source <a href=\"https://www.mongodb.com/\">MongoDB</a> technology to keep persistence of the context data it holds. Therefore, the architecture will consist of two elements:</p>\n<ul>\n<li>The Orion Context Broker server which will receive requests using NGSI</li>\n<li>The underlying MongoDB database associated to the Orion Context Broker server</li>\n</ul>\n<p>Since all interactions between the two elements are initiated by HTTP requests, the entities can be containerized and run from exposed ports. </p>\n<p><img src=\"https://fiware.github.io/tutorials.Entity-Relationships/img/architecture.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:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-yaml\">  orion:\n    image: fiware/orion:latest\n    hostname: orion\n    container_name: orion\n    depends_on:\n      - context-db\n    networks:\n        - default\n    expose:\n        - \"1026\"\n    ports:\n        - \"1026:1026\"\n    command: -dbhost context-db -logLevel DEBUG\n</code></pre>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-yaml\">  context-db:\n    image: mongo:3.6\n    hostname: context-db\n    container_name: context-db\n    expose:\n        - \"27017\"\n    ports:\n        - \"27017:27017\"\n    networks:\n        - default\n    command: --bind_ip_all --smallfiles\n</code></pre>\n<p>Both containers are residing on the same network - the Orion Context Broker is listening on Port <code>1026</code> \nand MongoDB is listening on the default port <code>271071</code>. Both containers are also exposing the same ports\nexternally - this is purely for the tutorial access - so that cUrl or Postman can access them without\nbeing part of the same network. The command line initialization should be self explanatory.</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 technology 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 <a href=\"https://raw.githubusercontent.com/Fiware/tutorials.Entity-Relationships/master/docker-compose.yml\">YAML file</a> is used configure the required\nservices for the application. This means all container sevices can be brought up in a single commmand. Docker Compose is installed by default as part of Docker for Windows and  Docker for Mac, however Linux users will need to follow the instructions found <a href=\"https://docs.docker.com/compose/install/\">here</a></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=\"www.cygwin.com\">cygwin</a> to 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 initialised from the command line by running the bash script provided within the repository:</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code class=\"language-bash\">./services start\n</code></pre>\n</body></html>","schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json","toc":[{"content":"Data Entities","slug":"data-entities"},{"content":"Architecture","slug":"architecture"},{"content":"Prerequisites","slug":"prerequisites"},{"content":"Start Up","slug":"start-up"}],"owner":"513743","collectionId":"05e4b8a2-b7fd-4689-afd4-efb71cc2f17e","publishedId":"RVu8gSCh","public":true,"customColor":{"top-bar":"FFFFFF","right-sidebar":"4C4C4C","highlight":"233C68"},"publishDate":"2020-01-02T11:03:00.000Z"},"item":[{"name":"Re-create two Stores (optional)","id":"97eded23-bad2-4687-9288-8c26a84f5c24","request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n  \"actionType\": \"APPEND\",\n  \"entities\": [\n    {\n    \t\"type\": \"Store\",\n    \t\"id\": \"urn:ngsi-ld:Store:001\",\n    \t\"address\": {\n        \"type\": \"PostalAddress\",\n        \"value\": {\n            \"streetAddress\": \"Bornholmer Straße 65\",\n            \"addressRegion\": \"Berlin\",\n            \"addressLocality\": \"Prenzlauer Berg\",\n            \"postalCode\": \"10439\"\n\t        }\n\t    },\n\t    \"location\": {\n\t        \"type\": \"geo:json\",\n\t        \"value\": {\n\t           \"type\": \"Point\",\n\t           \"coordinates\": [13.3986, 52.5547]\n\t        }\n\t    },\n    \t\"name\": {\n        \t\"type\": \"Text\",\n        \t\"value\": \"Bösebrücke Einkauf\"\n    \t}\n    },\n    {\n    \t\"type\": \"Store\",\n        \"id\": \"urn:ngsi-ld:Store:002\",\n\t    \"address\": {\n\t        \"type\": \"PostalAddress\",\n\t        \"value\": {\n\t            \"streetAddress\": \"Friedrichstraße 44\",\n\t            \"addressRegion\": \"Berlin\",\n\t            \"addressLocality\": \"Kreuzberg\",\n\t            \"postalCode\": \"10969\"\n\t        }\n\t    },\n\t    \"location\": {\n\t        \"type\": \"geo:json\",\n\t        \"value\": {\n\t             \"type\": \"Point\",\n\t             \"coordinates\": [13.3903, 52.5075]\n\t        }\n\t    },\n\t    \"name\": {\n\t        \"type\": \"Text\",\n\t        \"value\": \"Checkpoint Markt\"\n\t    }\n    }\n  ]\n}"},"url":"http://localhost:1026/v2/op/update","description":"<p>This example uses the convenience batch processing endpoint to re-create the two <strong>Store</strong> entities from the previous tutorial.</p>\n<p>Batch processing uses the <code>/v2/op/update</code> endpoint with a payload with two attributes - <code>actionType=APPEND</code> means we will overwrite existing entities if they exist whereas the  <code>entities</code> attribute holds an array of entities we wish to update.</p>\n<p>As you can see each <strong>Store</strong> entity in the payload has been given a unique <code>id</code> (according to the NGSI-LD <a href=\"https://docbox.etsi.org/ISG/CIM/Open/ISG_CIM_NGSI-LD_API_Draft_for_public_review.pdf\">draft recommendation</a>) and assigned <code>type=Store</code>.</p>\n","urlObject":{"protocol":"http","path":["v2","op","update"],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"97eded23-bad2-4687-9288-8c26a84f5c24"},{"name":"Create Four Products","id":"6d6afb86-b234-4881-a45d-b594c95407f4","request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n  \"actionType\":\"APPEND\",\n  \"entities\":[\n    {\n      \"id\":\"urn:ngsi-ld:Product:001\", \"type\":\"Product\",\n      \"name\":{\n        \"type\":\"Text\", \"value\":\"Beer\"\n      },\n      \"size\":{\n        \"type\":\"Text\", \"value\": \"S\"\n      },\n      \"price\":{\n        \"type\":\"Integer\", \"value\": 99\n      }\n    },\n    {\n      \"id\":\"urn:ngsi-ld:Product:002\", \"type\":\"Product\",\n      \"name\":{\n        \"type\":\"Text\", \"value\":\"Red Wine\"\n      },\n      \"size\":{\n        \"type\":\"Text\", \"value\": \"M\"\n      },\n      \"price\":{\n        \"type\":\"Integer\", \"value\": 1099\n      }\n    },\n    {\n      \"id\":\"urn:ngsi-ld:Product:003\", \"type\":\"Product\",\n      \"name\":{\n        \"type\":\"Text\", \"value\":\"White Wine\"\n      },\n      \"size\":{\n        \"type\":\"Text\", \"value\": \"M\"\n      },\n      \"price\":{\n        \"type\":\"Integer\", \"value\": 1499\n      }\n    },\n    {\n      \"id\":\"urn:ngsi-ld:Product:004\", \"type\":\"Product\",\n      \"name\":{\n        \"type\":\"Text\", \"value\":\"Vodka\"\n      },\n      \"size\":{\n        \"type\":\"Text\", \"value\": \"XL\"\n      },\n      \"price\":{\n        \"type\":\"Integer\", \"value\": 5000\n      }\n    }\n  ]\n}"},"url":"http://localhost:1026/v2/op/update","description":"<p>This example uses the convenience batch processing endpoint to create a series of available products.</p>\n<p>Batch processing uses the <code>/v2/op/update</code> endpoint with a payload with two attributes - <code>actionType=APPEND</code> means we will overwrite existing entities if they exist whereas the <code>entities</code> attribute holds an array of entities we wish to update.</p>\n<p>Each product has a unique <code>id</code> following the NGSI-LD  <a href=\"https://docbox.etsi.org/ISG/CIM/Open/ISG_CIM_NGSI-LD_API_Draft_for_public_review.pdf\">draft recommendation</a>  and has been assigned <code>type=Product</code>.</p>\n","urlObject":{"protocol":"http","path":["v2","op","update"],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"6d6afb86-b234-4881-a45d-b594c95407f4"},{"name":"Create Five Shelf Units","id":"6f8a51e3-5ae2-4e85-8292-f4fd5d8877b0","request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n  \"actionType\":\"APPEND\",\n  \"entities\":[\n    {\n      \"id\":\"urn:ngsi-ld:Shelf:unit001\", \"type\":\"Shelf\",\n      \"location\":{\n        \"type\":\"geo:json\", \"value\":{ \"type\":\"Point\",\"coordinates\":[13.3986112, 52.554699]}\n      },\n      \"name\":{\n        \"type\":\"Text\", \"value\":\"Corner Unit\"\n      },\n      \"maxCapacity\":{\n        \"type\":\"Integer\", \"value\":50\n      }\n    },\n    {\n      \"id\":\"urn:ngsi-ld:Shelf:unit002\", \"type\":\"Shelf\",\n      \"location\":{\n        \"type\":\"geo:json\",\"value\":{\"type\":\"Point\",\"coordinates\":[13.3987221, 52.5546640]}\n      },\n      \"name\":{\n        \"type\":\"Text\", \"value\":\"Wall Unit 1\"\n      },\n      \"maxCapacity\":{\n        \"type\":\"Integer\", \"value\":100\n      }\n    },\n    {\n      \"id\":\"urn:ngsi-ld:Shelf:unit003\", \"type\":\"Shelf\",\n      \"location\":{\n        \"type\":\"geo:json\", \"value\":{\"type\":\"Point\",\"coordinates\":[13.3987221, 52.5546640]}\n      },\n      \"name\":{\n        \"type\":\"Text\", \"value\":\"Wall Unit 2\"\n      },\n      \"maxCapacity\":{\n        \"type\":\"Integer\", \"value\":100\n      }\n    },\n    {\n      \"id\":\"urn:ngsi-ld:Shelf:unit004\", \"type\":\"Shelf\",\n      \"location\":{\n        \"type\":\"geo:json\", \"value\":{\"type\":\"Point\",\"coordinates\":[13.390311, 52.507522]}\n      },\n      \"name\":{\n        \"type\":\"Text\", \"value\":\"Corner Unit\"\n      },\n      \"maxCapacity\":{\n        \"type\":\"Integer\", \"value\":50\n      }\n    },\n    {\n      \"id\":\"urn:ngsi-ld:Shelf:unit005\", \"type\":\"Shelf\",\n      \"location\":{\n        \"type\":\"geo:json\",\"value\":{\"type\":\"Point\",\"coordinates\":[13.390309, 52.50751]}\n      },\n      \"name\":{\n        \"type\":\"Text\", \"value\":\"Long Wall Unit\"\n      },\n      \"maxCapacity\":{\n        \"type\":\"Integer\", \"value\":200\n      }\n    }\n  ]\n}"},"url":"http://localhost:1026/v2/op/update","description":"<p>This example uses the convenience batch processing endpoint to create the five shelf entities.</p>\n<p>Batch processing uses the <code>/v2/op/update</code> endpoint with a payload with two attributes - <code>actionType=APPEND</code> means we will overwrite existing entities if they exist whereas the  <code>entities</code> attribute holds an array of entities we wish to update.</p>\n<p>To differenciate <strong>Shelf</strong> Entities from <strong>Store</strong> Entities, each shelf has been assigned <code>type=Shelf</code>. The <code>id</code> of each <strong>Shelf</strong> Entity follows the NGSI-LD  <a href=\"https://docbox.etsi.org/ISG/CIM/Open/ISG_CIM_NGSI-LD_API_Draft_for_public_review.pdf\">draft recommendation</a> and is therefore unique.</p>\n<p>Real-world properties such as <code>name</code> and <code>location</code> have been addded as properties to each shelf.</p>\n","urlObject":{"protocol":"http","path":["v2","op","update"],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"6f8a51e3-5ae2-4e85-8292-f4fd5d8877b0"},{"name":"Obtain Shelf Information","id":"68ea01ec-7f2d-43e3-81c8-2e14f65cc36a","request":{"method":"GET","header":[],"body":{"mode":"raw","raw":""},"url":"http://localhost:1026/v2/entities/urn:ngsi-ld:Shelf:unit001/?options=keyValues","description":"<p>This example returns the context data of the <em>Shelf</em> entity with the <code>id=urn:ngsi-ld:Shelf:unit001</code>.</p>\n<p>There are currently three additional property attributes present <code>location</code>, <code>maxCapacity</code> and <code>name</code></p>\n","urlObject":{"protocol":"http","path":["v2","entities","urn:ngsi-ld:Shelf:unit001",""],"host":["localhost:1026"],"query":[{"disabled":true,"description":{"content":"<p>Entity type</p>\n","type":"text/plain"},"key":"type","value":"Shelf"},{"description":{"content":"<ul>\n<li><code>keyValues</code> option in order to get a more compact and brief representation, including just attribute values</li>\n<li><code>values</code> option combined with a list of attribute values  <code>attrs</code>  for an ordered list of attributes only</li>\n</ul>\n","type":"text/plain"},"key":"options","value":"keyValues"}],"variable":[]}},"response":[],"_postman_id":"68ea01ec-7f2d-43e3-81c8-2e14f65cc36a"},{"name":"Adding a Foreign Key Relationship","id":"d65c3b44-38b6-40ae-9b25-0fd208785b7e","request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n  \"actionType\":\"APPEND\",\n  \"entities\":[\n    {\n      \"id\":\"urn:ngsi-ld:Shelf:unit001\", \"type\":\"Shelf\",\n      \"refStore\": { \n        \"type\": \"Relationship\",\n        \"value\": \"urn:ngsi-ld:Store:001\"\n      }\n    },\n    {\n      \"id\":\"urn:ngsi-ld:Shelf:unit002\", \"type\":\"Shelf\",\n      \"refStore\": { \n        \"type\": \"Relationship\",\n        \"value\": \"urn:ngsi-ld:Store:001\"\n      }\n    },\n    {\n      \"id\":\"urn:ngsi-ld:Shelf:unit003\", \"type\":\"Shelf\",\n      \"refStore\": { \n        \"type\": \"Relationship\",\n        \"value\": \"urn:ngsi-ld:Store:001\"\n      }\n    },\n    {\n      \"id\":\"urn:ngsi-ld:Shelf:unit004\", \"type\":\"Shelf\",\n      \"refStore\": { \n        \"type\": \"Relationship\",\n        \"value\": \"urn:ngsi-ld:Store:002\"\n      }\n    },\n    {\n      \"id\":\"urn:ngsi-ld:Shelf:unit005\", \"type\":\"Shelf\",\n      \"refStore\": { \n        \"type\": \"Relationship\",\n        \"value\": \"urn:ngsi-ld:Store:002\"\n      }\n    }\n  ]\n}"},"url":"http://localhost:1026/v2/op/update","description":"<p>This example uses batch processing to amend the existing the <strong>Shelf</strong> entities to add a <code>refStore</code> relationship to each shelf. According to the FIWARE Data Modelling Guidelines on <a href=\"http://fiware-datamodels.readthedocs.io/en/latest/guidelines/index.html#modelling-linked-data\">linked data</a>, when an entity attribute is used as a link to other entities  it should be named with the prefix <code>ref</code> plus the name of the target (linked) entity type. </p>\n<p>Batch processing uses the <code>/v2/op/update</code> endpoint with a payload with two attributes - <code>actionType=APPEND</code> means we will overwrite existing entities if they exist whereas the  <code>entities</code> attribute holds an array of entities we wish to update.</p>\n<p>The value corresponds to a URN associated to an existing <strong>Store</strong> entity within the context.</p>\n","urlObject":{"protocol":"http","path":["v2","op","update"],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"d65c3b44-38b6-40ae-9b25-0fd208785b7e"},{"name":"Obtain Updated Shelf Information","id":"4010848f-f739-4d07-8870-700ce2641477","request":{"method":"GET","header":[],"body":{"mode":"raw","raw":""},"url":"http://localhost:1026/v2/entities/urn:ngsi-ld:Shelf:unit001/?options=keyValues","description":"<p>This example returns the context data of the <code>Shelf</code> entity with the <code>id=urn:ngsi-ld:Shelf:unit001</code>.</p>\n<p>The response now includes a new relationship property <code>refStore</code>, which has been added in the previous step.</p>\n","urlObject":{"protocol":"http","path":["v2","entities","urn:ngsi-ld:Shelf:unit001",""],"host":["localhost:1026"],"query":[{"disabled":true,"description":{"content":"<p>Entity type</p>\n","type":"text/plain"},"key":"type","value":"Shelf"},{"description":{"content":"<ul>\n<li><code>keyValues</code> option in order to get a more compact and brief representation, including just attribute values</li>\n<li><code>values</code> option combined with a list of attribute values  <code>attrs</code>  for an ordered list of attributes only</li>\n</ul>\n","type":"text/plain"},"key":"options","value":"keyValues"}],"variable":[]}},"response":[],"_postman_id":"4010848f-f739-4d07-8870-700ce2641477"},{"name":"Obtain a Foreign Key URN","id":"e808d05c-9e42-4429-b8da-bc1c35e230c5","request":{"method":"GET","header":[],"body":{"mode":"raw","raw":""},"url":"http://localhost:1026/v2/entities/urn:ngsi-ld:Shelf:unit001/?options=values&attrs=refStore","description":"<p>This example returns the <code>refStore</code> value associated with a given <code>Shelf</code> unit. </p>\n<p>If the <code>id</code> and <code>type</code> of a data entity are known, a specific field can be requested by combining the <code>options=values</code> parameter and the <code>attrs</code> parameter. </p>\n<p>The URN returned has a standard format: <code>urn:ngsi-ld:&lt;entity-type&gt;:&lt;entity-id&gt;</code>, which has been used as the <code>id</code> of the <strong>Store</strong> entity itself (based on the NGSI-LD <a href=\"https://docbox.etsi.org/ISG/CIM/Open/ISG_CIM_NGSI-LD_API_Draft_for_public_review.pdf\">draft recommendation</a>), therefore it is a simple matter to request more information about the linked store by making a query to the <code>/entities</code> endpoint.</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code>http://localhost:1026/v2/entities/urn:ngsi-ld:Store:001?options=keyValues\n</code></pre>","urlObject":{"protocol":"http","path":["v2","entities","urn:ngsi-ld:Shelf:unit001",""],"host":["localhost:1026"],"query":[{"disabled":true,"description":{"content":"<p>Entity type</p>\n","type":"text/plain"},"key":"type","value":"Shelf"},{"description":{"content":"<ul>\n<li><code>keyValues</code> option in order to get a more compact and brief representation, including just attribute values</li>\n<li><code>values</code> option combined with a list of attribute values  <code>attrs</code>  for an ordered list of attributes only</li>\n</ul>\n","type":"text/plain"},"key":"options","value":"values"},{"description":{"content":"<p>Ordered list of attribute names to display</p>\n","type":"text/plain"},"key":"attrs","value":"refStore"}],"variable":[]}},"response":[],"_postman_id":"e808d05c-9e42-4429-b8da-bc1c35e230c5"},{"name":"Obtain all Shelf Units found within a Store","id":"4495d116-6f78-4b7d-bb5d-3e34059e16c8","request":{"method":"GET","header":[],"body":{"mode":"raw","raw":""},"url":"http://localhost:1026/v2/entities/?q=refStore==urn:ngsi-ld:Store:001&type=Shelf&options=values&attrs=name","description":"<p>This example returns the <code>name</code> of all <code>Shelf</code> entities associated with the <code>shop1</code>.</p>\n<p>The value of the query parameter <code>q</code> holds a URN of the form <code>urn:ngsi-ld:&lt;entity-type&gt;:&lt;entity-id&gt;</code> which corresponds to the the Relationship URN in order to filter the information returned.</p>\n","urlObject":{"protocol":"http","path":["v2","entities",""],"host":["localhost:1026"],"query":[{"key":"q","value":"refStore==urn:ngsi-ld:Store:001"},{"description":{"content":"<p>Entity type</p>\n","type":"text/plain"},"key":"type","value":"Shelf"},{"description":{"content":"<ul>\n<li><code>keyValues</code> option in order to get a more compact and brief representation, including just attribute values</li>\n<li><code>values</code> option combined with a list of attribute values  <code>attrs</code>  for an ordered list of attributes only</li>\n</ul>\n","type":"text/plain"},"key":"options","value":"values"},{"description":{"content":"<p>Ordered list of attribute names to display</p>\n","type":"text/plain"},"key":"attrs","value":"name"}],"variable":[]}},"response":[],"_postman_id":"4495d116-6f78-4b7d-bb5d-3e34059e16c8"},{"name":"Putting a Product onto  a shelf","id":"a0246746-38d8-4794-91e0-9a9d7a7acf34","request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n    \"id\": \"urn:ngsi-ld:InventoryItem:001\", \"type\": \"InventoryItem\",\n    \"refStore\": { \n        \"type\": \"Relationship\",\n        \"value\": \"urn:ngsi-ld:Store:001\"\n    },\n    \"refShelf\": { \n        \"type\": \"Relationship\",\n        \"value\": \"urn:ngsi-ld:Shelf:unit001\"\n    },\n    \"refProduct\": { \n        \"type\": \"Relationship\",\n        \"value\": \"urn:ngsi-ld:Product:001\"\n    },\n    \"stockCount\":{\n        \"type\":\"Integer\", \"value\": 10000\n    },\n    \"shelfCount\":{\n        \"type\":\"Integer\", \"value\": 50\n    }\n}"},"url":"http://localhost:1026/v2/entities/","description":"<p>The <strong>InventoryItem</strong> entity exists to associate data from other entities.  It has a foreign key relationship to the <strong>Store</strong>, <strong>Shelf</strong> and <strong>Product</strong> entities and therefore requires relationship attributes called <code>refStore</code>, <code>refShelf</code> and <code>refProduct</code>.</p>\n<p>Assigning a product to a shelf is simply a  create an entity holding the relationship information and any other additional properties (such as <code>stockCount</code> and <code>shelfCount</code>).</p>\n","urlObject":{"protocol":"http","path":["v2","entities",""],"host":["localhost:1026"],"query":[],"variable":[]}},"response":[],"_postman_id":"a0246746-38d8-4794-91e0-9a9d7a7acf34"},{"name":"Find all stores in which a product is sold","id":"c6995610-613a-4ec7-a39d-13fc922d7b6e","request":{"method":"GET","header":[],"body":{"mode":"raw","raw":""},"url":"http://localhost:1026/v2/entities/?q=refProduct==urn:ngsi-ld:Product:001&options=values&attrs=refStore&type=InventoryItem","description":"<p>This example returns the URN of all stores in which the product <code>id=urn:ngsi-ld:Product:001</code> is sold. The URN returned has a standard format: <code>urn:ngsi-ld:&lt;entity-type&gt;:&lt;entity-id&gt;</code>.</p>\n<p>Because we have based the <code>id</code> of the <strong>Store</strong> entity on the NGSI-LD <a href=\"https://docbox.etsi.org/ISG/CIM/Open/ISG_CIM_NGSI-LD_API_Draft_for_public_review.pdf\">draft recommendation</a>), therefore it is a simple matter to request more information about the linked store by making a query to the <code>/entities</code> endpoint.</p>\n<pre class=\"click-to-expand-wrapper is-snippet-wrapper\"><code>http://localhost:1026/v2/entities/urn:ngsi-ld:Store:001?options=keyValues\n</code></pre><p>Since there is no direct relationship between product and store, a query must be made to find all entities which have both <code>refProduct</code> and <code>refStore</code> attributes.</p>\n<p>In  our current context the <code>type</code> parameter is optional since only one type of entity contains the fields requested in the request</p>\n","urlObject":{"protocol":"http","path":["v2","entities",""],"host":["localhost:1026"],"query":[{"key":"q","value":"refProduct==urn:ngsi-ld:Product:001"},{"description":{"content":"<ul>\n<li><code>keyValues</code> option in order to get a more compact and brief representation, including just attribute values</li>\n<li><code>values</code> option combined with a list of attribute values  <code>attrs</code>  for an ordered list of attributes only</li>\n</ul>\n","type":"text/plain"},"key":"options","value":"values"},{"description":{"content":"<p>Ordered list of attribute names to display</p>\n","type":"text/plain"},"key":"attrs","value":"refStore"},{"description":{"content":"<p>Entity type</p>\n","type":"text/plain"},"key":"type","value":"InventoryItem"}],"variable":[]}},"response":[],"_postman_id":"c6995610-613a-4ec7-a39d-13fc922d7b6e"},{"name":"Find all Entities related to a Store","id":"8395a892-e980-44d0-8848-d2245cdf8c1c","request":{"method":"GET","header":[],"body":{"mode":"raw","raw":"{\n  \"actionType\": \"APPEND\",\n  \"entities\": [\n    {\n    \"id\": \"7770\",\n    \"type\": \"Shelf\",\n    \"store\": { \n      \"type\": \"Relationship\",\n      \"value\": \"urn:ngsi-ld:Store:store1\"\n    },\n    \"location\": {\n        \"type\": \"geo:json\",\n        \"value\": {\n           \"type\": \"Point\",\n           \"coordinates\": [13.3986112, 52.554699]\n        }\n    },\n    \"name\": {\n        \"type\": \"Text\",\n        \"value\": \"Corner Unit\"\n    },\n    \"maxCapacity\": {\n        \"type\": \"Integer\",\n        \"value\": 50\n    }\n},\n\n {\n      \"id\": \"7771\",\n      \"type\": \"Shelf\",\n      \"store\": {\n        \"type\": \"Relationship\",\n        \"value\": \"urn:ngsi-ld:Store:store1\"\n      },\n      \"location\": {\n        \"type\": \"geo:json\",\n        \"value\": {\n          \"type\": \"Point\",\n          \"coordinates\": [\n            13.3987221,\n            52.5546640\n          ]\n        }\n      },\n      \"name\": {\n        \"type\": \"Text\",\n        \"value\": \"Wall Unit 1\"\n      },\n      \"maxCapacity\": {\n        \"type\": \"Integer\",\n        \"value\": 100\n      }\n    },\n    \n    {\n      \"id\": \"7772\",\n      \"type\": \"Shelf\",\n      \"store\": {\n        \"type\": \"Relationship\",\n        \"value\": \"urn:ngsi-ld:Store:store1\"\n      },\n      \"location\": {\n        \"type\": \"geo:json\",\n        \"value\": {\n          \"type\": \"Point\",\n          \"coordinates\": [\n            13.3987221,\n            52.5546640\n          ]\n        }\n      },\n      \"name\": {\n        \"type\": \"Text\",\n        \"value\": \"Wall Unit 2\"\n      },\n      \"maxCapacity\": {\n        \"type\": \"Integer\",\n        \"value\": 100\n      }\n    }\n    \n    \n\n\n\n\n  ]\n}"},"url":"http://localhost:1026/v2/entities/?q=refStore==urn:ngsi-ld:Store:001&options=count&attrs=type","description":"<p>This example returns the key of all entities directly associated with the <code>urn:ngsi-ld:Store:001</code>.</p>\n<p>The response lists a series of Shelf and InventoryItem entities - there are no products since there is no direct relationship between product and store.</p>\n<p>If this request returns an empty array, the entity has no associates.</p>\n","urlObject":{"protocol":"http","path":["v2","entities",""],"host":["localhost:1026"],"query":[{"key":"q","value":"refStore==urn:ngsi-ld:Store:001"},{"description":{"content":"<ul>\n<li><code>keyValues</code> option in order to get a more compact and brief representation, including just attribute values</li>\n<li><code>values</code> option combined with a list of attribute values  <code>attrs</code>  for an ordered list of attributes only</li>\n</ul>\n","type":"text/plain"},"key":"options","value":"count"},{"description":{"content":"<p>Ordered list of attribute names to display</p>\n","type":"text/plain"},"key":"attrs","value":"type"}],"variable":[]}},"response":[],"_postman_id":"8395a892-e980-44d0-8848-d2245cdf8c1c"}],"event":[{"listen":"prerequest","script":{"id":"f1d42f27-1cae-4144-b06e-237fad09b51b","type":"text/javascript","exec":[""]}},{"listen":"test","script":{"id":"028325fa-d62b-4d7a-afbf-5b138040015a","type":"text/javascript","exec":[""]}}],"variable":[{"id":"73b7c194-97af-4388-81ee-6dce0839c507","key":"orion","value":"localhost:1026","type":"string"}]}