Hi,
I'm trying to authenticate with Trafficvance API.
for example: http://apitest.trafficvance.com/?v3=campaigns.wsdl
Their API requires and AuthenticateRequest with each request.
Quoting their documentation:
Authentication credentials are required to be specified within the SOAP XML request header. You need to invoke AuthenticateRequest
operation and provide the API key as its only parameter, please see available examples for more details
I can't find any way to use this API with Zeep library.
No matter what I try I get zeep.exceptions.Fault: Access denied, authentication failed
Is it even possible?
You can send the headers when you make the operation call by setting _soapheader along with it, eg:
client.service.getCampaignIds(filterNames=['filtered name'], _soapheader={'apiKey': 'myApiKey'})
Ok thanks! authentications seems to be working now!
I think It should be added to documentation..
But now I get
Requested operation failed [Description: Invalid operation requested] [Service: Campaigns Service v3] [Operation: addCampaignRequest]
no matter what I try.. dont know if its related to how zeep works or the API itself
Hm, I'm afraid I need more information to do something with this. Not familiair with the API.
What you can do is use soap-ui to do the request and if that works we can compare the XML generated by soap-ui with the xml generated by zeep
Looks like you're trying to call addCampaignRequest directly, you want to call something like:
client.service.addCampaign(campaign={'name': 'foo', ...})
You'll need to make sure you fill out whatever data is required by the API, which from that wsdl it looks like all of the fields of a CampaignAdd complex type need to be between 1-250 chars.
With an API Key this example code made it work for us.
-- UPDATE: 2018-01-21
Fixed spelling mistakes pointed out below
from zeep import Client, xsd
API_KEY_TEST = 'YOUR_OWN_API_KEY'
WSDL_TEST = 'https://apitest.trafficvance.com/?v3=system.wsdl'
client = Client(WSDL)
header = xsd.Element(
'{WSDL_TEST}AuthenticateRequest',
xsd.ComplexType([
xsd.Element(
'{WSDL_TEST}apiKey', xsd.String()
)
])
)
header_value = header(apiKey=API_KEY_TEST)
res = client.service.getServerTime(_soapheaders=[header_value])
@MichaelSvendsen I was working on something similar and this really helped. Thanks.
By the way, in your code you've declared WSDL_TEST but misspelt it further down as WDSL_TEST
Most helpful comment
With an API Key this example code made it work for us.
-- UPDATE: 2018-01-21
Fixed spelling mistakes pointed out below