Using Python zeep, I'm interacting with Salesforce's SOAP (specifically, Metadata) API.
Trying to createMetadata
I get this error:
Fault: Must specify a {http://www.w3.org/2001/XMLSchema-instance}type attribute value for the {http://soap.sforce.com/2006/04/metadata}metadata element
I've gathered that this is not about parameters passed to the method (the way createMetadata
requires a metadata
argument, which itself is an object with a fullName
field), but rather about a missing xsi:type
attribute somewhere.
This is my zeep
call:
resp = service['createMetadata'](_soapheaders=soap_headers,
metadata=[{'fullName': 'SomeCustomObject'}])
This is the generated XML:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Body>
<ns0:createMetadata xmlns:ns0="http://soap.sforce.com/2006/04/metadata">
<ns0:metadata>
<ns0:fullName>SomeCustomObject</ns0:fullName>
</ns0:metadata>
</ns0:createMetadata>
</soap-env:Body>
</soap-env:Envelope>
My question is: how can I set that xsi:type
on whatever it needs to be set on (that ns0:metadata
guy?) using zeep
?
UPDATE:
Instead of using a dictionary to represent the metadata object, I replaced it with this:
metadata_type = client.get_type('{http://soap.sforce.com/2006/04/metadata}Metadata')
metadata = metadata_type(fullName='SomeCustomObject')
resp = service['createMetadata'](_soapheaders=soap_headers, metadata=[metadata])
The new generated XML is:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Body>
<ns0:createMetadata xmlns:ns0="http://soap.sforce.com/2006/04/metadata">
<ns0:metadata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns0:Metadata">
<ns0:fullName>SomeCustomObject</ns0:fullName>
</ns0:metadata>
</ns0:createMetadata>
</soap-env:Body>
</soap-env:Envelope>
which has the xsi:type
attribute on the ns0:metadata
tag, but I get the same error as before. So I guess it wasn't about a missing xsi:type
. Any ideas on what it is?