PubNub keys and the PubNub object

A PubNub API key set includes a publish key, a subscribe key, and a secret key. You can create key sets in the PubNub Admin Dashboard and are free to create as many key sets as you need.

When creating keys in your PubNub Admin Dashboard, be sure to consider all deployment environments for your application; think of your keys as you might think of your database instances.

For example, you likely have a database instance for each of your deployment environments: dev, test, prod, staging, etc. And you probably have a config file that your app reads in the initialization phase that contains the database connection parameters for each environment. You can do this with your keys as well; for example, in your PubNub Admin Dashboard you might have a couple of apps, each with three sets of keys, like this:

  • Taxi Dispatcher
    • Development
    • Test
    • Production
  • Stock Trader
    • Development
    • Test
    • Production

Every PubNub operation requires that you first initialize the PubNub object. To do this, you need a subscribe key and optionally a publish and secret key. You only need to provide the publish key when you initialize PubNub if there is a need to publish messages. But, even if a client is only publishing messages, it still requires the subscribe key, too. The secret key is only required for performing grants when using the Access Manager feature and it should only be used within your secure server environment – never use it on a client-side application.

For further learning, please see:

  • API Keys section of the knowledge base

    Try PubNub Today

    Try Our APIs
    • 1M Transactions
    • 1GB Data Persistence
    • All major Features