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"?>
-- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://soap.sforce.com/2006/04/metadata">
-- <soapenv:Header>
-- <tns:SessionHeader>
-- <tns:sessionId>{{_accessToken}}</tns:sessionId>
-- </tns:SessionHeader>
-- </soapenv:Header>
-- <soapenv:Body>
-- <tns:describeValueType>
-- <type>{http://soap.sforce.com/2006/04/metadata}INSERT_METADATA_TYPE_NAME</type>
-- </tns:describeValueType>
-- </soapenv:Body>
-- </soapenv: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', 'soapenv:Envelope'
EXEC sp_OAMethod @xml, 'AddAttribute', @success OUT, 'xmlns:soapenv', 'http://schemas.xmlsoap.org/soap/envelope/'
EXEC sp_OAMethod @xml, 'AddAttribute', @success OUT, 'xmlns:tns', 'http://soap.sforce.com/2006/04/metadata'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'soapenv:Header|tns:SessionHeader|tns:sessionId', '{{_accessToken}}'
EXEC sp_OAMethod @xml, 'UpdateChildContent', NULL, 'soapenv:Body|tns:describeValueType|type', '{http://soap.sforce.com/2006/04/metadata}INSERT_METADATA_TYPE_NAME'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Content-Type', 'text/xml'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'SOAPAction', 'login'
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/m/{{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
DECLARE @sbResponseBody int
-- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @resp, 'GetBodySb', @success OUT, @sbResponseBody
EXEC @hr = sp_OADestroy @resp
DECLARE @xmlResponse int
-- Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Xml', @xmlResponse OUT
EXEC sp_OAMethod @xmlResponse, 'LoadSb', @success OUT, @sbResponseBody, 1
EXEC sp_OAMethod @xmlResponse, 'GetXml', @sTmp0 OUT
PRINT @sTmp0
-- Sample XML response:
-- (Sample code for parsing the XML response is shown below)
-- <?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>
-- <describeValueTypeResponse>
-- <result>
-- <apiCreatable>false</apiCreatable>
-- <apiDeletable>false</apiDeletable>
-- <apiReadable>false</apiReadable>
-- <apiUpdatable>false</apiUpdatable>
-- </result>
-- </describeValueTypeResponse>
-- </soapenv:Body>
-- </soapenv:Envelope>
-- Sample code for parsing the XML response...
-- Use this online tool to generate parsing code from sample XML: Generate XML Parsing Code
DECLARE @soapenv_Envelope_xmlns_soapenv nvarchar(4000)
EXEC sp_OAMethod @xmlResponse, 'GetAttrValue', @soapenv_Envelope_xmlns_soapenv OUT, 'xmlns:soapenv'
DECLARE @soapenv_Envelope_xmlns nvarchar(4000)
EXEC sp_OAMethod @xmlResponse, 'GetAttrValue', @soapenv_Envelope_xmlns OUT, 'xmlns'
DECLARE @apiCreatable nvarchar(4000)
EXEC sp_OAMethod @xmlResponse, 'GetChildContent', @apiCreatable OUT, 'soapenv:Body|describeValueTypeResponse|result|apiCreatable'
DECLARE @apiDeletable nvarchar(4000)
EXEC sp_OAMethod @xmlResponse, 'GetChildContent', @apiDeletable OUT, 'soapenv:Body|describeValueTypeResponse|result|apiDeletable'
DECLARE @apiReadable nvarchar(4000)
EXEC sp_OAMethod @xmlResponse, 'GetChildContent', @apiReadable OUT, 'soapenv:Body|describeValueTypeResponse|result|apiReadable'
DECLARE @apiUpdatable nvarchar(4000)
EXEC sp_OAMethod @xmlResponse, 'GetChildContent', @apiUpdatable OUT, 'soapenv:Body|describeValueTypeResponse|result|apiUpdatable'
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @xml
EXEC @hr = sp_OADestroy @sbRequestBody
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @xmlResponse
END
GO
Curl Command
curl -X POST
-H "Content-Type: text/xml"
-H "charset: UTF-8"
-H "SOAPAction: login"
-H "Accept: text/xml"
-d '<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://soap.sforce.com/2006/04/metadata">
<soapenv:Header>
<tns:SessionHeader>
<tns:sessionId>{{_accessToken}}</tns:sessionId>
</tns:SessionHeader>
</soapenv:Header>
<soapenv:Body>
<tns:describeValueType>
<type>{http://soap.sforce.com/2006/04/metadata}INSERT_METADATA_TYPE_NAME</type>
</tns:describeValueType>
</soapenv:Body>
</soapenv:Envelope>'
https://domain.com/services/Soap/m/{{version}}
Postman Collection Item JSON
{
"name": "SOAP DescribeValueType",
"event": [
{
"listen": "test",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "text/xml",
"type": "text"
},
{
"key": "charset",
"value": "UTF-8"
},
{
"key": "SOAPAction",
"value": "login"
},
{
"key": "Accept",
"value": "text/xml",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tns=\"http://soap.sforce.com/2006/04/metadata\">\n\t<soapenv:Header>\n\t<tns:SessionHeader>\n\t\t<tns:sessionId>{{_accessToken}}</tns:sessionId>\n\t</tns:SessionHeader>\n\t</soapenv:Header>\n\t<soapenv:Body>\n\t\t<tns:describeValueType>\n\t\t\t<type>{http://soap.sforce.com/2006/04/metadata}INSERT_METADATA_TYPE_NAME</type>\n\t\t</tns:describeValueType>\n\t</soapenv:Body>\n</soapenv:Envelope>"
},
"url": {
"raw": "{{_endpoint}}/services/Soap/m/{{version}}",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"Soap",
"m",
"{{version}}"
]
}
},
"response": [
{
"name": "Status200-Success",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "text/xml"
},
{
"key": "charset",
"value": "UTF-8"
},
{
"key": "SOAPAction",
"value": "login"
},
{
"key": "Accept",
"value": "text/xml"
}
],
"body": {
"mode": "raw",
"raw": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tns=\"http://soap.sforce.com/2006/04/metadata\">\n\t<soapenv:Header>\n\t<tns:SessionHeader>\n\t\t<tns:sessionId>{{_accessToken}}</tns:sessionId>\n\t</tns:SessionHeader>\n\t</soapenv:Header>\n\t<soapenv:Body>\n\t\t<tns:describeValueType>\n\t\t\t<type>{http://soap.sforce.com/2006/04/metadata}INSERT_METADATA_TYPE_NAME</type>\n\t\t</tns:describeValueType>\n\t</soapenv:Body>\n</soapenv:Envelope>"
},
"url": {
"raw": "{{_endpoint}}/services/Soap/m/{{version}}",
"host": [
"{{_endpoint}}"
],
"path": [
"services",
"Soap",
"m",
"{{version}}"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "xml",
"header": [
{
"key": "Date",
"value": "Thu, 07 Sep 2023 09:25:45 GMT"
},
{
"key": "Cache-Control",
"value": "no-cache,must-revalidate,max-age=0,no-store,private"
},
{
"key": "Content-Type",
"value": "text/xml; charset=utf-8"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Transfer-Encoding",
"value": "chunked"
}
],
"cookie": [
],
"body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns=\"http://soap.sforce.com/2006/04/metadata\">\n <soapenv:Body>\n <describeValueTypeResponse>\n <result>\n <apiCreatable>false</apiCreatable>\n <apiDeletable>false</apiDeletable>\n <apiReadable>false</apiReadable>\n <apiUpdatable>false</apiUpdatable>\n </result>\n </describeValueTypeResponse>\n </soapenv:Body>\n</soapenv:Envelope>"
}
]
}