I'm trying to use the CleverElements SOAP API, but I can't get it to work. I have honestly never worked with SOAP (but a lot with XML-RPC, REST, etc.), and thought it should be straightforward.
I'm using Ruby with the savon gem. I can call any function via SOAP which doesn't need any parameters, but on functions with parameters, the SOAP service doesn't recognize the parameters.
This is my request:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="Sendcockpit/API" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="Sendcockpit/API">
<env:Header>
<validate>
<userid>32027</userid>
<apikey>**************</apikey>
<version>1.0</version>
<mode>live</mode>
</validate>
</env:Header>
<env:Body>
<apiGetListDetails>
<listID>72472</listID>
</apiGetListDetails>
</env:Body>
</env:Envelope>
This is the WSDL file: http://api.sendcockpit.com/server.php?wsdl
Am I missing something (maybe dead simple, super obvious, basic SOAP) stuff?
Never mind. Apparently I need a wrapping <ctListRequest> node. I was under the impression that savon applies all things specified by the wsdl file...
This request works:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsdl="Sendcockpit/API" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="Sendcockpit/API">
<env:Header>
<validate>
<userid>32027</userid>
<apikey>***********</apikey>
<version>1.0</version>
<mode>live</mode>
</validate>
</env:Header>
<env:Body>
<apiGetListDetails>
<ctListRequest>
<listID>72472</listID>
</ctListRequest>
</apiGetListDetails>
</env:Body>
</env:Envelope>
Related
I need to call a SOAP service that doesn’t contain any operation encapsulation on the body.
Normally with Savon (Ruby 2.3, Savon 2.11) we have:
client = Savon.client(endpoint: 'http://example.com', namespace: 'http://v1.example.com')
response = client.call(:opName, message_hash)
And this will generate a request like:
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wsdl="http://v1.example.com" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<wsdl:opName>
...message content ...
</wsdl:opName>
</env:Body>
</env:Envelope>
But I dont want it to generate the <wsdl:opName> node. I tried to passnil as the operation but it generates the tag as <wsdl:>.
I want to generate a SOAP request without it, like:
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wsdl="http://v1.example.com" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
...message content ...
</env:Body>
</env:Envelope>
I"m trying to connect to a SOAP API using Savon.
The WSDL shows this:
wsdl:operation name="CustomerList" parameterOrder="Username Password Settings">
<wsdl:input message="impl:CustomerListRequest" name="CustomerListRequest"/>
<wsdl:output message="impl:CustomerListResponse" name="CustomerListResponse"/>
</wsdl:operation>
Customer Support says to use a request such as this:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:ei2="http://ei2.nobj.nable.com/">
<soap:Header/>
<soap:Body>
<ei2:customerList>
<!--Optional:-->
<ei2:username>testaccount#n-able.com</ei2:username>
<!--Optional:-->
<ei2:password>!PDf2lfij23l!!</ei2:password>
<!--Zero or more repetitions:-->
<ei2:settings>
<!--Optional:-->
<ei2:key>null</ei2:key>
<!--Optional:-->
<ei2:value>null</ei2:value>
</ei2:settings>
</ei2:customerList>
</soap:Body>
</soap:Envelope>
This is my request:
{"SOAPAction"=>"\"CustomerList\"", "Content-Type"=>"text/xml;charset=UTF-8", "Content-Length"=>"452"}
<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:impl="http://www.n-able.com/mickey" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<impl:CustomerList>
<username>test#test.com</username>
<password>MytestPassword1234</password>
<settings>
<listSOs>false</listSOs>
</settings>
</impl:CustomerList>
</env:Body>
</env:Envelope>
The difference is that the WSDL which Savon consumes and generates methods to call off of, is making my request send CustomerList instead of the customerList the API seems to be expecting.
Is there a way to force Savon to send CustomerList instead of customerList without constructing the entire SOAP Request by hand?
Edit 1
Found the answer in this Github Issue. https://github.com/savonrb/savon/issues/530
By adding the following to a gemspec, I was able to get a well formed request:
spec.add_runtime_dependency 'savon', '~> 2.3'
spec.add_runtime_dependency 'wasabi', '~> 3.2'
include one of those when you build your client:
convert_request_keys_to :camelcase # or one of [:lower_camelcase, :upcase, :none]
or work without the WSDL and hand code the call with 'strings'.
I need send message request in Ruby.This message works in the SoapUI see example below:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body><auth:callAuth xmlns:auth="http://auth.org"><auth:StringInput><?xml version="1.0" encoding="UTF-8" ?><ns0:TestService xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns0="http://xml.netbeans.org/schema/TestService" xsi:schemaLocation="http://xml.netbeans.org/schema/TestService AuthReqType.xsd http://xml.netbeans.org/schema/TestService HeaderType.xsd http://xml.netbeans.org/schema/TestService AuthResType.xsd http://xml.netbeans.org/schema/TestService TestService.xsd"><ns0:Header><ns0:Version>3.4.2</ns0:Version><ns0:SrcApp>Test</ns0:SrcApp><ns0:TargetApp>AppName</ns0:TargetApp><ns0:SrcMsgId>00000001198469411500</ns0:SrcMsgId><ns0:TranTimeStamp>20130329104502</ns0:TranTimeStamp></ns0:Header><ns0:Body><ns0:AuthReq><ns0:MsgType>0200</ns0:MsgType><ns0:RvslCde>00</ns0:RvslCde></ns0:AuthReq></ns0:Body></ns0:TestService> ]]></auth:StringInput></auth:callAuth></soapenv:Body>
Using the savon gem, I get the following request XML:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wsdl="URL"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ins0="SOME URL">
<soap:Body>
<ins0:Test xmlns="SOME URL">
</ins0:Test>
</soap:Body>
</soap:Envelope>
But it needs to be this instead:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wsdl="URL"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Test xmlns="SOME URL">
</Test>
</soap:Body>
</soap:Envelope>
Notice ins0 was removed.
Any suggestions?
The two XML documents are equivalent, so there should be no issues as long as the document is parsed by an XML compliant agent.
The Savon generated document is simply creating a namespace prefix of ins0 for the "SOME URL" namespace. This is convenient for a large SOAP document with many elements from that namespace. In this example, the prefix is not really necessary.
The only potential issue I can see is that the Savion generated document seems to declare the ins0 namespace twice - once in the soap:Envelope and then again in the soap:Body. Seems superfluous and potentially open to error.
I'm running into some issues doing a describeSObject call from a ruby on rails application using Savon. Could someone share an example of what my soap body should look like either from past experience with the salesforce partner api or general wsdl knowledge?
Here's what my application is generating:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:wsdl="urn:partner.soap.sforce.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ins0="urn:partner.soap.sforce.com" xmlns:ins1="urn:fault.partner.soap.sforce.com" xmlns:ins2="urn:sobject.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header>
<wsdl:SessionHeader>
<wsdl:sessionId>REMOVED</wsdl:sessionId>
</wsdl:SessionHeader>
</env:Header>
<env:Body>
<ins0:describeSObjects>
<wsdl:object1>Action_Plans_Settings__c</wsdl:object1>
<wsdl:object2>QuoteLineSyncField__c</wsdl:object2>
</ins0:describeSObjects>
</env:Body>
</env:Envelope>
I know this isn't correct, but I'm having trouble figuring out from the wsdl alone what the final soap body would look like. I've browsed the salesforce forums and docs without much luck.
Here's the wsdl definition for this operation, perhaps some wsdl gurus can figure this out based on it:
<operation name="describeSObjects">
<documentation>Describe a number sObjects</documentation>
<input message="tns:describeSObjectsRequest"/>
<output message="tns:describeSObjectsResponse"/>
<fault message="tns:InvalidSObjectFault" name="InvalidSObjectFault"/>
<fault message="tns:UnexpectedErrorFault" name="UnexpectedErrorFault"/>
</operation>
<message name="describeSObjectsRequest">
<part element="tns:describeSObjects" name="parameters"/>
</message>
<element name="describeSObjects">
<complexType>
<sequence>
<element name="sObjectType" type="xsd:string" minOccurs='0' maxOccurs='100' />
</sequence>
</complexType>
</element>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:partner.soap.sforce.com">
<soapenv:Header>
<urn:SessionHeader>
<urn:sessionId>someSessionId</urn:sessionId>
</urn:SessionHeader>
</soapenv:Header>
<soapenv:Body>
<urn:describeSObjects>
<urn:sObjectType>Account</urn:sObjectType>
<urn:sObjectType>Contact</urn:sObjectType>
</urn:describeSObjects>
</soapenv:Body>
</soapenv:Envelope>