Help Center/ EventGrid/ API Reference/ APIs/ Event Management/ Publishing an Event to an Event Channel
Updated on 2023-05-24 GMT+08:00

Publishing an Event to an Event Channel

Function

This API is used to publish an event to an event channel.

URI

POST /v1/{project_id}/channels/{channel_id}/events

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Tenant project ID.

channel_id

Yes

String

ID of the event channel.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token. The token can be obtained by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token.

Minimum: 1

Maximum: 16384

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

events

No

Array of CloudEvents objects

CloudEvents event format definition. For details, see https://github.com/cloudevents/spec/blob/v1.0.1/spec.md.

Table 4 CloudEvents

Parameter

Mandatory

Type

Description

id

Yes

String

Event ID. The ID must be unique for the same event source.

source

Yes

String

Event source. The combination of source and id uniquely identifies an event. The URI-Reference format is used. For details, see https://tools.ietf.org/html/rfc3986#section-4.1.

specversion

Yes

String

CloudEvents protocol version. The format is major.minor.

type

Yes

String

Event type.

datacontenttype

No

String

Event content format. Events use the MIME format and comply with RFC 2046. For details, see https://tools.ietf.org/html/rfc2046.

dataschema

No

String

URI defined by the event content schema, which complies with RFC 3986. For details, see https://tools.ietf.org/html/rfc3986#section-4.3.

data

No

Object

Event payload content, which uses the format specified by the datacontenttype field. The content field complies with the description of the dataschema field.

time

No

String

UTC time when the event occurs. Events from the same source have the same format, which complies with RFC 3339. An example format is 2018-04-05T17:31:00Z. For details, see https://tools.ietf.org/html/rfc3339.

subject

No

String

Subject or object where the event occurs.

Response Parameters

Status code: 200

Table 5 Response header parameters

Parameter

Type

Description

X-Request-Id

String

This field is the request ID number for task tracking. Format is request_uuid-timestamp-hostname.

Table 6 Response body parameters

Parameter

Type

Description

failed_count

Integer

Number of events that fail to be published.

events

Array of events objects

Event list.

Table 7 events

Parameter

Type

Description

error_code

String

Error code displayed for the publishing failure.

error_msg

String

Cause of the publishing failure.

event_id

String

Unique ID of the event.

Status code: 400

Table 8 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

Minimum: 1

Maximum: 128

error_msg

String

Error message.

Minimum: 1

Maximum: 512

error_details

String

Error details.

Minimum: 1

Maximum: 1024

request_id

String

Request ID.

Minimum: 1

Maximum: 128

Status code: 401

Table 9 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

Minimum: 1

Maximum: 128

error_msg

String

Error message.

Minimum: 1

Maximum: 512

error_details

String

Error details.

Minimum: 1

Maximum: 1024

request_id

String

Request ID.

Minimum: 1

Maximum: 128

Status code: 403

Table 10 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

Minimum: 1

Maximum: 128

error_msg

String

Error message.

Minimum: 1

Maximum: 512

error_details

String

Error details.

Minimum: 1

Maximum: 1024

request_id

String

Request ID.

Minimum: 1

Maximum: 128

Status code: 404

Table 11 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

Minimum: 1

Maximum: 128

error_msg

String

Error message.

Minimum: 1

Maximum: 512

error_details

String

Error details.

Minimum: 1

Maximum: 1024

request_id

String

Request ID.

Minimum: 1

Maximum: 128

Status code: 500

Table 12 Response body parameters

Parameter

Type

Description

error_code

String

Error code.

Minimum: 1

Maximum: 128

error_msg

String

Error message.

Minimum: 1

Maximum: 512

error_details

String

Error details.

Minimum: 1

Maximum: 1024

request_id

String

Request ID.

Minimum: 1

Maximum: 128

Example Requests

Publish events from a specified source to a channel.

/v1/{project_id}/channels/{channel_id}/events

{
  "events" : [ {
    "specversion" : "1.0",
    "id" : "eventid",
    "source" : "{{source-name}}",
    "type" : "blob_created",
    "data" : {
      "name" : "values"
    },
    "subject" : "myevent.jpg"
  } ]
}

Example Responses

Status code: 400

{
  "error_code" : "EG.00014000",
  "error_msg" : "Bad request"
}

Status code: 401

{
  "error_code" : "EG.00014010",
  "error_msg" : "Incorrect token or token resolution failed"
}

Status code: 403

{
  "error_code" : "EG.00014030",
  "error_msg" : "No permissions to request this method"
}

Status code: 404

{
  "error_code" : "EG.00014040",
  "error_msg" : "Not request resource found"
}

Status code: 500

{
  "error_code" : "EG.00015000",
  "error_msg" : "Internal Server Error"
}

Status Codes

Status Code

Description

200

Information

400

Invalid request.

401

Unauthorized.

403

Access denied.

404

Resource not found.

500

Internal service error.

Error Codes

See Error Codes.