# API

For an easier usage of the application from other applications in the project, an API is provided.

Broadcast a message to multiple Users.

For an easier cleanup, all these messages are directly marked as archived and deleted on the sender side.

Arguments: (sender, recipients, subject, body='', skip_notification=False)

## pm_write()

Write a message to a User.

Contrary to pm_broadcast(), the message is archived and/or deleted on the sender side only if requested.

Arguments: (sender, recipient, subject, body='', skip_notification=False, auto_archive=False, auto_delete=False)

## Arguments

• auto_archive: to mark the message as archived on the sender side
• auto_delete: to mark the message as deleted on the sender side
• body: the contents of the message
• recipient: a User instance
• recipients: a list or tuple of User instances, or a single User instance
• sender: a User instance
• subject: the subject of the message

## Example

Suppose an application managing Event objects. Whenever a new Event is generated, you want to broadcast an announcement to Users who have subscribed to be informed of the availability of such a kind of Event.

Code sample:

from postman.api import pm_broadcast
events = Event.objects.filter(...)
for e in events: