My SOAP post response is not returning 200 in Python, but it works in Postman - python-3.x

So I ran my post method for SOAP in Postman and received 200, the response headers had text/xml; charset=utf-8 for Content type. My Headers in Postman excluding the default values are
ClientID 700,
SOAPAction urn,
Content-Type text/xml
url = www.xyz.com.svc
The SOAP raw XML used to run in Postman.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.xsd" xmlns:wsu="http://docs.oa.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-1234">
<wsse:Username>E</wsse:Username>
<wsse:Password Type="http://docs.o-username-token-profile-1.0#PasswordText">abcd</wsse:Password>
<wsse:Nonce EncodingType="http://docs.o.security-1.0#Base64Binary">happy</wsse:Nonce>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<ConfirmAppointment xmlns="urn:CompanyNameServices" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--string occurs:0,1-->
<PatID xsi:nil="false">A1</PatID>
<!--string occurs:0,1-->
<PIDType xsi:nil="false">B</PIDType>
<!--string occurs:0,1-->
<MyCID xsi:nil="false">1</MyCID>
<!--string occurs:0,1-->
<MIDType xsi:nil="false">External</MyIDType>
<!--string occurs:0,1-->
<AppCID xsi:nil="false">1</AppCID>
</ConfirmAppointment>
</soapenv:Body>
</soapenv:Envelope>
I am trying to run this using Python requests.post, here is my code.
soap_body = '''
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.xsd" xmlns:wsu="http://docs.oa.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-1234">
<wsse:Username>E</wsse:Username>
<wsse:Password Type="http://docs.o-username-token-profile-1.0#PasswordText">abcd</wsse:Password>
<wsse:Nonce EncodingType="http://docs.o.security-1.0#Base64Binary">happy</wsse:Nonce>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<ConfirmAppointment xmlns="urn:CompanyNameServices" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--string occurs:0,1-->
<PatID xsi:nil="false">A1</PatID>
<!--string occurs:0,1-->
<PIDType xsi:nil="false">B</PIDType>
<!--string occurs:0,1-->
<MyCID xsi:nil="false">1</MyCID>
<!--string occurs:0,1-->
<MIDType xsi:nil="false">External</MyIDType>
<!--string occurs:0,1-->
<AppCID xsi:nil="false">1</AppCID>
</ConfirmAppointment>
</soapenv:Body>
</soapenv:Envelope>'''
headers = {
'ClientID': '700',
'SOAPAction': 'urn',
'Content-Type': 'text/xml'
}
response = requests.post(url=url, data=soap_body, headers=headers)
print(response)
My output:
<Response [500]>
If I add <?xml version="1.0" encoding="UTF-8"?> to the beginning of my body, my output:
<Response [400]>
What am I doing wrong here?

Here are 2 sample SOAP requests. See if they work for you.
import requests
url = "https://httpbin.org/post"
headers = {"content-type" : "application/soap+xml"}
body = """
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="https://httpbin.org/post">
<soapenv:Header/>
<soapenv:Body/>
</soapenv:Envelope>
""".strip()
response = requests.post(url, data = body, headers = headers)
print(response.content.decode("utf-8") +'\n')
###########################################
url = "https://www.dataaccess.com/webservicesserver/NumberConversion.wso"
headers = {"content-type" : "application/soap+xml"}
body = """
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<NumberToWords xmlns="http://www.dataaccess.com/webservicesserver/">
<ubiNum>500</ubiNum>
</NumberToWords>
</soap:Body>
</soap:Envelope>
""".strip()
response = requests.post(url, data = body, headers = headers)
print(response.content.decode("utf-8") +'\n')

Related

PYTHON REQUESTS ERROR: ('Connection aborted.', OSError("(10054, 'WSAECONNRESET')"))

I am trying to get data from a web service,working with soap. Until now, I was able to get successfull responses but now my code throws this error. Any ideas on why a working code a day before throws this error now?
Note that this is not a public API, your IP needed to be in whitelist to retrieve data.
edit for code:
import requests
headers = {'x-ibm-client-id': "MY KEY",
'content-type': 'application/soap+xml',
'accept':'application/xml'}
url="https://api.epias.com.tr/epias/exchange/electricity/balancingMarket"
login="""<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header>
<wsse:Security 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>string</wsse:Username>
<wsse:Password>string</wsse:Password>
<wsse:Nonce EncodingType="string">string</wsse:Nonce>
<wsu:Created>string</wsu:Created>
</wsse:UsernameToken>
<wsu:Timestamp wsu:Id="string">
<wsu:Created>string</wsu:Created>
<wsu:Expires>string</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<dgp:login xmlns:dgp="http://ws.dgpys.deloitte.com"><!-- mandatory -->
<loginMessage>
<Password v="MYPASSWORD"></Password>
<UserName v="MYUSERNAME"></UserName>
</loginMessage>
</dgp:login>
</soapenv:Body>
"""
s=requests.Session()
s.get(url)
res=s.post(url,data=login,headers=headers)
keep the above code ,you should handle the proxy setting.
import urlparse,urllib2
s=requests.Session()
opener=urllib2.build_opener()
if proxy:
proxy_params={urlparse.urlparse(url).scheme : proxy}
opener.add_handler(urllib2.ProxyHandler(proxy_params))
s.get(url)
res=s.post(url,data=login,headers=headers)
if your code used to work, the site might have blocked your IP or don't like your header settings.

how to make http request from xml soap?

I am implementing one of the payment gateway(Advance cash) in my application.Here is the link :
Adv documentaion
According to its documentation I have to made request for transaction. But the request mention in it in xml format.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:wsm="http://wsm.advcash/">
<soapenv:Header/>
<soapenv:Body>
<wsm:sendMoney>
<arg0>
<apiName>api_name</apiName>
<authenticationToken>token</authenticationToken>
<accountEmail>name#example.com</accountEmail>
</arg0>
<arg1>
<amount>1.00</amount>
<currency>USD</currency>
<email>name#example.com</email>
<note>Some note</note>
<savePaymentTemplate>false</savePaymentTemplate>
</arg1>
</wsm:sendMoney>
</soapenv:Body>
</soapenv:Envelope>
I think it is kind of soap request,I want to know how to request this and what are the parameters I have to send using my node js application using "request" npm module.Please help.
You should use node-soap package. There is a request option which override the request module.
I made a sample, take a look
service.ts:
const service = {
UserService: {
ServicePort: {
getUserById(args) {
const user = { id: args.id, name: faker.name.findName(), email: faker.internet.email() };
return user;
}
}
}
};
service.wsdl:
<definitions name="Service" targetNamespace="http://localhost:8001/get-started/service.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://localhost:8001/get-started/service.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<message name="GetUserByIdInput">
<part name="id" type="xsd:string"></part>
</message>
<message name="GetUserByIdOutput">
<part name="id" type="xsd:string"></part>
<part name="name" type="xsd:string"></part>
<part name="email" type="xsd:string"></part>
</message>
<portType name="ServicePortType">
<operation name="getUserById">
<input message="tns:GetUserByIdInput"/>
<output message="tns:GetUserByIdOutput"></output>
</operation>
</portType>
<binding name="ServiceSoapBinding" type="tns:ServicePortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getUserById">
<soap:operation soapAction="getUserById"/>
<input message="tns:GetUserByIdInput">
<soap:body parts="id" use="literal"/>
</input>
<output message="tns:GetUserByIdOutput">
<soap:body parts="id" use="literal"/>
<soap:body parts="name" use="literal"/>
<soap:body parts="email" use="literal"/>
</output>
</operation>
</binding>
<service name="UserService">
<documentation>Get started service</documentation>
<port name="ServicePort" binding="tns:ServiceSoapBinding">
<soap:address location="http://localhost:8001/get-started"/>
</port>
</service>
</definitions>
request.xml:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tns="http://localhost:8001/get-started/service.wsdl">
<soap:Body>
<tns:getUserById>
<id>8104d3c3-de13-432f-b4a0-a62f84f6206a</id>
</tns:getUserById>
</soap:Body>
</soap:Envelope>
server.spec.ts:
it('should get correct result using http request and static xml', async (done: jest.DoneCallback) => {
const xml = fs.readFileSync(path.resolve(__dirname, './static-xml.xml'), 'utf8');
const uuid = '8104d3c3-de13-432f-b4a0-a62f84f6206a';
const options = {
url,
method: 'POST',
body: xml,
headers: {
'Content-Type': 'text/xml;charset=utf-8',
'Accept-Encoding': 'gzip,deflate',
'Content-Length': xml.length
}
};
const rawXml = await request(options);
parser.parseString(rawXml, (err, actualValue) => {
if (err) {
done(err);
}
console.log('actualValue: ', JSON.stringify(actualValue));
expect(actualValue['soap:Envelope']['soap:Body']['tns:getUserByIdResponse']['tns:id']).toBe(uuid);
done();
});
});
The result:
actualValue: {"soap:Envelope":{"$":{"xmlns:soap":"http://schemas.xmlsoap.org/soap/envelope/","xmlns:tns":"http://localhost:8001/get-started/service.wsdl"},"soap:Body":{"tns:getUserByIdResponse":{"tns:id":"bf0f6172-2f53-4b33-94c8-9ff9ed8fd431","tns:name":"Theo Leannon","tns:email":"Brent.Berge#hotmail.com"}}}}
Here is the demo: https://github.com/mrdulin/nodejs-soap/tree/master/src/get-started

NetSuite API Insert Phone Call

I've successfully created a phone call record in netsuite and related it to a company record. However, I haven't been able to relate a phone call to a contact record. Where am I going wrong?
Error
{
"message": "Invalid contact reference key 43780 for company <NULL>.",
"code": "INVALID_KEY_OR_REF"
}
Note: Internal ID 4370 is a contact in netsuite
Envelope with variables
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<applicationInfo xmlns="urn:messages_2015_2.platform.webservices.netsuite.com">
<applicationId>_appId_</applicationId>
</applicationInfo>
<preferences xmlns="urn:messages_2015_2.platform.webservices.netsuite.com">
<warningAsError>false</warningAsError>
</preferences>
</soap:Header>
<soap:Body>
<update xmlns="urn:messages_2015_2.platform.webservices.netsuite.com">
<record internalId="_callId_" xmlns:q1="urn:scheduling_2015_2.activities.webservices.netsuite.com" xsi:type="q1:PhoneCall">
<q1:message>_description_</q1:message>
<q1:title>_name_</q1:title>
<q1:assigned internalId="_user_" type="contact"/>
<q1:contact internalId="_customer_" type="contact"/>
<q1:phone>_number_</q1:phone>
<q1:startDate>_startDate_</q1:startDate>
<q1:endDate>_endDate_</q1:endDate>
<q1:timedEvent>true</q1:timedEvent>
</record>
</update>
</soap:Body>
</soap:Envelope>

SharePoint - SOAP Request To Web Services Returns List Of Operations

