Skip to content

Working with Message Streams

Vlad-Cosmin Sandu edited this page May 28, 2020 · 1 revision

The PostmarkClient allows you to easily manage your Message Streams.

Get details about an existing message stream:

var fetchedStream = await _client.GetMessageStream("my-stream-id");

Console.WriteLine($"StreamID: {fetchedStream.ID}");
Console.WriteLine($"ServerID: {fetchedStream.ServerID}");
Console.WriteLine($"Stream Type: {fetchedStream.MessageStreamType}");
Console.WriteLine($"Stream Name: {fetchedStream.Name}");
Console.WriteLine($"Stream Description: {fetchedStream.Description}");

List existing message streams:

var messageStreamType = MessageStreamTypeFilter.Transactional; // Filter by stream type; Defaults to All.
var includeArchivedStreams = true;

var listing = await _client.ListMessageStreams(messageStreamType, includeArchivedStreams);

foreach (var stream in listing.MessageStreams)
{
    Console.WriteLine($"StreamID: {stream.ID}");
}

Create a new message stream:

var id = "new-stream-id";
var streamType = MessageStreamType.Broadcasts;
var streamName = "New Broadcasts Stream";
var description = "This is a test description."; // optional

var messageStream = await _client.CreateMessageStream(id, streamType, streamName, description);

Console.WriteLine($"StreamID: {messageStream.ID}");

Edit an existing message stream:

var id = "stream-id-to-update";
var newStreamName = "Updated Name"; // optional
var newDescription = "Updated Description"; // optional

var updatedStream = await _client.EditMessageStream(id, newStreamName, newDescription);

Console.WriteLine($"New Name: {updatedStream.Name}");
Console.WriteLine($"New Description: {updatedStream.Description}");

Archive a message stream:

var archivalConfirmation = await _client.ArchiveMessageStream("stream-to-archive");

Console.WriteLine($"StreamID: {archivalConfirmation.ID}");
Console.WriteLine($"ServerID: {archivalConfirmation.ServerID}");
Console.WriteLine($"Expected Purge Date: {archivalConfirmation.ExpectedPurgeDate}");

Archiving a message stream will disable sending/receiving messages via that stream. The stream will also stop being shown in the Postmark UI. Once a stream has been archived, it will be deleted (alongside associated data) at the ExpectedPurgeDate in the response.

UnArchive a message stream:

var unarchivedStream = await _client.UnArchiveMessageStream("archived-stream-id");

Console.WriteLine($"StreamID: {unarchivedStream.ID}");
Console.WriteLine($"ServerID: {unarchivedStream.ServerID}");

UnArchiving a message stream will resume sending/receiving messages via that stream. The stream will also re-appear in the Postmark UI. A stream can be unarchived only before the stream's ExpectedPurgeDate.

Clone this wiki locally