Newer Version Available
Publish Event Messages with Salesforce APIs
Publish events by creating records of your event in the same way that you insert sObjects. You can use any Salesforce API to create platform events, such as SOAP API, REST API, or Bulk API.
REST API
To publish a platform event message using REST API, send a POST request to the following endpoint.
1/services/data/v42.0/sobjects/Event_Name__e/Example
If you’ve defined a platform event named Low Ink, publish event notifications by inserting Low_Ink__e records. This example creates one event of type Low_Ink__e in REST API.
REST endpoint:
1/services/data/v42.0/sobjects/Low_Ink__e/Request body:
1{
2 "Printer_Model__c" : "XZO-5"
3}After the platform event record is created, the REST response looks like this output. Headers are deleted for brevity.
1HTTP/1.1 201 Created
2
3{
4 "id" : "e00xx000000000B",
5 "success" : true,
6 "errors" : [ ]
7}SOAP API
To publish a platform event message using SOAP API, use the create() call.
Example
This example shows the SOAP message (using Partner API) of a request to create three platform events in one call. Each event has one custom field named Printer_Model__c.
1<?xml version="1.0" encoding="UTF-8"?>
2<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:sobject.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns2="urn:partner.soap.sforce.com">
3<SOAP-ENV:Header>
4 <ns2:SessionHeader>
5 <ns2:sessionId>00DR00000001fWV!AQMAQOshATCQ4fBaYFOTrHVixfEO6l...</ns2:sessionId>
6 </ns2:SessionHeader>
7 <ns2:CallOptions>
8 <ns2:client>Workbench/34.0.12i</ns2:client>
9 <ns2:defaultNamespace xsi:nil="true"/>
10 <ns2:returnFieldDataTypes xsi:nil="true"/>
11 </ns2:CallOptions>
12</SOAP-ENV:Header>
13<SOAP-ENV:Body>
14 <ns2:create>
15 <ns2:sObjects>
16 <ns1:type>Low_Ink__e</ns1:type>
17 <ns1:fieldsToNull xsi:nil="true"/>
18 <ns1:Id xsi:nil="true"/>
19 <Printer_Model__c>XZO-600</Printer_Model__c>
20 </ns2:sObjects>
21 <ns2:sObjects>
22 <ns1:type>Low_Ink__e</ns1:type>
23 <ns1:fieldsToNull xsi:nil="true"/>
24 <ns1:Id xsi:nil="true"/>
25 <Printer_Model__c>XYZ-100</Printer_Model__c>
26 </ns2:sObjects>
27 <ns2:sObjects>
28 <ns1:type>Low_Ink__e</ns1:type>
29 <ns1:fieldsToNull xsi:nil="true"/>
30 <ns1:Id xsi:nil="true"/>
31 <Printer_Model__c>XYZ-9000</Printer_Model__c>
32 </ns2:sObjects>
33 </ns2:create>
34</SOAP-ENV:Body>
35</SOAP-ENV:Envelope>The response of the Partner SOAP API request looks something like the following. Headers are deleted for brevity.
1<?xml version="1.0" encoding="UTF-8"?>
2<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:partner.soap.sforce.com">
3<soapenv:Header>
4 ...
5</soapenv:Header>
6<soapenv:Body>
7 <createResponse>
8 <result>
9 <id>e00xx000000000F</id>
10 <success>true</success>
11 </result>
12 <result>
13 <id>e00xx000000000G</id>
14 <success>true</success>
15 </result>
16 <result>
17 <id>e00xx000000000H</id>
18 <success>true</success>
19 </result>
20 </createResponse>
21</soapenv:Body>
22</soapenv:Envelope>