You need to sign in to do that
Don't have an account?
Singer-Clark
Logging in SOAP API / Metadata API in Python
I'm using Python [zeep](http://docs.python-zeep.org/en/master/) to use SOAP to interact with Salesforce's Metadata API.
I'm attempting to start with the simplest thing possible, just log in and read a metadata object.
from zeep import Client as zClient
client = zClient('sf_config/sf_metadata_40.xml')
// readMetadata method exists, prints <zeep.client.OperationProxy object at ...>
print client.service.readMetadata
// errors because login method does not exist
print client.service.login
I know the zeep client reads the XML because it correctly knows that `readMetadata` exists, but I'm confused about how I am supposed to log in with my Salesforce username and password. I expected a `login` method to exist.
Additionally, I tried adding username and password to the construction of the `client` object:
from zeep.wsse.username import UsernameToken
client = zClient('sf_config/sf_metadata_40.xml',
wsse=UsernameToken('bub@bob.com', 'scary_secretPassW*rd'))
but it was unsuccessful, in that, executing the `readMetadata` method caused this error:
`Fault: UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService`
(The Java examples in Salesforce docs use a `connection` object that I'm not really sure what the Python zeep equivalent would be, so I don't have an example to go off of.)
UPDATE:
That error brings this to mind, from the [docs](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_calls_intro.htm):
> Retrieve the metadataServerUrl from the LoginResult returned by your SOAP API login() call.
But I'm not sure what the `login()` call is, since such a method does not exist on the `client.service`.
I'm attempting to start with the simplest thing possible, just log in and read a metadata object.
from zeep import Client as zClient
client = zClient('sf_config/sf_metadata_40.xml')
// readMetadata method exists, prints <zeep.client.OperationProxy object at ...>
print client.service.readMetadata
// errors because login method does not exist
print client.service.login
I know the zeep client reads the XML because it correctly knows that `readMetadata` exists, but I'm confused about how I am supposed to log in with my Salesforce username and password. I expected a `login` method to exist.
Additionally, I tried adding username and password to the construction of the `client` object:
from zeep.wsse.username import UsernameToken
client = zClient('sf_config/sf_metadata_40.xml',
wsse=UsernameToken('bub@bob.com', 'scary_secretPassW*rd'))
but it was unsuccessful, in that, executing the `readMetadata` method caused this error:
`Fault: UNKNOWN_EXCEPTION: Destination URL not reset. The URL returned from login must be set in the SforceService`
(The Java examples in Salesforce docs use a `connection` object that I'm not really sure what the Python zeep equivalent would be, so I don't have an example to go off of.)
UPDATE:
That error brings this to mind, from the [docs](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_calls_intro.htm):
> Retrieve the metadataServerUrl from the LoginResult returned by your SOAP API login() call.
But I'm not sure what the `login()` call is, since such a method does not exist on the `client.service`.
That says I can use access token from OAuth flow (which I've already done before, so have the access token) in place of the session ID, which you mention to put in the header.
But what about the server URL? How can I get that if I'm using the OAuth flow (and thus don't do the login() call which normally gives you the server URL to use as the endpoint)?
https://developer.salesforce.com/page/Digging_Deeper_into_OAuth_2.0_on_Force.com
How does that relate to Metadata API though? Once you have that, is there a specific URL path to put at the end of it, to construct the Metadata API?
https://help.salesforce.com/articleView?id=000004383&type=1