Feedback

HTTP API

Authentication / Account Management

Login STEP 1

Create Auth TokenPost/me

Authenticate with an email and password to receive a session_token. The Session Token will be a top level key called token. The Session Token token is used for all requests after authentication. You also receive a user_id which is used Step 2.

Example URI

Post https://admin.pubnub.com/api/me
Request
HideShow
Headers
Content-Type: application/json
Body
{
    "email": "blocksUser@pubnub.com",
    "password": "verySecretPassword"
}
Response  200
HideShow
Body
{
    result: {
        created: 1464063983,
        expires: 1467594357,
        modified: 1465002357,
        token: "394f7dbd-f713-4a02-b1ca-17a258f5c9cc",
        user_id: 123456,
    }
}
Example
HideShow
curl \
    -H "Content-Type: application/json" \
    -d '{
        "email": "blocksUser@pubnub.com",
        "password": "verySecretPassword"
    }' \
    -X POST \
    "https://admin.pubnub.com/api/me"

Login Step 2

Fetch Account IDGet/accounts?user_id=123456

This endpoint returns an array of accounts you are part of. Array item 0 is the account you are owning. That object has an ID field. You need to use this ID to in query apps and keys endpoint where owner_id = account.id

Example URI

Get https://admin.pubnub.com/api/accounts?user_id=123456
URI Parameters
HideShow
user_id
number (required) Example: 123456

use user_id received from Step 1.

Request
HideShow
Headers
Accept: application/json
X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc
Response  200
HideShow
Body
{
    "result": {
        "accounts": [{
            "created": 1355425945,
            "dates": {
                "company": { 
                    "created": 1489708540, 
                    "modified": null
                }
            },
            "id": 267180,
            "modified": null,
            "owner_id": 123456,
            "properties": { 
                "company": "home"
            },
            "protected": 0
        }],
        "permissions": {}
    }
}
Example
HideShow
curl \
    -H "Accept: application/json" \
    -H "X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc" \
    -X GET \
    "https://admin.pubnub.com/api/accounts?user_id=123456"

Listing Applications

Listing ApplicationsGet/apps?owner_id=267180

Example URI

Get https://admin.pubnub.com/api/apps?owner_id=267180
URI Parameters
HideShow
owner_id
number (required) Example: 267180

return Keys for this application.

Request
HideShow
Headers
X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc
Response  200
HideShow
Example
HideShow
curl \
    -H "X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc" \
    -X GET \
    "https://admin.pubnub.com/api/apps?owner_id=267180"

Block Operations

Show All

Listing Blocks GET/v1/blocks/key/178088/block

Example URI

GET https://admin.pubnub.com/api/v1/blocks/key/178088/block
URI Parameters
HideShow
keyId
number (required) Example: 178088

key id for which to fetch associated blocks

Request
HideShow
Headers
Content-Type: application/json
X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc
Response  200
Example
HideShow
curl \
    -H "Content-Type: application/json" \
    -H "X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc" \
    -X GET \
    "https://admin.pubnub.com/api/v1/blocks/key/178088/block"

Starting

StartingPOST/v1/blocks/key/178088/block/71/start

Example URI

POST https://admin.pubnub.com/api/v1/blocks/key/178088/block/71/start
URI Parameters
HideShow
keyId
number (required) Example: 178088

key which owns the block.

blockId
number (required) Example: 71

block id to start.

Request
HideShow
Headers
Content-Type: application/json
X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc
Response  200
Example
HideShow
curl \
    -H "Content-Type: application/json" \
    -H "X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc" \
    -X POST \
    "https://admin.pubnub.com/api/v1/blocks/key/178088/block/71/start"

Stopping

StoppingPOST/v1/blocks/key/178088/block/71/stop

Example URI

POST https://admin.pubnub.com/api/v1/blocks/key/178088/block/71/stop
URI Parameters
HideShow
keyId
number (required) Example: 178088

key which owns the block.

blockId
number (required) Example: 71

block id to stop.

Request
HideShow
Headers
Content-Type: application/json
X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc
Response  200
Example
HideShow
curl \
    -H "Content-Type: application/json" \
    -H "X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc" \
    -X POST \
    "https://admin.pubnub.com/api/v1/blocks/key/178088/block/71/stop"

Event Handlers

Show All

Listing Event HandlersGET/v1/blocks/key/178088/block/71

Example URI

GET https://admin.pubnub.com/api/v1/blocks/key/178088/block/71
URI Parameters
HideShow
keyId
number (required) Example: 178088

key which owns the block.

blockId
number (required)  Example: 71

block id to list event handlers for.

Request
HideShow
Headers
Content-Type: application/json
X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc
Response  200
Example
HideShow
curl \
    -H "Content-Type: application/json" \
    -H "X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc" \
    -X GET \
    "https://admin.pubnub.com/api/v1/blocks/key/178088/block/71"

Creating Event Handler

Create Event HandlerPOST/v1/blocks/key/178088/event_handler

