{"id":515,"date":"2020-11-23T17:41:20","date_gmt":"2020-11-23T17:41:20","guid":{"rendered":"https:\/\/cupl.co.uk\/?page_id=515"},"modified":"2020-12-16T10:40:40","modified_gmt":"2020-12-16T10:40:40","slug":"cuplbackend-consumer-api","status":"publish","type":"page","link":"https:\/\/cupl.co.uk\/index.php\/software\/cuplbackend\/cuplbackend-consumer-api\/","title":{"rendered":"Consumer API"},"content":{"rendered":"\n<p><a href=\"https:\/\/redocly.github.io\/redoc\/?url=https:\/\/raw.githubusercontent.com\/cuplsensor\/cuplbackend\/32882118c93e564f40fd17192fd6b1cdaf3e6014\/docs\/api\/consumer\/api.yaml\" data-type=\"URL\" data-id=\"https:\/\/redocly.github.io\/redoc\/?url=https:\/\/raw.githubusercontent.com\/cuplsensor\/cuplbackend\/32882118c93e564f40fd17192fd6b1cdaf3e6014\/docs\/api\/consumer\/api.yaml\">API Documentation<\/a><\/p>\n\n\n\n<p>This API is designed to be accessed by regular end-users. Tags can only be viewed (not deleted or created). Captures can be created, but only by scanning a tag with a recognised serial and secretkey. Samples from multiple captures can be retrieved and de-duplicated.<\/p>\n\n\n\n<h2>Capture Creation<\/h2>\n\n\n\n<p>The <a href=\"https:\/\/redocly.github.io\/redoc\/?url=https:\/\/raw.githubusercontent.com\/cuplsensor\/cuplbackend\/32882118c93e564f40fd17192fd6b1cdaf3e6014\/docs\/api\/consumer\/api.yaml#operation\/CapturesPost\" data-type=\"URL\" data-id=\"https:\/\/redocly.github.io\/redoc\/?url=https:\/\/raw.githubusercontent.com\/cuplsensor\/cuplbackend\/32882118c93e564f40fd17192fd6b1cdaf3e6014\/docs\/api\/consumer\/api.yaml#operation\/CapturesPost\">create capture<\/a> endpoint passes data extracted from a cuplURL to the <a href=\"https:\/\/cupl.co.uk\/index.php\/cuplcodec\/\" data-type=\"page\" data-id=\"171\">decoder<\/a>. Output is persisted in the database as a <strong>capture<\/strong>. Each is stored as a child of the tag that created the cuplURL. This list of captures constitutes a long-term record of the temperature and humidity measured by cuplTag. It extends datalogging capacity well beyond the on-board 1KB circular buffer. <\/p>\n\n\n\n<p>The decoder requires a secret key to validate the HMAC part of the cuplURL. Without this, no capture is created and an error message is raised &#8211; the cuplURL could have originated from anywhere. The secret key is a random 16-character string <a href=\"https:\/\/cupl.co.uk\/index.php\/cuplbackend-admin-api\/\" data-type=\"page\" data-id=\"512\">assigned<\/a> to each tag in production. It is looked up before the decoder is invoked. <\/p>\n\n\n\n<figure class=\"wp-block-image size-medium is-resized\"><img loading=\"lazy\" src=\"https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/tag_capture_graphic-271x300.png\" alt=\"\" class=\"wp-image-575\" width=\"136\" height=\"150\" srcset=\"https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/tag_capture_graphic-271x300.png 271w, https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/tag_capture_graphic.png 480w\" sizes=\"(max-width: 136px) 100vw, 136px\" \/><\/figure>\n\n\n\n<h2>Sample De-duplication<\/h2>\n\n\n\n<p>The cuplTag writes samples to a circular buffer at 10 minute intervals. It takes roughly one day for old samples to be overwritten. A subset of two captures taken within one day will be identical. <\/p>\n\n\n\n<p>The user will want to view all samples stitched together on a timeline, with no duplicates. This is much better than viewing one capture at-a-time. cuplBackend facilitates this with the <a href=\"https:\/\/redocly.github.io\/redoc\/?url=https:\/\/raw.githubusercontent.com\/cuplsensor\/cuplbackend\/32882118c93e564f40fd17192fd6b1cdaf3e6014\/docs\/api\/consumer\/api.yaml#operation\/UniqueSamplesGet\" data-type=\"URL\" data-id=\"https:\/\/redocly.github.io\/redoc\/?url=https:\/\/raw.githubusercontent.com\/cuplsensor\/cuplbackend\/32882118c93e564f40fd17192fd6b1cdaf3e6014\/docs\/api\/consumer\/api.yaml#operation\/UniqueSamplesGet\">unique samples<\/a> endpoint. It returns sample data between a start and end timestamp. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"997\" height=\"325\" src=\"https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/de-duplication-1.png\" alt=\"\" class=\"wp-image-590\" srcset=\"https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/de-duplication-1.png 997w, https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/de-duplication-1-600x196.png 600w, https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/de-duplication-1-300x98.png 300w, https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/de-duplication-1-768x250.png 768w\" sizes=\"(max-width: 997px) 100vw, 997px\" \/><\/figure>\n\n\n\n<h2>Physical Access Endpoints<\/h2>\n\n\n\n<p>When the <a href=\"https:\/\/redocly.github.io\/redoc\/?url=https:\/\/raw.githubusercontent.com\/cuplsensor\/cuplbackend\/32882118c93e564f40fd17192fd6b1cdaf3e6014\/docs\/api\/admin\/api.yaml#operation\/AdminCapturePost\" data-type=\"URL\" data-id=\"https:\/\/redocly.github.io\/redoc\/?url=https:\/\/raw.githubusercontent.com\/cuplsensor\/cuplbackend\/32882118c93e564f40fd17192fd6b1cdaf3e6014\/docs\/api\/admin\/api.yaml#operation\/AdminCapturePost\">create <\/a><a href=\"https:\/\/redocly.github.io\/redoc\/?url=https:\/\/raw.githubusercontent.com\/cuplsensor\/cuplbackend\/32882118c93e564f40fd17192fd6b1cdaf3e6014\/docs\/api\/consumer\/api.yaml#operation\/CapturesPost\" data-type=\"URL\" data-id=\"https:\/\/redocly.github.io\/redoc\/?url=https:\/\/raw.githubusercontent.com\/cuplsensor\/cuplbackend\/32882118c93e564f40fd17192fd6b1cdaf3e6014\/docs\/api\/consumer\/api.yaml#operation\/CapturesPost\">capture<\/a> endpoint is called a <strong>tagtoken <\/strong>is returned, which expires after 10 minutes. This<strong> <\/strong>can then be passed to POST, PUT and DELETE endpoints described below. The token proves the user has <strong>physical access<\/strong> to one tag and is therefore likely to own it. Therefore, some write privileges are granted.<\/p>\n\n\n\n<figure class=\"wp-block-image size-medium is-resized\"><img loading=\"lazy\" src=\"https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/tag_proximity_graphic-2-252x300.png\" alt=\"\" class=\"wp-image-580\" width=\"126\" height=\"150\" srcset=\"https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/tag_proximity_graphic-2-252x300.png 252w, https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/tag_proximity_graphic-2.png 452w\" sizes=\"(max-width: 126px) 100vw, 126px\" \/><\/figure>\n\n\n\n<h3>Description<\/h3>\n\n\n\n<p>Users can label cuplTags by making a PUT request to the <a href=\"https:\/\/redocly.github.io\/redoc\/?url=https:\/\/raw.githubusercontent.com\/cuplsensor\/cuplbackend\/32882118c93e564f40fd17192fd6b1cdaf3e6014\/docs\/api\/consumer\/api.yaml#operation\/TagDescriptionPut\" data-type=\"URL\" data-id=\"https:\/\/redocly.github.io\/redoc\/?url=https:\/\/raw.githubusercontent.com\/cuplsensor\/cuplbackend\/32882118c93e564f40fd17192fd6b1cdaf3e6014\/docs\/api\/consumer\/api.yaml#operation\/TagDescriptionPut\">tag description<\/a> endpoint. <\/p>\n\n\n\n<figure class=\"wp-block-image size-medium\"><img loading=\"lazy\" width=\"300\" height=\"222\" src=\"https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/tag_description_graphic-300x222.png\" alt=\"\" class=\"wp-image-598\" srcset=\"https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/tag_description_graphic-300x222.png 300w, https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/tag_description_graphic-600x445.png 600w, https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/tag_description_graphic.png 696w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/figure>\n\n\n\n<h3>Webhooks<\/h3>\n\n\n\n<p>When a capture is created by cuplBackend, it can be transmitted to a 3rd party application by means of a reverse API call (webhook). In other words: cuplbackend can POST new captures to a URL of your choice.<\/p>\n\n\n\n<p>Webhooks eliminate the need for 3rd party applications polling cuplBackend for new tag data. The URL is set from a frontend application. A tagtoken is required (see above).  <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"243\" src=\"https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/webhook_diagram-1-1024x243.png\" alt=\"\" class=\"wp-image-595\" srcset=\"https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/webhook_diagram-1-1024x243.png 1024w, https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/webhook_diagram-1-600x142.png 600w, https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/webhook_diagram-1-300x71.png 300w, https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/webhook_diagram-1-768x182.png 768w, https:\/\/cupl.co.uk\/wp-content\/uploads\/2020\/12\/webhook_diagram-1.png 1054w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2>Browse Tags, Captures and Samples<\/h2>\n\n\n\n<p>Without authentication, users are free to read non-sensitive data on tags, captures and samples. Rate limits are adjusted with environment variables.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>API Documentation This API is designed to be accessed by regular end-users. Tags can only be viewed (not deleted or created). Captures can be created, but only by scanning a tag with a recognised serial and secretkey. Samples from multiple captures can be retrieved and de-duplicated. Capture Creation The create capture endpoint passes data extracted&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":173,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"spay_email":""},"featured_image_urls":{"full":"","thumbnail":"","medium":"","medium_large":"","large":"","1536x1536":"","2048x2048":""},"post_excerpt_stackable":"<p>API Documentation This API is designed to be accessed by regular end-users. Tags can only be viewed (not deleted or created). Captures can be created, but only by scanning a tag with a recognised serial and secretkey. Samples from multiple captures can be retrieved and de-duplicated. Capture Creation The create capture endpoint passes data extracted from a cuplURL to the decoder. Output is persisted in the database as a capture. Each is stored as a child of the tag that created the cuplURL. This list of captures constitutes a long-term record of the temperature and humidity measured by cuplTag. It&hellip;<\/p>\n","category_list":"","author_info":{"name":"malcolmmackay","url":"https:\/\/cupl.co.uk\/index.php\/author\/malcolmmackay\/"},"comments_num":"0 comments","featured_image_urls_v2":{"full":"","thumbnail":"","medium":"","medium_large":"","large":"","1536x1536":"","2048x2048":""},"post_excerpt_stackable_v2":"<p>API Documentation This API is designed to be accessed by regular end-users. Tags can only be viewed (not deleted or created). Captures can be created, but only by scanning a tag with a recognised serial and secretkey. Samples from multiple captures can be retrieved and de-duplicated. Capture Creation The create capture endpoint passes data extracted from a cuplURL to the decoder. Output is persisted in the database as a capture. Each is stored as a child of the tag that created the cuplURL. This list of captures constitutes a long-term record of the temperature and humidity measured by cuplTag. It&hellip;<\/p>\n","category_list_v2":"","author_info_v2":{"name":"malcolmmackay","url":"https:\/\/cupl.co.uk\/index.php\/author\/malcolmmackay\/"},"comments_num_v2":"0 comments","_links":{"self":[{"href":"https:\/\/cupl.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/515"}],"collection":[{"href":"https:\/\/cupl.co.uk\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/cupl.co.uk\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/cupl.co.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cupl.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=515"}],"version-history":[{"count":37,"href":"https:\/\/cupl.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/515\/revisions"}],"predecessor-version":[{"id":709,"href":"https:\/\/cupl.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/515\/revisions\/709"}],"up":[{"embeddable":true,"href":"https:\/\/cupl.co.uk\/index.php\/wp-json\/wp\/v2\/pages\/173"}],"wp:attachment":[{"href":"https:\/\/cupl.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=515"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}