---
title: "POST /v1/projects/{projectsId}/topics/{topicsId}:publish"
method: POST
path: "/v1/projects/{projectsId}/topics/{topicsId}:publish"
tags: ["projects"]
---

# POST /v1/projects/{projectsId}/topics/{topicsId}:publish

`POST /v1/projects/{projectsId}/topics/{topicsId}:publish`

## Request

- Base URL: `https://pubsub.googleapis.com`
- URL: `https://pubsub.googleapis.com/v1/projects/{projectsId}/topics/{topicsId}:publish`
- Auth: one of:
  - OAuth 2 and OAuth 2
    - Implicit: `https://accounts.google.com/o/oauth2/auth`
    - Scopes: `https://www.googleapis.com/auth/cloud-platform`
    - Authorization code: `https://accounts.google.com/o/oauth2/auth`
    - Token URL: `https://accounts.google.com/o/oauth2/token` scopes: `https://www.googleapis.com/auth/cloud-platform`
  - OAuth 2 and OAuth 2
    - Implicit: `https://accounts.google.com/o/oauth2/auth`
    - Scopes: `https://www.googleapis.com/auth/pubsub`
    - Authorization code: `https://accounts.google.com/o/oauth2/auth`
    - Token URL: `https://accounts.google.com/o/oauth2/token` scopes: `https://www.googleapis.com/auth/pubsub`

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

## Path parameters

- `projectsId` string, required
- `topicsId` string, required

## Query parameters

- `$.xgafv` '1' | '2'
- `access_token` string
- `alt` 'json' | 'media' | 'proto'
- `callback` string
- `fields` string
- `key` string
- `oauth_token` string
- `prettyPrint` boolean
- `quotaUser` string
- `uploadType` string
- `upload_protocol` string

## 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.
    - `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.
    - `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).
    - `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

- PublishResponse: Response for the `Publish` method.
  - `messageIds` string[]: Optional. The server-assigned ID of each published message, in the same order as the messages in the request. IDs are guaranteed to be unique within the topic.

## Changes

- **2026-11-11** `5eea47510ec8`: 4 info
  - the security scope `https://www.googleapis.com/auth/cloud-platform` was added to the endpoint's security scheme `Oauth2`
  - the security scope `https://www.googleapis.com/auth/cloud-platform` was added to the endpoint's security scheme `Oauth2c`
  - the security scope `https://www.googleapis.com/auth/pubsub` was removed from the endpoint's security scheme `Oauth2`
  - the security scope `https://www.googleapis.com/auth/pubsub` was removed from the endpoint's security scheme `Oauth2c`

[Operation history](https://skmtc.dev/google/apis/pubsub/changes/v1/projects/:projectsId/topics/:topicsId:publish/post.md)

---

[API](https://skmtc.dev/google/apis/pubsub.md) - [All operations](https://skmtc.dev/google/apis/pubsub/llms.txt) - [OpenAPI document](https://skmtc.dev/google/apis/pubsub/revisions/5eea47510ec8?raw)