Be sure to reformat the code before uploading using the following snippet:

EH_FILE="event-handler.js"
  EVENT_HANDLER='cat $EH_FILE | sed "s/'/\\\'/g" | sed 's/"/\\\"/g' | sed 's/[\r\n]/\\n/g''

Example URI

POST https://admin.pubnub.com/api/v1/blocks/key/178088/event_handler
URI Parameters
HideShow
keyId
number (required) Example: 178088

key which owns the event handler.

Request
HideShow
Headers
Content-Type: application/json
X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc
Body
{
    "type": "before-publish",
    "key_id": 178088,
    "block_id": 71,
    "channels": "eventHandlerChannel",
    "code": "console.log('hi')",
    "event": "js-before-publish",
    "log_level": "debug",
    "name": "eventHandlerName",
    "output": "output-0.5823105682419438"
}
Response  200
Example
HideShow
curl \
    -H "Content-Type: application/json" \
    -H "X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc" \
    -d '{"type": "before-publish", "key_id": 178088, "block_id": 71, "channels": "eventHandlerChannel", "code": "console.log(\u0027hi\u0027)", "event": "js-before-publish", "log_level": "debug", "name": "eventHandlerName", "output": "output- .5823105682419438"}' \
    -X POST \
    "https://admin.pubnub.com/api/v1/blocks/key/178088/event_handler"

Updating Event Handler

Updating Event HandlerPUT/v1/blocks/key/178088/event_handler/112

Be sure to reformat the code before uploading using the following snippet:

EH_FILE="event-handler.js"
  EVENT_HANDLER='cat $EH_FILE | sed "s/'/\\\'/g" | sed 's/"/\\\"/g' | sed 's/[\r\n]/\\n/g''

Example URI

PUT https://admin.pubnub.com/api/v1/blocks/key/178088/event_handler/112
URI Parameters
HideShow
keyId
number (required) Example: 178088

key which owns the event handler.

eventHandlerId
number (required) Example: 112

id of event handler to be updated

Request
HideShow
Headers
Content-Type: application/json
X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc
Body
{
    "type": "before-publish",
    "key_id": 178088,
    "block_id": 71,
    "event_handler_id": 112,
    "channels": "eventHandlerChannel",
    "code": "console.log('hi')",
    "event": "js-before-publish",
    "log_level": "debug",
    "name": "eventHandlerName",
    "output": "output-0.5823105682419438"
}
Response  200
Example
HideShow
curl \
    -H "Content-Type: application/json" \
    -H "X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc" \
    -d '{"type": "before-publish", "key_id": 178088, "block_id": 71, "event_handler_id": 112, "channels": "eventHandlerChannel", "code": "console.log(\u0027hi\u0027)", "event": "js-before-publish", "log_level": "debug", "name": "eventHandlerName", "output": "output- .5823105682419438"}' \
    -X PUT \
    "https://admin.pubnub.com/api/v1/blocks/key/178088/event_handler/112"

Block Creation

CREATE Block

Create BlockPOST/api/v1/blocks/key/<key_id>/block

URI Parameters
HideShow
keyId
number (required) Example: 178088

key which owns the event handler.

blockId
number (required) Example: 71

block id to list event handlers for.

Request
HideShow
Headers
Content-Type: application/json
X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc
Response  200
Body
{
"key_id": < key id>,
"name": "< name of the block>",
"description": "< description of the block>"
}
Example
HideShow
curl \
    -H "Content-Type: application/json" \
    -H "X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc" \
    -d '{"key_id": 178088,"name": "new block","description": "new block"}' 
    -X POST \
    "https://admin.pubnub.com/api/v1/blocks/key/178088/block"

UPDATE Block

UPDATE BlockPUT/api/v1/blocks/key/<key_id>/block/<block_id>

URI Parameters
HideShow
keyId
number (required) Example: 178088

key which owns the event handler.

blockId
number (required) Example: 71

block id to list event handlers for.

Request
HideShow
Headers
Content-Type: application/json
X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc
Response  200
Body
{
"key_id": < key id>,
"name": "< name of the block>",
"description": "< description of the block>"
}
Example
HideShow
curl \
    -H "Content-Type: application/json" \
    -H "X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc" \
    -d '{"key_id": 178088,"name": "new block","description": "new block"}' \
    -X PUT \
    "https://admin.pubnub.com/api/v1/blocks/key/178088/block/71"

DELETE Block

DELETE BlockDELETE/api/v1/blocks/key/<key-id>/block/<block-id>

URI Parameters
HideShow
keyId
number (required) Example: 178088

key which owns the event handler.

blockId
number (required) Example: 71

block id to list event handlers for.

Request
HideShow
Headers
Content-Type: application/json
X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc
Response  200
Example
HideShow
curl \
    -H "Content-Type: application/json" \
    -H "X-Session-Token: 394f7dbd-f713-4a02-b1ca-17a258f5c9cc" \
    -X DELETE \
    "https://admin.pubnub.com/api/v1/blocks/key/178088/block/71"