5

PubNub Functions REST APIs using CURL Commands

 2 years ago
source link: https://gist.github.com/stephenlb/5acf10d2691fbb26a50a5f51e8547967
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

PubNub Functions REST APIs using CURL Commands

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 in your apps and keys lookup.

Login

curl --data '{"email":"<email>","password":"<password>"}'       \
    -H 'Content-Type: application/json'                         \
    https://admin.pubnub.com/api/me

List Apps and Keys

curl https://admin.pubnub.com/api/apps?owner_id=<user_id>  \
    -H 'X-Session-Token: <session_token>'

List Keys by App ID optional

curl https://admin.pubnub.com/api/keys?app_id=<app_id>     \
    -H 'X-Session-Token: <session_token>'

Functions

curl https://admin.pubnub.com/api/v1/blocks/key/<key_id>/block  \
    -H 'X-Session-Token: <session_token>'

Event Handlers

curl https://admin.pubnub.com/api/v1/blocks/key/<key_id>/block/<block_id>  \
    -H 'X-Session-Token: <session_token>'

Update Event Handlers

EH_FILE="event-handler.js"
EVENT_HANDLER=`cat $EH_FILE | sed "s/'/\\\'/g" | sed 's/"/\\\"/g' | sed 's/[\r\n]/\\n/g'`
curl --data '{"key_id":<key_id>,"block_id":<block_id>,"id":<event_handler_id>,"channels":"<channel>","code":"$EVENT_HANDLER","event":"js-before-publish","log_level":"debug","name":"New Event Handler","output":"output-0.5823105682419438"}' \
    -X PUT                                                                                      \
    https://admin.pubnub.com/api/v1/blocks/key/<key_id>/event_handler/<event_handler_id>  \
    -H 'X-Session-Token: <session_token>'

Start Event Handler

curl --data '{"block_id":<block_id>,"key_id":<key_id>,"action":"start"}'  \
    -H 'Content-Type: application/json'                                   \
    -H 'X-Session-Token: <session_token>'                                 \
    https://admin.pubnub.com/api/v1/blocks/key/<key_id>/block/<block_id>/start

Stop Event Handler

curl --data '{"block_id":<block_id>,"key_id":<key_id>,"action":"stop"}'  \
    -H 'Content-Type: application/json'                                  \
    -H 'X-Session-Token: <session_token>'                                \
    https://admin.pubnub.com/api/v1/blocks/key/<key_id>/block/<block_id>/stop

Create Event Handler

EH_FILE="event-handler.js"
EVENT_HANDLER=`cat $EH_FILE | sed "s/'/\\\'/g" | sed 's/"/\\\"/g' | sed 's/[\r\n]/\\n/g'`
curl --data '{"key_id":<key_id>,"block_id":<block_id>,"id":<event_handler_id>,"channels":"<channel>","code":"$EVENT_HANDLER","event":"js-before-publish","log_level":"debug","name":"New Event Handler","output":"output-0.5823105682419438"}' \ 
    -H 'Content-Type: application/json'                                                         \
    -H 'X-Session-Token: <session_token>'                                                       \
     https://admin.pubnub.com/api/v1/blocks/key/<key_id>/event_handler

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK