I'm trying to consume/publish Platform Events using aiosfstream python library. There is a publish() function but I always get an error response:

aiocometd.exceptions.ServerError: ('Publish request failed.', {'clientId': '3bq174in63lwkx7j1asoyin32nemt', 'channel': '/event/TestEvent__e', 'id': '4', 'successful': False})

Here is my code to publish an event. TestEvent__e has just one text field in it - message__c.

CHANNEL_PATH = "/event/TestEvent__e"
messageData = {"message__c": "Hello, THIS IS CLIENT SPEAKING!!"}
await client.publish(CHANNEL_PATH,message)

What can I change? What would be the correct message format to publish it to salesforce event bus?


1 Answer 1


I'm the author of aiosfstream. Thanks for notifying me about this question!


You can use aiosfstream to subscribe and listen for platform events, but you can't use it for publishing.

To publish platform events you have to use one of the documented methods. Since you're trying to publish events from a python application, publishing events with the REST or SOAP API is what probably best suits your needs.

Detailed explanation

Salesforce's Streaming API is implemented using a CometD server with Salesforce's custom replay extension and authentication. Similarly, aiosfstream is based on aiocometd, which is a CometD client.

With CometD you can listen for or stream incoming messages and you can also publish messages on certain channels. A good example to this is CometD's chat example. So the implementation of the publish method in aiosfstream comes from the aiocometd library. However, while publishing messages is a legal and useful operation in other CometD applications in the case of the Streaming API it is a legal but a totally useless operation, since Salesforce rejects messages published on any channel (as far as I know). So in practice, you can transfer messages to Salesforce, but they'll be ignored.

Thanks for reporting this issue, it made me realize how misleading the presence of the publish method is!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .