unicodeC / Salesforce Platform APIs / Publish multiple events with SOAP call
Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkXmlW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkXmlW xml;
HCkStringBuilderW sbRequestBody;
HCkHttpResponseW resp;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
// 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>
//
xml = CkXmlW_Create();
CkXmlW_putTag(xml,L"SOAP-ENV:Envelope");
CkXmlW_AddAttribute(xml,L"xmlns:SOAP-ENV",L"http://schemas.xmlsoap.org/soap/envelope/");
CkXmlW_AddAttribute(xml,L"xmlns:ns1",L"urn:sobject.partner.soap.sforce.com");
CkXmlW_AddAttribute(xml,L"xmlns:xsi",L"http://www.w3.org/2001/XMLSchema-instance");
CkXmlW_AddAttribute(xml,L"xmlns:ns2",L"urn:partner.soap.sforce.com");
CkXmlW_UpdateChildContent(xml,L"SOAP-ENV:Header|ns2:SessionHeader|ns2:sessionId",L"{{_accessToken}}");
CkXmlW_UpdateChildContent(xml,L"SOAP-ENV:Body|ns2:create|ns2:sObjects|ns1:type",L"Carbon_Comparison__e");
CkXmlW_UpdateChildContentInt(xml,L"SOAP-ENV:Body|ns2:create|ns2:sObjects|Annual_Mileage__c",12000);
CkXmlW_UpdateChildContent(xml,L"SOAP-ENV:Body|ns2:create|ns2:sObjects|Current_Vehicle__c",L"Fast car 1");
CkXmlW_UpdateChildContentInt(xml,L"SOAP-ENV:Body|ns2:create|ns2:sObjects|Model_Year__c",2019);
CkXmlW_UpdateChildContent(xml,L"SOAP-ENV:Body|ns2:create|ns2:sObjects[1]|ns1:type",L"Carbon_Comparison__e");
CkXmlW_UpdateChildContentInt(xml,L"SOAP-ENV:Body|ns2:create|ns2:sObjects[1]|Annual_Mileage__c",12000);
CkXmlW_UpdateChildContent(xml,L"SOAP-ENV:Body|ns2:create|ns2:sObjects[1]|Current_Vehicle__c",L"Fast car 2");
CkXmlW_UpdateChildContentInt(xml,L"SOAP-ENV:Body|ns2:create|ns2:sObjects[1]|Model_Year__c",2019);
CkHttpW_SetRequestHeader(http,L"SOAPAction",L"create");
CkHttpW_SetRequestHeader(http,L"Content-Type",L"text/xml");
// Adds the "Authorization: Bearer <access_token>" header.
CkHttpW_putAuthToken(http,L"<access_token>");
CkHttpW_SetRequestHeader(http,L"Accept",L"text/xml");
CkHttpW_SetRequestHeader(http,L"charset",L"UTF-8");
sbRequestBody = CkStringBuilderW_Create();
CkXmlW_GetXmlSb(xml,sbRequestBody);
resp = CkHttpW_PTextSb(http,L"POST",L"https://domain.com/services/Soap/u/{{version}}",sbRequestBody,L"utf-8",L"text/xml",FALSE,FALSE);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkXmlW_Dispose(xml);
CkStringBuilderW_Dispose(sbRequestBody);
return;
}
wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkXmlW_Dispose(xml);
CkStringBuilderW_Dispose(sbRequestBody);
}
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": [
]
}