---
title: "POST /v1/{+topic}:publish"
method: POST
path: "/v1/{+topic}:publish"
tags: ["projects"]
---

# POST /v1/{+topic}:publish

`POST /v1/{+topic}:publish`

Adds one or more messages to the topic. Returns `NOT_FOUND` if the topic does not exist.

## Path parameters

- `topic` string, required

## Request body

- PublishRequest — Request for the Publish method.
  - `messages` PubsubMessage[] — Required. The messages to publish.
    - `attributes` object — Optional. Attributes for this message. If this field is empty, the message must contain non-empty data. This can be used to filter messages on the subscription.
    - `orderingKey` string — Optional. If non-empty, identifies related messages for which publish order should be respected. If a `Subscription` has `enable_message_ordering` set to `true`, messages published with the same non-empty `ordering_key` value will be delivered to subscribers in the order in which they are received by the Pub/Sub system. All `PubsubMessage`s published in a given `PublishRequest` must specify the same `ordering_key` value. For more information, see [ordering messages](https://cloud.google.com/pubsub/docs/ordering).
    - `data` string, byte — Optional. The message data field. If this field is empty, the message must contain at least one attribute.
    - `messageId` string — ID of this message, assigned by the server when the message is published. Guaranteed to be unique within the topic. This value may be read by a subscriber that receives a `PubsubMessage` via a `Pull` call or a push delivery. It must not be populated by the publisher in a `Publish` call.
    - `publishTime` string, google-datetime — The time at which the message was published, populated by the server when it receives the `Publish` call. It must not be populated by the publisher in a `Publish` call.

## Response `200`

Successful response

---

[API](https://skmtc.net/google/apis/pubsub.md) · [All operations](https://skmtc.net/google/apis/pubsub/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/google/pubsub/versions/bf72396b5785/schema)
