Newer Version Available

This content describes an older version of this product. View Latest

Platform Event Schema by Event Name

Gets the definition of a platform event in JSON format for an event name.

Syntax

URI
/vXX.X/sobjects/Event_Name/eventSchema
Available since release
40.0
Formats
JSON
HTTP methods
GET
Authentication
Authorization: Bearer token
Parameters
Parameter Description
payloadFormat (Optional query parameter. Available in API version 43.0 and later.) The format of the returned event schema. This parameter can take one of the following values.
  • EXPANDED—The JSON representation of the event schema, which is the default format when payloadFormat is not specified in API version 43.0 and later.
  • COMPACT—A format that adheres to the open-source Apache Avro specification for the record complex type (see Apache Avro Format). Subscribers use the compact schema format to deserialize compact events received in binary form.

Error Codes

400 Bad Request Description
In API version 43.0 and later The request was formatted incorrectly—an invalid value was passed for the payloadFormat parameter in the URI.
In API version 42.0 and earlier The request was formatted incorrectly—the payloadFormat parameter was passed in the URI but this API version doesn’t support this parameter.

Examples for API Version 43.0 and Later

This URI gets the schema of a platform event named Low_Ink__e. In API version 43.0 and later, the default response format is the JSON representation of the event schema.

1/services/data/v43.0/sobjects/Low_Ink__e/eventSchema

Or:

1/services/data/v43.0/sobjects/Low_Ink__e/eventSchema?payloadFormat=EXPANDED

The returned response for the expanded format looks like the following in API version 43.0.

1{
2  "name" : "Low_Ink__e",
3  "namespace" : "com.sforce.eventbus",
4  "type" : "expanded-record",
5  "fields" : [ {
6    "name" : "data",
7    "type" : {
8      "type" : "record",
9      "name" : "Data",
10      "namespace" : "",
11      "fields" : [ {
12        "name" : "schema",
13        "type" : "string"
14      }, {
15        "name" : "payload",
16        "type" : {
17          "type" : "record",
18          "name" : "Payload",
19          "doc" : "",
20          "fields" : [ {
21            "name" : "CreatedDate",
22            "type" : "string",
23            "doc" : "CreatedDate:DateTime"
24          }, {
25            "name" : "CreatedById",
26            "type" : "string",
27            "doc" : "CreatedBy:EntityId"
28          }, {
29            "name" : "Printer_Model__c",
30            "type" : [ "null", "string" ],
31            "doc" : "Data:Text",
32            "default" : null
33          }, {
34            "name" : "Serial_Number__c",
35            "type" : [ "null", "string" ],
36            "doc" : "Data:Text",
37            "default" : null
38          }, {
39            "name" : "Ink_Percentage__c",
40            "type" : [ "null", "double" ],
41            "doc" : "Data:Double",
42            "default" : null
43          } ]
44        }
45      }, {
46        "name" : "event",
47        "type" : {
48          "type" : "record",
49          "name" : "Event",
50          "fields" : [ {
51            "name" : "replayId",
52            "type" : "long"
53          } ]
54        }
55      } ]
56    }
57  }, {
58    "name" : "channel",
59    "type" : "string"
60  } ]
61}

To get the compact (Apache Avro) format, use the following URI.

1/services/data/v43.0/sobjects/Low_Ink__e/eventSchema?payloadFormat=COMPACT

The returned response for the compact format looks like the following in API version 43.0.

1{
2  "name" : "Low_Ink__e",
3  "namespace" : "com.sforce.eventbus",
4  "doc" : "43.0",
5  "type" : "record",
6  "fields" : [ {
7    "name" : "CreatedDate",
8    "type" : "long",
9    "doc" : "CreatedDate:DateTime"
10  }, {
11    "name" : "CreatedById",
12    "type" : "string",
13    "doc" : "CreatedBy:EntityId"
14  }, {
15    "name" : "Printer_Model__c",
16    "type" : [ "null", "string" ],
17    "doc" : "Data:Text",
18    "default" : null
19  }, {
20    "name" : "Serial_Number__c",
21    "type" : [ "null", "string" ],
22    "doc" : "Data:Text",
23    "default" : null
24  }, {
25    "name" : "Ink_Percentage__c",
26    "type" : [ "null", "double" ],
27    "doc" : "Data:Double",
28    "default" : null
29  } ],
30  "uuid" : "5E5OtZj5_Gm6Vax9XMXH9A"
31}

The compact schema doesn’t include the replayId or channel fields because these fields are not necessary for deserializing the compact event received.

Note

Examples for API Version 42.0 and Earlier

In API version 42.0 and earlier, the response format adheres to the open-source Apache Avro specification for the record complex type.

This format is what the API returns in API version 43.0 and later when appending the ?payloadFormat=COMPACT parameter.

Note

1/services/data/v42.0/sobjects/Low_Ink__e/eventSchema

The returned response looks like the following in API version 42.0.

1{
2  "name" : "Low_Ink__e",
3  "namespace" : "com.sforce.eventbus",
4  "doc" : "42.0",
5  "type" : "record",
6  "fields" : [ {
7    "name" : "CreatedDate",
8    "type" : "long",
9    "doc" : "CreatedDate:DateTime"
10  }, {
11    "name" : "CreatedById",
12    "type" : "string",
13    "doc" : "CreatedBy:EntityId"
14  }, {
15    "name" : "Printer_Model__c",
16    "type" : [ "null", "string" ],
17    "doc" : "Data:Text",
18    "default" : null
19  }, {
20    "name" : "Serial_Number__c",
21    "type" : [ "null", "string" ],
22    "doc" : "Data:Text",
23    "default" : null
24  }, {
25    "name" : "Ink_Percentage__c",
26    "type" : [ "null", "double" ],
27    "doc" : "Data:Double",
28    "default" : null
29  } ],
30  "uuid" : "5E5OtZj5_Gm6Vax9XMXH9A"
31}

When you change the definition of a platform event, the schema ID for this platform event changes.

Note

Apache Avro Format

The fields in the returned response adhere to the open-source Apache Avro specification for the record complex type (see Avro Records in the Apache Avro specification). Note the following:
  • name is the name of the platform event.
  • namespace corresponds to com.sforce.eventbus.
  • type is the Avro complex type.
  • fields is a JSON array containing the fields of the platform event. For each field, type indicates that the field can be either null or have a value of the specified type. When the field is not present, the value is default. Also, doc is the field data type. The data type information is used to convert DateTime fields from long to DateTime.

The response also includes the uuid field, which contains the schema’s ID. The ID is the MD5 fingerprint of the normalized Avro schema encoded as a base-64 URL variant. You can append this ID to the /vXX.X/event/eventSchema/ URI to retrieve the schema.