Skip to content

Instantly share code, notes, and snippets.

@wadewegner
Created February 21, 2014 17:58
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save wadewegner/9139536 to your computer and use it in GitHub Desktop.
Save wadewegner/9139536 to your computer and use it in GitHub Desktop.
Examples of HTTP requests and responses for Salesforce SOAP and Metadata API calls.
POST https://na15.salesforce.com/services/Soap/m/29.0/00Di0000000icUB HTTP/1.1
SOAPAction: create
Content-Type: text/xml; charset=utf-8
Host: na15.salesforce.com
Content-Length: 894
Expect: 100-continue
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:apex="http://soap.sforce.com/2006/08/apex" xmlns:cmd="http://soap.sforce.com/2006/04/metadata" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<cmd:SessionHeader>
<cmd:sessionId>00Di0000000icUB!ASAAQF0stgINehCxOnHPGuLI4TMVx.jP8rEkLY5axmf0XWLfj0WFsmXhfXoFFgJ2gw1b2DImwyzSFPgB2wuIwNtG94ytkpoh</cmd:sessionId>
</cmd:SessionHeader>
</soapenv:Header>
<soapenv:Body>
<create xmlns="http://soap.sforce.com/2006/04/metadata">
<metadata xsi:type="CustomField">
<fullName>MyCustomObject2__c.MyField__c</fullName>
<label>MyField</label>
<length>100</length>
<type>Text</type>
</metadata>
</create>
</soapenv:Body>
</soapenv:Envelope>
POST https://na15.salesforce.com/services/Soap/m/29.0/00Di0000000icUB HTTP/1.1
SOAPAction: create
Content-Type: text/xml; charset=utf-8
Host: na15.salesforce.com
Content-Length: 1057
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:apex="http://soap.sforce.com/2006/08/apex" xmlns:cmd="http://soap.sforce.com/2006/04/metadata" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<cmd:SessionHeader>
<cmd:sessionId>00Di0000000icUB!ASAAQF0stgINehCxOnHPGuLI4TMVx.jP8rEkLY5axmf0XWLfj0WFsmXhfXoFFgJ2gw1b2DImwyzSFPgB2wuIwNtG94ytkpoh</cmd:sessionId>
</cmd:SessionHeader>
</soapenv:Header>
<soapenv:Body>
<create xmlns="http://soap.sforce.com/2006/04/metadata">
<metadata xsi:type="CustomObject">
<fullName>MyCustomObject2__c</fullName>
<label>MyCustomObject2</label>
<pluralLabel>MyCustomObject2</pluralLabel>
<deploymentStatus>Deployed</deploymentStatus>
<sharingModel>ReadWrite</sharingModel>
<nameField>
<label>ID</label>
<type>AutoNumber</type>
</nameField>
</metadata>
</create>
</soapenv:Body>
</soapenv:Envelope>
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/2006/04/metadata">
<soapenv:Body>
<createResponse>
<result>
<done>false</done>
<id>04si0000000tpbwAAA</id>
<state>InProgress</state>
</result>
</createResponse>
</soapenv:Body>
</soapenv:Envelope>
POST https://login.salesforce.com/services/Soap/c/29.0/0DFi00000008UYO HTTP/1.1
SOAPAction: login
Content-Type: text/xml; charset=utf-8
Host: login.salesforce.com
Content-Length: 307
Expect: 100-continue
Connection: Keep-Alive
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<login xmlns="urn:enterprise.soap.sforce.com">
<username>you@yourdomain.com</username>
<password>password</password>
</login>
</soapenv:Body>
</soapenv:Envelope>
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="urn:enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<loginResponse>
<result>
<metadataServerUrl>https://na15.salesforce.com/services/Soap/m/29.0/00Di0000000icUB</metadataServerUrl>
<passwordExpired>false</passwordExpired>
<sandbox>false</sandbox>
<serverUrl>https://na15.salesforce.com/services/Soap/c/29.0/00Di0000000icUB/0DFi00000008UYO</serverUrl>
<sessionId>00Di0000000icUB!ASAAQF0stgINehCxOnHPGuLI4TMVx.jP8rEkLY5axmf0XWLfj0WFsmXhfXoFFgJ2gw1b2DImwyzSFPgB2wuIwNtG94ytkpoh</sessionId>
<userId>005i0000002MUqLAAW</userId>
<userInfo>
<accessibilityMode>false</accessibilityMode>
<currencySymbol>$</currencySymbol>
<orgAttachmentFileSizeLimit>5242880</orgAttachmentFileSizeLimit>
<orgDefaultCurrencyIsoCode>USD</orgDefaultCurrencyIsoCode>
<orgDisallowHtmlAttachments>false</orgDisallowHtmlAttachments>
<orgHasPersonAccounts>false</orgHasPersonAccounts>
<organizationId>00Di0000000icUBEAY</organizationId>
<organizationMultiCurrency>false</organizationMultiCurrency>
<organizationName>salesforce.com</organizationName>
<profileId>00ei0000001CMKcAAO</profileId>
<roleId xsi:nil="true" />
<sessionSecondsValid>7200</sessionSecondsValid>
<userDefaultCurrencyIsoCode xsi:nil="true" />
<userEmail>you@yourdomain.com</userEmail>
<userFullName>Wade Wegner</userFullName>
<userId>005i0000002MUqLAAW</userId>
<userLanguage>en_US</userLanguage>
<userLocale>en_US</userLocale>
<userName>you@yourdomain.com</userName>
<userTimeZone>America/Los_Angeles</userTimeZone>
<userType>Standard</userType>
<userUiSkin>Theme3</userUiSkin>
</userInfo>
</result>
</loginResponse>
</soapenv:Body>
</soapenv:Envelope>
POST https://login.salesforce.com/services/Soap/u/29.0/0DFi00000008UYO HTTP/1.1
SOAPAction: login
Content-Type: text/xml; charset=utf-8
Host: login.salesforce.com
Content-Length: 306
Expect: 100-continue
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<login xmlns="urn:partner.soap.sforce.com">
<username>you@yourdomain.com</username>
<password>password</password>
</login>
</soapenv:Body>
</soapenv:Envelope>
@dharmac1
Copy link

dharmac1 commented Sep 15, 2020

@wadewegner Thank you so much for making this. It was made a long ago, but it helped me today. I would not have had figured this out on my own - Forming request xml for metadata API. I used it with createMetaData and updateMetaData.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment