SQL Server / Salesforce Platform APIs / Publish multiple events with SOAP call
Back to Collection Items
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @http int
-- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
-- Use this online tool to generate code from sample XML: Generate Code to Create XML
-- The following XML is sent in the request body.
-- <?xml version="1.0" encoding="UTF-8"?>
-- <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">
-- <SOAP-ENV:Header>
-- <ns2:SessionHeader>
-- <ns2:sessionId>{{_accessToken}}</ns2:sessionId>
-- </ns2:SessionHeader>
-- </SOAP-ENV:Header>
-- <SOAP-ENV:Body>
-- <ns2:create>
-- <ns2:sObjects>
-- <ns1:type>Carbon_Comparison__e</ns1:type>
-- <Annual_Mileage__c>12000</Annual_Mileage__c>
-- <Current_Vehicle__c>Fast car 1</Current_Vehicle__c>
-- <Model_Year__c>2019</Model_Year__c>
-- </ns2:sObjects>
-- <ns2:sObjects>
-- <ns1:type>Carbon_Comparison__e</ns1:type>
-- <Annual_Mileage__c>12000</Annual_Mileage__c>
-- <Current_Vehicle__c>Fast car 2</Current_Vehicle__c>
-- <Model_Year__c>2019</Model_Year__c>
-- </ns2:sObjects>
-- </ns2:create>
-- </SOAP-ENV:Body>
-- </SOAP-ENV:Envelope>
--
DECLARE @xml int
-- Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Xml', @xml OUT
EXEC sp_OASetProperty @xml, 'Tag', 'SOAP-ENV:Envelope'
EXEC sp_OAMethod @xml, 'AddAttribute', @success OUT, 'xmlns:SOAP-ENV', 'http://schemas.xmlsoap.org/soap/envelope/'
EXEC sp_OAMethod @xml, 'AddAttribute', @success OUT, 'xmlns:ns1', 'urn:sobject.partner.soap.sforce.com'
EXEC sp_OAMethod @xml, 'AddAttribute', @success OUT, 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'
EXEC sp_OAMethod @xml, 'AddAttribute', @success OUT, 'xmlns:ns2', 'urn:partner.soap.sforce.com'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'SOAP-ENV:Header|ns2:SessionHeader|ns2:sessionId', '{{_accessToken}}'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'SOAP-ENV:Body|ns2:create|ns2:sObjects|ns1:type', 'Carbon_Comparison__e'
EXEC sp_OAMethod @xml, 'UpdateChildContentInt', NULL, 'SOAP-ENV:Body|ns2:create|ns2:sObjects|Annual_Mileage__c', 12000
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'SOAP-ENV:Body|ns2:create|ns2:sObjects|Current_Vehicle__c', 'Fast car 1'
EXEC sp_OAMethod @xml, 'UpdateChildContentInt', NULL, 'SOAP-ENV:Body|ns2:create|ns2:sObjects|Model_Year__c', 2019
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'SOAP-ENV:Body|ns2:create|ns2:sObjects[1]|ns1:type', 'Carbon_Comparison__e'
EXEC sp_OAMethod @xml, 'UpdateChildContentInt', NULL, 'SOAP-ENV:Body|ns2:create|ns2:sObjects[1]|Annual_Mileage__c', 12000
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'SOAP-ENV:Body|ns2:create|ns2:sObjects[1]|Current_Vehicle__c', 'Fast car 2'
EXEC sp_OAMethod @xml, 'UpdateChildContentInt', NULL, 'SOAP-ENV:Body|ns2:create|ns2:sObjects[1]|Model_Year__c', 2019
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'SOAPAction', 'create'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'text/xml'
-- Adds the "Authorization: Bearer <access_token>" header.
EXEC sp_OASetProperty @http, 'AuthToken', '<access_token>'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'text/xml'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'charset', 'UTF-8'
DECLARE @sbRequestBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbRequestBody OUT
EXEC sp_OAMethod @xml, 'GetXmlSb', @success OUT, @sbRequestBody
DECLARE @resp int
EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'POST', 'https://domain.com/services/Soap/u/{{version}}', @sbRequestBody, 'utf-8', 'text/xml', 0, 0
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @xml
EXEC @hr = sp_OADestroy @sbRequestBody
RETURN
END
EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
PRINT @iTmp0
EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @xml
EXEC @hr = sp_OADestroy @sbRequestBody
END
GO
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-H "Content-Type: text/xml"
-H "charset: UTF-8"
-H "SOAPAction: create"
-H "Accept: text/xml"
-d '<?xml version="1.0" encoding="UTF-8"?>
<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">
<SOAP-ENV:Header>
<ns2:SessionHeader>
<ns2:sessionId>{{_accessToken}}</ns2:sessionId>
</ns2:SessionHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns2:create>
<ns2:sObjects>
<ns1:type>Carbon_Comparison__e</ns1:type>
<Annual_Mileage__c>12000</Annual_Mileage__c>
<Current_Vehicle__c>Fast car 1</Current_Vehicle__c>
<Model_Year__c>2019</Model_Year__c>
</ns2:sObjects>
<ns2:sObjects>
<ns1:type>Carbon_Comparison__e</ns1:type>
<Annual_Mileage__c>12000</Annual_Mileage__c>
<Current_Vehicle__c>Fast car 2</Current_Vehicle__c>
<Model_Year__c>2019</Model_Year__c>
</ns2:sObjects>
</ns2:create>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>'
https://domain.com/services/Soap/u/{{version}}
Postman Collection Item JSON
{
"name": "Publish multiple events with SOAP call",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "text/xml"
},
{
"key": "charset",
"value": "UTF-8"
},
{
"key": "SOAPAction",
"value": "create"
},
{
"key": "Accept",
"value": "text/xml"
}
],
"body": {
"mode": "raw",
"raw": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<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\">\n <SOAP-ENV:Header>\n <ns2:SessionHeader>\n <ns2:sessionId>{{_accessToken}}</ns2:sessionId>\n </ns2:SessionHeader>\n </SOAP-ENV:Header>\n <SOAP-ENV:Body>\n <ns2:create>\n <ns2:sObjects>\n <ns1:type>Carbon_Comparison__e</ns1:type>\n <Annual_Mileage__c>12000</Annual_Mileage__c>\n <Current_Vehicle__c>Fast car 1</Current_Vehicle__c>\n <Model_Year__c>2019</Model_Year__c>\n </ns2:sObjects>\n <ns2:sObjects>\n <ns1:type>Carbon_Comparison__e</ns1:type>\n <Annual_Mileage__c>12000</Annual_Mileage__c>\n <Current_Vehicle__c>Fast car 2</Current_Vehicle__c>\n <Model_Year__c>2019</Model_Year__c>\n </ns2:sObjects>\n </ns2:create>\n </SOAP-ENV:Body>\n</SOAP-ENV:Envelope>",
"options": {
"raw": {
"language": "xml"
}
}
},
"url": {
"raw": "{{_endpoint}}/services/Soap/u/{{version}}",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"Soap",
"u",
"{{version}}"
]
}
},
"response": [
]
}