App Streams

App streams are long-lasting connections between the API and your server, often for notifications and other applications that need instant updates.

You will need an app token to use them. Look at How To: App Streams for details on usage.

Endpoints:

GET /streams

Token: app

Get all app streams for the authenticated app.

Example
curl "https://api.pnut.io/v0/streams" \
    -H "Authorization: Bearer ${ACCESS_TOKEN}" \
    -X GET \
    -H "X-Pretty-Json: 1"

Returns a list of streams.

{
    "meta": {
        "code": 200
    },
    "data": [
        {
            "key": "String",
            "object_types": [
                "String",
                "String",
                "String"
            ],
            "endpoint": "wss://stream.pnut.io/v0/app",
            "type": "long_poll"
        }
    ]
}

GET /streams/{stream_key}

Token: app

Get a specific app stream by its key.

URL Parameters

Name Description
stream_key Stream to retrieve
Example
curl "https://api.pnut.io/v0/streams/4" \
    -H "Authorization: Bearer ${ACCESS_TOKEN}" \
    -X GET \
    -H "X-Pretty-Json: 1"

Returns the requested stream.

{
    "meta": {
        "code": 200
    },
    "data": {
        "key": "String",
        "object_types": [
            "String",
            "String",
            "String"
        ],
        "endpoint": "wss://stream.pnut.io/v0/app",
        "type": "long_poll"
    }
}

POST /streams

Token: app

Create an app stream for the authenticated app. Can create up to five (5) app streams.

Must have a Content-Type of application/json.

Post Parameters

Field Type Description
type string The only value currently allowed is long_poll
object_types array List of object types to listen for. Valid values are post, bookmark, follow, mute, block, message, channel, channel_subscription, token, file, poll, and user.
key string Optional name for the stream, instead of an automatically assigned numeric key. Alphanumeric and underscore allowed, 32 characters, unique for this app.
Example
curl "https://api.pnut.io/v0/streams" \
    -H "Authorization: Bearer ${ACCESS_TOKEN}" \
    -H "Content-Type: application/json" \
    -d "{
    \"type\":\"long_poll\",
    \"object_types\":[
        \"post\",\"message\",\"channel_subscription\",\"bookmark\"
    ],
    \"key\":\"butterball\"
}" \
    -X POST \
    -H "X-Pretty-Json: 1"

Returns the created stream.

{
    "meta": {
        "code": 200
    },
    "data": {
        "key": "String",
        "object_types": [
            "String",
            "String",
            "String"
        ],
        "endpoint": "wss://stream.pnut.io/v0/app",
        "type": "long_poll"
    }
}

PUT /streams/{stream_key}

Token: app

Update an app stream. Note that, currently, any connected app streams will not be updated until the app disconnects and reconnects.

The only changeable field currently is object_types.

URL Parameters

Name Description
stream_key Stream to update
Example
curl "https://api.pnut.io/v0/streams/butterball" \
    -H "Authorization: Bearer ${ACCESS_TOKEN}" \
    -H "Content-Type: application/json" \
    -d "{
    \"object_types\":[
        \"post\",\"message\",\"bookmark\"
    ]
}" \
    -X POST \
    -H "X-Pretty-Json: 1"

Returns the updated stream.

{
    "meta": {
        "code": 200
    },
    "data": {
        "key": "String",
        "object_types": [
            "String"
        ],
        "endpoint": "wss://stream.pnut.io/v0/app",
        "type": "long_poll"
    }
}

DELETE /streams

Token: app

Delete all app streams for the authorized app.

Example
curl "https://api.pnut.io/v0/streams" \
    -H "Authorization: Bearer ${ACCESS_TOKEN}" \
    -X DELETE \
    -H "X-Pretty-Json: 1"

Returns a list of deleted streams.

{
    "meta": {
        "code": 200
    },
    "data": [
        {
            "key": "String",
            "object_types": [
                "String",
                "String"
            ],
            "endpoint": "wss://stream.pnut.io/v0/app",
            "type": "long_poll",
            "is_deleted": true
        }
    ]
}

DELETE /streams/{stream_key}

Token: app

Delete a specific app stream by its key.

URL Parameters

Name Description
stream_key Stream to delete
Example
curl "https://api.pnut.io/v0/streams/butterball" \
    -H "Authorization: Bearer ${ACCESS_TOKEN}" \
    -X DELETE \
    -H "X-Pretty-Json: 1"

Returns the deleted stream.

{
    "meta": {
        "code": 200
    },
    "data": {
        "key": "String",
        "object_types": [
            "String",
            "String",
            "String"
        ],
        "endpoint": "wss://stream.pnut.io/v0/app",
        "type": "long_poll",
        "is_deleted": true
    }
}