> For the complete documentation index, see [llms.txt](https://ksdaemon.gitbook.io/wampy.js/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ksdaemon.gitbook.io/wampy.js/api/publish.md).

# publish()

### publish(topicURI\[, payload\[, advancedOptions]])

Publish a new event to topic.

Parameters:

* **topicURI**. Required. A string that identifies the topic. Must meet a WAMP Spec URI requirements.
* **payload**. Publishing event data. Optional. Maybe any single value or array or hash-table object or null:
  * If it is an array - it is sent as is as WAMP positional arguments attribute
  * If it is a single object (without **argsList** and **argsDict** keys) - it is sent AS IS as WAMP key-value arguments attribute
  * If it is a single Number/String/Boolean/Null value - it is packed into a one-item array and is sent as WAMP positional arguments attribute. Be aware: the receiver will get it in **argsList** as a one-item array and not as a single value!
  * It is possible to pass the array and object-like data simultaneously. In this case, pass a hash-table with the next attributes:
    * **argsList**: array payload (may be omitted)
    * **argsDict**: object payload (may be omitted)
* **advancedOptions**. Optional parameters hash table. Must include any or all of the options:
  * **exclude**: integer|array WAMP session id(s) that won't receive a published event, even though they may be subscribed
  * **exclude\_authid**: string|array Authentication id(s) that won't receive a published event, even though they may be subscribed
  * **exclude\_authrole**: string|array Authentication role(s) that won't receive a published event, even though they may be subscribed
  * **eligible**: integer|array WAMP session id(s) that are allowed to receive a published event
  * **eligible\_authid**: string|array Authentication id(s) that are allowed to receive a published event
  * **eligible\_authrole**: string|array Authentication role(s) that are allowed to receive a published event
  * **exclude\_me**: bool flag of receiving publishing event by initiator (if it is subscribed to this topic)
  * **disclose\_me**: bool flag of disclosure of publisher identity (its WAMP session ID) to receivers of a published event
  * **ppt\_scheme**: string Identifies the Payload Schema for Payload Passthru Mode
  * **ppt\_serializer**: string Specifies what serializer was used to encode the payload
  * **ppt\_cipher**: string Specifies the cryptographic algorithm that was used to encrypt the payload
  * **ppt\_keyid**: string Contains the encryption key id that was used to encrypt the payload

Returns `promise`:

* Resolved with one hash-table parameter with following attributes:
  * **topic**
  * **requestId**
  * **publicationId**
* Rejected with one of the [Errors instances](broken://pages/e80SGqRyzZXRlbWTYu1Y)

```javascript
await ws.publish('user.logged.in');
await ws.publish('chat.message.received', 'user message'); // will be sent as ['user message1']
await ws.publish('chat.message.received', ['user message1', 'user message2']);
await ws.publish('user.modified', { field1: 'field1', field2: true, field3: 123 });
await ws.publish('chat.message.received', ['Private message'], { eligible: 123456789 });

try {
    await ws.publish('user.modified', { field1: 'field1', field2: true, field3: 123 });
    console.log('User successfully modified');
} catch (e) {
    console.log('User modification failed', e.error, e.details);
}
```
