# PubSub

The PubSub APIs allow users to publish and retrieve messages from PubSub topics. Each message in the topic has an ID that is used as an offset. You must store either the message ID or last message timestamp in order to use this endpoint.

# Quick reference

Type Resource Description
POST /api/pubsub/topics/:topic_id/consume Consume messages from a topic.
POST /api/pubsub/topics/:topic_id/publish Publish a message to a topic.

# Consume messages

Retrieve messages from the topic.

POST /api/pubsub/topics/:topic_id/consume

# URL parameters

Name Type Description
topic_id integer
required
PubSub topic ID.

# Payload

Name Type Description
after_message_id string
optional
Message ID. The service returns all messages after the message with the specified ID. The ID must correspond to a message that exists in the topic.
since_time string
optional
Timestamp in RFC 3339 format. The service returns all messages after the timestamp specified.

# Sample request

curl  -X POST "https://www.workato.com/api/pubsub/topics/<id>/consume" \
      -H 'Authorization: Bearer <token>' \
      -H 'Content-Type: application/json' \
      --data '{"after_message_id": "A12x"}'

# Response

{
    "messages": [
        {
            "message_id": "A12y",
            "payload": {
                "Name": "Jane",
                "Surname": "Doe"
            },
            "time": "2023-04-14T15:07:14.437+00:00"
        },
        {
            "message_id": "A12z",
            "payload": {
                "Name": "John",
                "Surname": "Doe"
            },
            "time": "2023-04-14T15:43:40.227+00:00"
        }
    ]
}

# Publish message

Publish a message to a topic. The message must comply with the topic schema.

POST /api/pubsub/topics/:topic_id/publish

# URL parameters

Name Type Description
topic_id integer
required
PubSub topic ID.

# Payload

Name Type Description
JSON
required
Message to publish to the topic. The message must comply with the topic schema.

# Sample request

curl  -X POST "https://www.workato.com/api/pubsub/topics/<id>/publish" \
      -H 'Authorization: Bearer <token>' \
      --data '{"Name": "John", "Surname": "Doe"}'

# Response

{
    "message_id": "A1BRi"
}


Last updated: 4/20/2023, 8:45:02 PM