{"_id":"555f9bf914d68e0d0096658d","user":"555f9a010758330d000d531a","__v":16,"githubsync":"","isReference":false,"link_external":false,"order":0,"updates":["5725adc5d10d5e0e00faa993"],"category":"555f9bf814d68e0d0096658b","createdAt":"2015-05-22T21:13:29.770Z","link_url":"","parentDoc":null,"slug":"getting-started","api":{"auth":"required","params":[],"results":{"codes":[]},"settings":"","url":""},"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.","hidden":false,"sync_unique":"","version":"555f9bf814d68e0d0096658a","excerpt":"","project":"555f9bf814d68e0d00966587","title":"Getting Started with Pushjet","type":"basic","childrenPages":[]}