I have a VB script that is supposed to grab a specific list item from SharePoint 2013 via web services.
Relevant code:
Dim response, request, colItem, objItem
Dim fileSystem: Set fileSystem = CreateObject("Scripting.FileSystemObject")
request = "<?xml version='1.0' encoding='utf-8'?>" & _
"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" & _
" <soap:Body>" & _
" <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>" & _
" <listName>{FC3E18D6-33E5-4032-BE4B-F0F92F6F18BA}</listName>" + _
" <viewName>{2861DF9F-11F8-4E4B-A318-D4D37C1C5169}</viewName>" + _
" <query></query>" & _
" </GetListItems>" & _
" </soap:Body>" & _
"</soap:Envelope>"
http.open "POST", "http://<redacted>/_vti_bin/Lists.asmx", False
http.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
http.setRequestHeader "Content-Length", Len(request)
http.setRequestHeader "SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetListItems"
http.send request
However, it is just returning the same page that I see if I navigate directly to .../_vti_bin/Lists.asmx, which is the list of supported operations. If I click on "GetListItems", the example XML it provides looks like what I have in the VB script, except for a few parameters which I believe are optional:
POST /_vti_bin/Lists.asmx HTTP/1.1
Host: <redacted>
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/GetListItems"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>string</listName>
<viewName>string</viewName>
<query>string</query>
<viewFields>string</viewFields>
<rowLimit>string</rowLimit>
<queryOptions>string</queryOptions>
<webID>string</webID>
</GetListItems>
</soap:Body>
</soap:Envelope>
I have Googled around and been unable to find what I am doing wrong.
Thanks
Instead of GUID try using the regular names of the list and views for the listName and viewName XML elements.
<GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>My List</listName>
<viewName>All Items</viewName>
</GetListItems>
Here's a sample code I used on my SP 2013 site with jQuery.
$.ajax({
type: "POST",
contentType: "text/xml; charset=utf-8",
url: "https://site/_vti_bin/Lists.asmx",
data: '<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/"> <listName>My Test Cases</listName> </GetListItems> </soap:Body> </soap:Envelope>',
dataType: "xml",
success: function (msg) {
console.log(msg);
},
error: function (data, status, error) {
console.log('error');
}
});

Setting Flag for an Email in ActiveSync

Trying to set status Flag for an email using ActiveSync. Below is my request. I receive status 6. What's wrong with my request?
Request
<Sync xmlns="AirSync:" xmlns:email="Email:" xmlns:tasks="Tasks:" >
<Collections>
<Collection>
<SyncKey>648263900</SyncKey>
<CollectionId>11</CollectionId>
<GetChanges>0</GetChanges>
<Commands>
<Change>
<ServerId>11:2</ServerId>
<ApplicationData>
<email:Flag>
<email:Status>1</email:Status>
<email:FlagType>Follow Up</email:FlagType>
<tasks:StartDate>113-04-23T05:30:00.000Z</tasks:StartDate>
<tasks:UTCStartDate>113-04-23T05:30:00.000Z</tasks:UTCStartDate>
<tasks:DueDate>113-04-26T05:30:00.000Z</tasks:DueDate>
<tasks:UTCDueDate>113-04-26T05:30:00.000Z</tasks:UTCDueDate>
</email:Flag>
</ApplicationData>
</Change>
</Commands>
</Collection>
</Collections>
Response I receive
<?xml version="1.0"?>
<!DOCTYPE ActiveSync PUBLIC "-//MICROSOFT//DTD ActiveSync//EN" "http://www.microsoft.com/">
<Sync xmlns="AirSync:">
<Collections>
<Collection>
<SyncKey>648263900</SyncKey>
<CollectionId>11</CollectionId>
<Status>1</Status>
<Responses>
<Change>
<ServerId>11:2</ServerId>
<Status>6</Status>
</Change>
</Responses>
</Collection>
</Collections>
</Sync>
Change email:FlagType from Follow Up to for Follow Up.
And add </Sync> in the end.
Try:
<?xml version="1.0" encoding="utf-8"?>
<Sync xmlns="AirSync:" xmlns:email="Email:" xmlns:tasks="Tasks:" >
<Collections>
<Collection>
<SyncKey>648263900</SyncKey>
<CollectionId>11</CollectionId>
<GetChanges>0</GetChanges>
<Commands>
<Change>
<ServerId>11:2</ServerId>
<ApplicationData>
<email:Flag>
<email:Status>1</email:Status>
<email:FlagType>for Follow Up</email:FlagType>
<tasks:StartDate>113-04-23T05:30:00.000Z</tasks:StartDate>
<tasks:UTCStartDate>113-04-23T05:30:00.000Z</tasks:UTCStartDate>
<tasks:DueDate>113-04-26T05:30:00.000Z</tasks:DueDate>
<tasks:UTCDueDate>113-04-26T05:30:00.000Z</tasks:UTCDueDate>
</email:Flag>
</ApplicationData>
</Change>
</Commands>
</Collection>
</Collections>
</Sync>
See more: MS-ASEMAIL

Resources