Soap Response parsing using cypress - soap

<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body>
<m:GetPriceRespon`enter code here`se xmlns:m="https://www.w3schools.com/prices">
<m:Price>1.90</m:Price>
</m:GetPriceResponse>
</soap:Body>
</soap:Envelope>
I want to read "Price" from above XML , how to read this price using cypress and store it to a variable ? could any one help me with the sample cypress code ?

You can use a DOMParser to make a queryable document,
it('parses XML price', () => {
const xmlStr = `<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope/" soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body>
<m:GetPriceResponse xmlns:m="https://www.w3schools.com/prices">
<m:Price>1.90</m:Price>
</m:GetPriceResponse>
</soap:Body>
</soap:Envelope>`
const parser = new DOMParser();
const doc = parser.parseFromString(xmlStr, "application/xml");
const price = +doc.querySelector("Price").textContent // numeric value of text content
cy.wrap(price)
.as('price') // save for later
.should('eq', 1.90) // verify the value
});

You can do something like this:
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope/" soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body>
<m:GetPriceResponse xmlns:m="https://www.w3schools.com/prices">
<m:Price>1.90</m:Price>
</m:GetPriceResponse>
</soap:Body>
</soap:Envelope>`
cy.wrap(Cypress.$(xml))
.then((xml) => xml.filter('soap:Body').find('m:Price').text())
.as('price')
cy.get('#price').then((price) => {
//Access price here
})

Related

MarkAsJunk operation Error Code 9020. Getting "An internal server error occurred. The operation failed."

I am trying to use the MarkAsJunk operation using only SOAP requests with Office.context.mailbox.makeEwsRequestAsync. For this purpose I also use the easyEWS module which is a wrapper over OfficeJS. The code I'm using to send the SOAP looks like this:
this.markAsJunk = function (itemId) {
var soap = '<m:MarkAsJunk IsJunk="true" MoveItem="true"' +
'
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
' <ItemIds>' +
' <t:ItemId Id="' + itemId + '"/>' +
' </ItemIds>' +
'</m:MarkAsJunk>';
soap = getSoapHeader(soap);
asyncEws(soap, function (data) { });
};
The SOAP which I'm sending looks like this:
<?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:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />
</soap:Header>
<soap:Body>
<m:MarkAsJunk IsJunk="true" MoveItem="true"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<ItemIds>
<t:ItemId Id="AAMkADg2OGZmNDkzLWVjNDYtNGI2MC1iMGI3LWE3YmEzMDk5MThiNABGAAAAAAC3FQIsRYg6SZwlyqfCFdA0BwBTNDtA08+GRo/QPlH0XaGpAAAAAAEMAABTNDtA08+GRo/QPlH0XaGpAADEMDCVAAA="/>
</ItemIds>
</m:MarkAsJunk>
</soap:Body>
</soap:Envelope>
ItemIds is present in namespace xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages", so you need to use "m:ItemIds".
Please refer the tutorial here for the SOAP request format.

Server was unable to process request.,Object reference not set to an instance of an object. SOAP API

want to push data through soap API, code provided in API documentation is given below. i am getting error. error i am getting. let me know where i am wrong, thanks in advance.
url
<?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>
<PushData xmlns="RBSS">
<RBSS>
<Lead_Response_DateTime>20-05-2016 10:25:16</Lead_Response_DateTime>
<Lead_Push_DateTime>20-05-2016 10:25:16</Lead_Push_DateTime>
<Lead_Recd_DataTime>20-05-2016 10:25:16</Lead_Recd_DataTime>
<FirstName>test</FirstName>
<Phone1>9876543215</Phone1>
<Phone2>9876543215</Phone2>
<Email>amrit#gmail.com</Email>
<DOB>20-05-2016</DOB>
<Age>26</Age>
<Child_DOB>20-05-2002</Child_DOB>
<Child_Age>4</Child_Age>
<Pincode>400052</Pincode>
<City_Name>Mumbai</City_Name>
<Address>2, Akshardham…..</Address>
<Annual_Income>1000000</Annual_Income>
<Annual_Income_Slab>10</Annual_Income_Slab>
<SMS_Keyword>0</SMS_Keyword>
<Short_Code></Short_Code>
<Circle_Operator></Circle_Operator>
<Sum_Assured></Sum_Assured>
<Premium_Pitched></Premium_Pitched>
<Company_Name>WRS</Company_Name>
<Website_Name>Bima Deals.com</Website_Name>
<UTN_Source>FaceBook</UTN_Source>
<Lead_Source></Lead_Source>
<Type_Of_Lead></Type_Of_Lead>
<Verification_Type></Verification_Type>
<Product_Name></Product_Name>
<Product_Category></Product_Category>
<No_of_Companies></No_of_Companies>
<Names_of_Companied></Names_of_Companied>
<SMS_Message_Sent></SMS_Message_Sent>
<Customer__Remarks></Customer__Remarks>
<FLAG></FLAG>
<Lead_Type>INCOMING_WEB</Lead_Type>
<Channel_Type>INTERNET</Channel_Type>
<Mode_Type>PREFIXED_APPOINTMENT</Mode_Type>
<Source_Type>BIMADEALS</Source_Type>
<Campaign_Type>APR_16</Campaign_Type>
<Opportunity_Id>123456</Opportunity_Id>
<PROSPECT_ID></PROSPECT_ID>
<Title>MR</Title>
<UID></UID>
<LastName>Lastname</LastName>
<Gender>Male</Gender>
<MaritalStatus></MaritalStatus>
<MobileNo>9865856325</MobileNo>
<AgeAtRetirement></AgeAtRetirement>
<VendorCSE_Name></VendorCSE_Name>
<TermOfPlan></TermOfPlan>
<Smoker_NonSmoker></Smoker_NonSmoker>
<VendorCode></VendorCode>
<MeetingDate></MeetingDate>
<MeetingTime></MeetingTime>
<City_ID>67</City_ID>
<ID>123</ID>
<CallcenterID></CallcenterID>
<ADDLInfo1></ADDLInfo1>
<ADDLInfo2></ADDLInfo2>
</RBSS>
</PushData>
</soap:Body>
</soap:Envelope>

set some property for array type element in node soap

i get xml like this when using node-soap in my app :
<?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:impl="http://magfa.com/soap/SOAPSmsQueue"
xmlns:intf="http://magfa.com/soap/SOAPSmsQueue"
xmlns:tns1="urn:SOAPSmsQueue">
<soap:Header></soap:Header>
<soap:Body>
<impl:enqueue>
<domain>magfa</domain>
<messageBodies>
<messageBodies>hi</messageBodies>
</messageBodies>
<recipientNumbers>
<recipientNumbers>989187004197</recipientNumbers>
</recipientNumbers>
<senderNumbers>
<senderNumbers>98300079368</senderNumbers>
</senderNumbers>
</impl:enqueue>
</soap:Body>
</soap:Envelope>
so i want's to add some property to array elements.
some property like this : soapenc:arrayType="soapenc:string[1]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
and create array element like this :
<messageBodies soapenc:arrayType="soapenc:string[1]" xsi:type="soapenc:Array"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" >
<messageBodies>hi</messageBodies>
</messageBodies>
finally i want my xml are look like this :
<?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:impl="http://magfa.com/soap/SOAPSmsQueue"
xmlns:intf="http://magfa.com/soap/SOAPSmsQueue"
xmlns:tns1="urn:SOAPSmsQueue">
<soap:Header></soap:Header>
<soap:Body>
<impl:enqueue>
<domain>magfa</domain>
<messageBodies soapenc:arrayType="soapenc:string[1]" xsi:type="soapenc:Array"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" >
<messageBodies>hi</messageBodies>
</messageBodies>
<recipientNumbers soapenc:arrayType="soapenc:string[1]" xsi:type="soapenc:Array"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" >
<recipientNumbers>989381028800</recipientNumbers>
</recipientNumbers>
<senderNumbers soapenc:arrayType="soapenc:string[1]" xsi:type="soapenc:Array"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<senderNumbers >98300079368</senderNumbers>
</senderNumbers>
</impl:enqueue>
</soap:Body>
</soap:Envelope>
this description just for silly validation in stackoverflow for this question is looks like your post is mostly code ...
Try this:
<messageBodies soap-enc:arrayType="xsd:string[1]" xsi:type="soap-enc:Array"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" >
<messageBodies>hi</messageBodies>
</messageBodies>
soap-enc instead of soapenc

Schema validation error when using Restriction in EWS FindItem request

I'm trying to find items in inbox with ItemClass = IPM.Note
<?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://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:wsi="http://ws-i.org/schemas/conformanceClaim/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010_SP2"></t:RequestServerVersion>
</soap:Header>
<soap:Body>
<FindItem Traversal="Shallow" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<ItemShape>
<t:BaseShape xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">IdOnly</t:BaseShape>
<t:AdditionalProperties xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<t:FieldURI FieldURI="item:ItemClass"></t:FieldURI>
</t:AdditionalProperties>
</ItemShape>
<IndexedPageItemView MaxEntriesReturned="50" Offset="0" BasePoint="Beginning"></IndexedPageItemView>
<Restriction>
<IsEqualTo>
<FieldURI FieldURI="item:ItemClass"></FieldURI>
<FieldURIOrConstant>
<Constant Value="IPM.Note"></Constant>
</FieldURIOrConstant>
</IsEqualTo>
</Restriction>
<ParentFolderIds>
<t:DistinguishedFolderId Id="inbox" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"></t:DistinguishedFolderId>
</ParentFolderIds>
</FindItem>
</soap:Body>
</soap:Envelope>
Resulting in this SchemaValidationError
a:ErrorSchemaValidation: The request failed schema validation: The element 'Restriction' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages' has invalid child element 'IsEqualTo' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages'. List of possible elements expected: 'SearchExpression' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'. [undefined] Error: a:ErrorSchemaValidation: The request failed schema validation: The element 'Restriction' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages' has invalid child element 'IsEqualTo' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages'. List of possible elements expected: 'SearchExpression' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'.
To my understaning, SearchExpression is an abstract type that can be replaced with IsEqualTo, among other types.
What am I missing here?
Some of these elements are in the 'types' namespace so they need the t: prefix
<Restriction>
<t:IsEqualTo>
<t:FieldURI FieldURI="item:ItemClass"></t:FieldURI>
<t:FieldURIOrConstant>
<t:Constant Value="IPM.Note"></t:Constant>
</t:FieldURIOrConstant>
</t:IsEqualTo>
</Restriction>

Querying Exchange Web Services fails with 400 Bad Request

I am trying to get some information from a specific calendar using EWS and Powershell.
I have a powershell function that I use to query EWS
Function EWSSoapRequest
{
param (
$soapRequest,
$exchangeServerAddress
)
# Create the request
$webRequest = [System.Net.WebRequest]::Create($exchangeServerAddress)
$webRequest.ContentType = "text/xml"
$webRequest.Headers.Add("Translate", "F")
$webRequest.Method = "Post"
$webRequest.Credentials = $credentials
# Setup the soap request to send to the server
$content = [System.Text.Encoding]::UTF8.GetBytes($soapRequest)
$webRequest.ContentLength = $content.Length
$requestStream = $webRequest.GetRequestStream()
$requestStream.Write($content, 0, $content.Length)
$requestStream.Close()
# Get the xml response from the server
$webResponse = $webRequest.GetResponse()
$responseStream = $webResponse.GetResponseStream()
$responseXml = [xml](new-object System.IO.StreamReader $responseStream).ReadToEnd()
$responseStream.Close()
$webResponse.Close()
$responseXml
}
I can get the list of calendar items just fine, using this XML:
$soapRequestOverview = #'
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010_SP2" />
<t:ExchangeImpersonation>
<t:ConnectingSID>
<t:SmtpAddress>user#domain.dk</t:SmtpAddress>
</t:ConnectingSID>
</t:ExchangeImpersonation>
</soap:Header>
<soap:Body>
<FindItem Traversal="Shallow" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<ItemShape>
<t:BaseShape>IdOnly</t:BaseShape>
<t:AdditionalProperties>
<t:FieldURI FieldURI="calendar:Start"/>
<t:FieldURI FieldURI="calendar:End"/>
<t:FieldURI FieldURI="item:Subject"/>
</t:AdditionalProperties>
</ItemShape>
<CalendarView MaxEntriesReturned="100" StartDate="{0}" EndDate="{1}"/>
<ParentFolderIds>
<t:DistinguishedFolderId Id="calendar"/>
</ParentFolderIds>
</FindItem>
</soap:Body>
</soap:Envelope>
'#
That gives me a list of entries in the given calendar (I replace the state and end date before calling the web service function. Then from the list of calendar items returned I use the ItemID property to try and query detailed information like location etc. But it is here I run into problems.
I use this XML to make the query and use the EWSSoapRequest function as before, but I keep getting 400 Bad request back. If I copy/paste the xml into SoapUI then I get a response just fine with the expected data.
$SoapRequestDetail = #'
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010_SP2" />
<t:ExchangeImpersonation>
<t:ConnectingSID>
<t:SmtpAddress>user#domain.dk</t:SmtpAddress>
</t:ConnectingSID>
</t:ExchangeImpersonation>
</soap:Header>
<soap:Body>
<m:GetItem>
<m:ItemShape>
<t:BaseShape>AllProperties</t:BaseShape>
</m:ItemShape>
<m:ItemIds>
<t:ItemId Id="AAMkADU3MzNlNjQxLTA3NDYtNDA4MS1hMmJhLTg5MmUxOTM2NzI3YwBGAAAAAABifraNBbAgRq+5NEGUOyNbBwBOxvhv/eH/R6wHrO/Hc4RhAAABnAHkAAChTN/6w47WS4YxX5iYDfnHAABfYm2zAAA=" />
</m:ItemIds>
</m:GetItem>
</soap:Body>
</soap:Envelope>
'#
Is it just me overlooking something obvious ?
Try using this XML instead
<?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/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010_SP2" />
<t:ExchangeImpersonation>
<t:ConnectingSID>
<t:SmtpAddress>user#domain.com</t:SmtpAddress>
</t:ConnectingSID>
</t:ExchangeImpersonation>
</soap:Header>
<soap:Body>
<GetItem
xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<ItemShape>
<t:BaseShape>AllProperties</t:BaseShape>
</ItemShape>
<ItemIds>
<t:ItemId Id="AAAlAF" />
</ItemIds>
</GetItem>
</soap:Body>
</soap:Envelope>
Cheers
Glen