Can't send a soap request -Invalid API namespace- - php

I'm trying to send a soap request with simple curl call in a laravel application but i get the next error.
<faultcode>soap:Client</faultcode>
<faultstring>Invalid API namespace</faultstring>
This is the XML request
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Security SOAP-ENV:mustUnderstand="1">
<wsse:UsernameToken>
<wsse:Username>usename</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">randompass</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<soapenv:Body>
<requestMessage
xmlns="urn:schemas-cybersource-com:transaction-data-N.NN">
<merchantID>themerchantid</merchantID>
<merchantReferenceCode>the reference</merchantReferenceCode>
<billTo>
<firstName>Name</firstName>
<lastName></lastName>
<street1></street1>
<city></city>
<state></state>
<postalCode></postalCode>
<country></country>
<email>name#mail.com</email>
</billTo>
<item id="1">
<unitPrice>25</unitPrice>
<quantity>1</quantity>
</item>
<purchaseTotals>
<currency>EUR</currency>
</purchaseTotals>
<card>
<accountNumber>9898989898989898</accountNumber>
<expirationMonth>10</expirationMonth>
<expirationYear>20</expirationYear>
</card>
<ccAuthService run="true"/>
</requestMessage>
</soapenv:Body>
</soapenv:Envelope>
I don't know why I'am getting this error. What's wrong with the request?

Your namespace that is currently
xmlns="urn:schemas-cybersource-com:transaction-data-N.NN"
should be
xmlns="urn:schemas-cybersource-com:transaction-data-1.155"
You will also need to populate the billTo fields since they are usually required.

Related

PHP CURL - SoapException: Server did not recognize the value of HTTP Header SOAPAction

I am creating XML in PHP and and sending the request using CURL. I am getting back an error: SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://www.starstandards.org/webservices/2005/10/transport/operations/ProcessMessage.
My XML being sent with sensitive info x'd out:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tran="http://www.starstandards.org/webservices/2005/10/transport">
<soap:Header>
<wsse:Security soap:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>x</wsse:Username>
<wsse:Password>x</wsse:Password>
<wsu:Created>x</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
<tran:PayloadManifest>
<tran:manifest contentID="Content0" namespaceURI="?" element="?" relatedID="?" version="?"/>
</tran:PayloadManifest>
</soap:Header>
<soap:Body>
<tran:ProcessMessage>
<tran:payload>
<tran:content id="Content0">
<Search>
<Deal>
<Code>x</Code>
<Number>x</Number>
<Name>x</Name>
</Deal>
<SearchParms>
<LastName>Doe</LastName>
<FirstName>John</FirstName>
</SearchParms>
</Search>
</tran:content>
</tran:payload>
</tran:ProcessMessage>
</soap:Body>
</soap:Envelope>
And I am setting the SOAPAction header like this:
$headers = array('Content-type: text/xml', 'SOAPAction: "http://www.starstandards.org/webservices/2005/10/transport/operations/ProcessMessage"');
I've googled and searched SO and found a lot of questions with this error, but nothing that seemed to help me. Any ideas why I would be getting this error?

How to make a SOAP request using cURL in PHP (Drupal)

I have been trying to get a SOAP request to work within a custom module for Drupal 7. I am using cURL to make the request within a function. At the moment the page I am using says it us under site maintenance whenever I activate the function. Below is an extract of a function. My question is how I can get the value of the email provided by the SOAP response and place it in a PHP variable? Below is my option for using SimpleXML.
$xml = simplexml_load_string($response);
$namespace = 'http://exacttarget.com/wsdl/partnerAPI';
$soap = $xml->children($namespace);
$subscriber_email = $soap->Body->RetrieveResponseMsg->Results->Properties->Property[2]->Value;
This is the result for SOAP request on its own using SOAP UI that I am trying to parse:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soap:Header>
<wsa:Action>RetrieveResponse</wsa:Action>
<wsa:MessageID>[REMOVED]</wsa:MessageID>
<wsa:RelatesTo>[REMOVED]</wsa:RelatesTo>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsse:Security>
<wsu:Timestamp wsu:Id="Timestamp-715a4a7e-4657-48c7-8b01-612580d331ce">
<wsu:Created>2019-03-04T12:41:08Z</wsu:Created>
<wsu:Expires>2019-03-04T12:46:08Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</soap:Header>
<soap:Body>
<RetrieveResponseMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
<OverallStatus>OK</OverallStatus>
<RequestID>[REMOVED]</RequestID>
<Results xsi:type="DataExtensionObject">
<PartnerKey xsi:nil="true"/>
<ObjectID xsi:nil="true"/>
<Type>DataExtensionObject</Type>
<Properties>
<Property>
<Name>SubscriberID</Name>
<Value>[REMOVED]</Value>
</Property>
<Property>
<Name>FirstName</Name>
<Value>[REMOVED]</Value>
</Property>
<Property>
<Name>Email</Name>
<Value>[REMOVED]</Value>
</Property>
</Properties>
</Results>
</RetrieveResponseMsg>
</soap:Body>
</soap:Envelope>

SOAP Service: I have a sample request file XML but getting confused about the format

I'm working on integrating to a remote service running Apache Axis. I have been given a sample request file that looks like the following
<?xml version="1.0" encoding="UTF-8"?>
<request xmlns="http://api.somedomain.com/openSession" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="openSession.xsd">
<session key="xabc123092"/>
<user name="admin" password="secret"/>
</request>
I know SOAP requires "envelope and body" such that the request conforms with
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
....
</soapenv:Body>
</soapenv:Envelope>
Now I'm confused about the sample request file given to me. I have tried to craft the following SOAP request with some SOAPAction in the request header but to no avail
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:openSession>
<session key="xabc123092"/>
<user name="admin" password="secret"/>
</soapenv:openSession>
</soapenv:Body>
</soapenv:Envelope>
The above gives the following
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server.userException</faultcode>
<faultstring>org.xml.sax.SAXException: operation description is missing parameter description!</faultstring>
<detail>
<ns1:hostname
xmlns:ns1="http://xml.apache.org/axis/">api.somedomain.com
</ns1:hostname>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
Can someone tell me what I'm missing here?
Not sure if you are still facing this problem. It was missing request element along with the namespace in the soap request. Please try below:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<request xmlns="http://api.somedomain.com/openSession" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="openSession.xsd">
<session key="xabc123092"/>
<user name="admin" password="secret"/>
</request>
</soapenv:Body>
</soapenv:Envelope>

INVALID_TYPE when creating salesforce attachment

Bellow is the XML POST and Response i get from the sales force servers.
Im trying to add an attachment to an Account but i keep getting INVALID_TYPE.
Im using NuSoap instead of the SalesForce PHP library because the server i'm working on doesnt have the SOAP extension required.
I have no issue with going in and amending the library to make it work but i dont have a clue whats wrong with the XML to fix the issue. I get query information perfectly fine.
All help and advice appreciated!
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
<nu2113:SessionHeader xmlns:nu2113="urn:enterprise.soap.sforce.com">
<sessionId>00Di00000{---cutting out for privacy--}UrYmByvpO5yRWIK0Gmy</sessionId>
</nu2113:SessionHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<create xmlns="urn:enterprise.soap.sforce.com">
<sObject>
<type xsi:type="xsd:string">Attachment</type>
<fieldsToNull>
<elementName xsi:type="xsd:string">fieldsToNull</elementName>
<values xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:string[5]">
<item xsi:type="xsd:string">OwnerId</item>
<item xsi:type="xsd:string">IsPrivate</item>
<item xsi:type="xsd:string">IsPartnerShared</item>
<item xsi:type="xsd:string">ConnectionSentId</item>
<item xsi:type="xsd:string">BodyLength</item>
</values>
</fieldsToNull>
<Id xsi:nil="true"/>
<ParentId xsi:type="xsd:string">001i000000JG17b</ParentId>
<Name xsi:type="xsd:string">Test document</Name>
<Description xsi:type="xsd:string">Test upload from WIN form</Description>
<ContentType xsi:type="xsd:string">.pdf</ContentType>
<Body xsi:type="xsd:string">hello</Body>
</sObject>
</create>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
HTTP/1.1 100 Continue
HTTP/1.1 500 Server Error
Date: Mon, 13 Jan 2014 15:49:56 GMT
Content-Type: text/xml;charset=UTF-8
Content-Length: 676
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.enterprise.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>sf:INVALID_TYPE</faultcode>
<faultstring>INVALID_TYPE: Must send a concrete entity type.</faultstring>
<detail>
<sf:InvalidSObjectFault xsi:type="sf:InvalidSObjectFault">
<sf:exceptionCode>INVALID_TYPE</sf:exceptionCode>
<sf:exceptionMessage>Must send a concrete entity type.</sf:exceptionMessage>
<sf:row>-1</sf:row>
<sf:column>-1</sf:column>
</sf:InvalidSObjectFault>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
This line might be the problem:
<ContentType xsi:type="xsd:string">.pdf</ContentType>
that is not a valid content type. try this:
<ContentType xsi:type="xsd:string">application/pdf</ContentType>

How do I send an array in SOAP?

I have a PHP file, which sends SOAP request
$client = new SoapClient('http://xyz');
$client->call('example', array('param1'=>'value2')
I want to do this same request using SoapUI:
<soapenv:Envelope [..]>
<soapenv:Header/>
<soapenv:Body>
<urn:call soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<param1 xsi:type="xsd:string">example</param1>
<param2 xsi:type="xsd:anyType">
??
</param2>
</urn:call>
</soapenv:Body>
</soapenv:Envelope>
How do I encode the above example in XML?
it should be something like that:
<soapenv:Envelope [..]>
<soapenv:Header/>
<soapenv:Body>
<urn:call soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<param1 xsi:type="xsd:string">example</param1>
<param2 xsi:type="xsd:anyType">
<param1 xsi:type="xsd:string">value2</param1>
</param2>
</urn:call>
</soapenv:Body>
</soapenv:Envelope>
Use json_encode() and then send the array as a string representation.
In this case there is a nice PHP SOAP client function: $client->__getLastRequest()
It showed that, the request is built like this:
<param2 xsi:type="ns2:Map">
<item xsi:type="ns2:Map">
<key xsi:type="xsd:string">param1</key>
<value xsi:type="xsd:string">param2</value>
</item>
</param2>

Categories