{"_id":"555f9bf914d68e0d0096658d","user":"555f9a010758330d000d531a","__v":16,"githubsync":"","category":{"_id":"555f9bf814d68e0d0096658b","pages":["555f9bf914d68e0d0096658d","55985a44ec869d0d0008c1a0"],"project":"555f9bf814d68e0d00966587","version":"555f9bf814d68e0d0096658a","__v":2,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-05-22T21:13:28.983Z","from_sync":false,"order":0,"slug":"documentation","title":"Documentation"},"parentDoc":null,"version":{"_id":"555f9bf814d68e0d0096658a","project":"555f9bf814d68e0d00966587","__v":9,"createdAt":"2015-05-22T21:13:28.470Z","releaseDate":"2015-05-22T21:13:28.470Z","categories":["555f9bf814d68e0d0096658b","555f9e9ed7777119003acfee","555fa040d7777119003acffd","555fa344d7777119003ad00b","555fa3e6d7777119003ad00f","555fb694336c041700a9b86e","555fb779336c041700a9b86f","555fb86bd7777119003ad039","555fbf1a336c041700a9b87f"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"project":"555f9bf814d68e0d00966587","metadata":{"title":"","description":"","image":[]},"updates":["5725adc5d10d5e0e00faa993"],"next":{"pages":[],"description":""},"createdAt":"2015-05-22T21:13:29.770Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"The Pushjet API is relativly simple once you realise that there are no user accounts. The entire API relies on persistant tokens. These tokens are also known as `uuid`, `service` and `secret`. They are used to identify the device/user, identify services and send notifications. \n\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"UUIDs\"\n}\n[/block]\nEvery device is identified by a persistant [UUID](https://en.wikipedia.org/wiki/UUID). This UUID is often generated using a function such as UUID4. UUIDs should not be shared between devices. The UUID is always passed to the API using the `uuid` parameter.\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"from uuid import uuid4\\n\\ndevice_id = str(uuid4())\",\n \"language\": \"python\"\n },\n {\n \"code\": \"<?php \\n// Taken from http://php.net/manual/en/function.uniqid.php#94959\\npublic static function UUID4() {\\n return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',\\n mt_rand(0, 0xffff), mt_rand(0, 0xffff),\\n mt_rand(0, 0xffff),\\n mt_rand(0, 0x0fff) | 0x4000,\\n mt_rand(0, 0x3fff) | 0x8000,\\n mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)\\n );\\n}\\n\\n$device_id = UUID4();\",\n \"language\": \"php\"\n },\n {\n \"code\": \"package main\\n\\nimport (\\n \\\"fmt\\\"\\n uuid4 \\\"github.com/wayn3h0/go-uuid\\\"\\n)\\n\\nfunc main() {\\n uuid, _ := uuid4.New()\\n \\n fmt.Println(uuid)\\n}\\n\",\n \"language\": \"go\"\n },\n {\n \"code\": \"// http://stackoverflow.com/a/105074\\nfunction uuid4() {\\n function s4() {\\n return Math.floor((1 + Math.random()) * 0x10000)\\n .toString(16)\\n .substring(1);\\n }\\n return s4() + s4() + '-' + s4() + '-' + s4() + '-' +\\n s4() + '-' + s4() + s4() + s4();\\n}\\n\\nvar device_id = uuid4();\",\n \"language\": \"javascript\"\n },\n {\n \"code\": \"package docs.pushjet.example.uuid;\\n \\nimport java.util.UUID;\\n \\npublic class RandomStringUUID {\\n public static void main(String[] args) {\\n \\t\\t// Alternativly http://stackoverflow.com/a/5626208\\n String deviceId = UUID.randomUUID().toString();\\n }\\n}\",\n \"language\": \"java\"\n },\n {\n \"code\": \"device_id=$(uuidgen -r)\",\n \"language\": \"shell\"\n }\n ]\n}\n[/block]\n\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"Services\"\n}\n[/block]\nServices all have a public and a private token. The api parameters for these tokens are `service` and `secret`. The public token can be requested [using the api](doc:obtaining-service-info) if the private token is availible. The private token is only given out upon [creating a new service](doc:creating-a-new-service).\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"Subscriptions\"\n}\n[/block]\nSubscribing to services is done by doing a [POST request to /subscriptions](doc:subscribe-to-service). The service's public key is used to subscribe to a service. This allows the device to receive notifications. \n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"Messages\"\n}\n[/block]\nMessages can be sent using the service's private key and will be delivered to every device that is subscribed to that service. Once a message has been received it will automatically be marked as read. If every device subscribed to a service has received the message then it will be deleted from the server. Messages can not be received twice. \n\nEvery message has importance known as `level`. This variable is used in devices to decide if the device should make a noise, vibrate, override silent mode etc. The default for this is 3.\n\nMessages also have a link, this link is used to optionally redirect the reader to a target URI opon clicking the notification. The default for this variable is `\"\"`.\n[block:api-header]\n{\n \"type\": \"basic\",\n \"title\": \"Don't force users to create services\"\n}\n[/block]\nThe Pushjet API is built with the idea that users should not have the burden of creating services themselves. The application can automatically [create a new service](doc:creating-a-new-service) and display the public token with a qr code. This enhances the user's experience by reducing the number of steps required to start receiving notifications.\n\nOf course users should always have the option to enter a secret token manually if preferred or copy the secret token by the server. This is no requirement for using Pushjet though.","excerpt":"","slug":"getting-started","type":"basic","title":"Getting Started with Pushjet"}