I have this query which fails on this extract value
EXTRACTVALUE(xmltype(REQUEST), '/soapenv:Envelope/soapenv:Body/ns2:getCustomerRequestRetrieve/ns2:requestHeader/ns5:referenceID', 'xmlns:soapenv:http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns8="ca/bell/oms/autotype/customerrequestretrieve" xmlns:ns2="ca/bell/oms/autotype/customerrequestretrieve"') RequestReferenceID
Somewhere i am setting the wrong path. can you let me know where i am making a error
The actual XML is
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns2:getCustomerRequestRetrieve xmlns = "ca/bell/oms/autotype/omscommonresponse"
xmlns:ns5 = "sa/cell/oms/autotype/omscommonrequest"
xmlns:ns2 = "sa/cell/oms/autotype/customerrequestretrieve"
xmlns:ns3 = "sa/cell/oms/autotype/omscommon"
xmlns:ns4 = "sa/cell/oms/customerprofile">
<ns2:requestHeader>
<ns5:customerInteractionType>CustomerNotification</ns5:customerInteractionType>
<ns5:serviceRequestUserId>null</ns5:serviceRequestUserId>
<ns5:serviceConsumer>khg</ns5:serviceConsumer>
<ns5:serviceRequestTimestamp>2019-02-05T03:50:12.000-05:00</ns5:serviceRequestTimestamp>
<ns5:language>English</ns5:language>
<ns5:referenceID>Tjutrf7T78H4</ns5:referenceID>
<ns5:transactionIdentifier>eed7ffe0-da22-498f-9913-c2279d1549356612606</ns5:transactionIdentifier>
</ns2:requestHeader>
<ns2:searchCriteria>
<ns2:requestIdentifier>
<ns2:orderNumber>TTjutrf7T8H4</ns2:orderNumber>
</ns2:requestIdentifier>
</ns2:searchCriteria>
<ns2:filterCriteria>
<ns2:fullOrderDetail>ContactOnly</ns2:fullOrderDetail>
</ns2:filterCriteria>
</ns2:getCustomerRequestRetrieve>
</soapenv:Body>
</soapenv:Envelope>
enter code here
You have mistakes in namespaces declaration.
EXTRACTVALUE(REQUEST, '/soapenv:Envelope/soapenv:Body/ns2:getCustomerRequestRetrieve/ns2:requestHeader/ns5:referenceID'
,'xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns2="sa/cell/oms/autotype/customerrequestretrieve"
xmlns:ns5="sa/cell/oms/autotype/omscommonrequest"
') RequestReferenceID
Moreover EXTRACTVALUE function is deprecated. Replacemnet for it is xmlquery,xmltable.
select xmlcast(xmlquery('declare namespace soapenv="http://schemas.xmlsoap.org/soap/envelope/";
declare namespace ns2="sa/cell/oms/autotype/customerrequestretrieve";
declare namespace ns5="sa/cell/oms/autotype/omscommonrequest";
/soapenv:Envelope/soapenv:Body/ns2:getCustomerRequestRetrieve/ns2:requestHeader/ns5:referenceID/text()' passing xmltype(request) returning content) as varchar2(100)) from ....;
Related
I'm making an XML API call in Postman and I get the following response:
<response>
<result>
<system>YYY:XXXXXXXXX</system>
</result>
</response>
I created a variable from the content in "system", but I need to remove the "YYY:" from the front. Here is how I created the variable:
var response = xml2Json(responseBody);
var uuid = response["response"]["result"]["system"];
pm.collectionVariables.set("uuid", uuid);
If that could be formatted to remove any possible other characters before the colon - ex: "CCC:" or "ABC:" or "VAR1:" - that would be a bonus, but hard-coding this to remove exactly "YYY:" would solve the current problem.
You could do this, split String by character ":"
let text = "YYY:XXXXXXXXX";
console.log(text.split(":")[1]);
Apply to your code:
var response = xml2Json(responseBody);
var uuid = response["response"]["result"]["system"];
pm.collectionVariables.set("uuid", uuid.split(":")[1]);
Result:
This question already has an answer here:
Karate assert - I'm trying to extract a value from HTML
(1 answer)
Closed 1 year ago.
I am getting response as below:
How to extract value of attribute xmlns as "https://www.w3schools.com/xml/"?
def response =
"""
<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">
soap:Body
37.7777777777778
</soap:Body>
</soap:Envelope>
"""
Sometimes it is better to convert to JSON. Try this example:
* def response =
"""
<soap:Envelope xmlns:soap="schemas.xmlsoap.org/soap/envelope" xmlns:xsi="w3.org/2001/XMLSchema-instance" xmlns:xsd="w3.org/2001/XMLSchema"> <soap:Body> <FahrenheitToCelsiusResponse xmlns="w3schools.com/xml"> <FahrenheitToCelsiusResult>37.7777777777778</FahrenheitToCelsiusResult> </FahrenheitToCelsiusResponse> </soap:Body> </soap:Envelope>
"""
* json response = response
* def ns = response['soap:Envelope']['_']['soap:Body'].FahrenheitToCelsiusResponse['#'].xmlns
* match ns == 'w3schools.com/xml'
Now you will be able to get any attribute you want.
Also read this: https://github.com/intuit/karate#print - especially the part about internally XML being JSON so if you don't print correctly, you won't see what you want.
Using response As WebResponse = request.GetResponse()
Using rd As New StreamReader(response.GetResponseStream())
Dim soapResult As String = rd.ReadToEnd()
SerializeCollection(soapResult)
the soapResult generate the following :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<createShipmentResponse xmlns="http://www.royalmailgroup.com/api/ship/V2">
<integrationHeader>
<dateTime xmlns="http://www.royalmailgroup.com/integration/core/V1">2016-03-23T06:55:32</dateTime>
<version xmlns="http://www.royalmailgroup.com/integration/core/V1">2</version>
<identification xmlns="http://www.royalmailgroup.com/integration/core/V1">
<applicationId>RMG-API-G-01</applicationId>
<transactionId>730222611</transactionId>
</identification>
</integrationHeader>
<integrationFooter>
<errors xmlns="http://www.royalmailgroup.com/integration/core/V1">
<error>
<errorCode>E1105</errorCode>
<errorDescription>The countryCode specified is not valid</errorDescription>
</error>
<error>
<errorCode>E1001</errorCode>
<errorDescription>Postcode AA9 0AA invalid</errorDescription>
</error>
</errors>
<warnings xmlns="http://www.royalmailgroup.com/integration/core/V1">
<warning>
<warningCode>W0036</warningCode>
<warningDescription>E-mail option not selected so e-mail address will be ignored</warningDescription>
</warning>
<warning>
<warningCode>W0035</warningCode>
<warningDescription>SMS option not selected so Telephone Number will be ignored</warningDescription>
</warning>
</warnings>
</integrationFooter>
</createShipmentResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
i am using this method to serialize this response :
Private Sub SerializeCollection(filename As String)
Dim Emps As createShipmentResponse = New createShipmentResponse()
' Note that only the collection is serialized -- not the
' CollectionName or any other public property of the class.
Dim x As XmlSerializer = New XmlSerializer(GetType(createShipmentResponse))
Dim writer As TextWriter = New StreamWriter(filename)
x.Serialize(writer, Emps)
writer.Close()
End Sub
but i am having this error : Illegal characters in path
what does that mean ? and how can i fix this ?
Your SerializeCollection() method expects a file path to serialize to a file. You're currently passing the contents of your response which is why it doesn't work.
If you haven't written the method yourself I think you've not found completely what you're looking for.
This is an example of how the method should be called:
SerializeCollection("C:\Users\Vincent\Desktop\Hello.bin") 'The extension doesn't need to be '.bin', but it's an example.
The method has currently no way of getting your response, for that you should add a second parameter.
As I'm not familiar with Soap serialization I'm afraid I cannot help you further.
So, for the Intuit IPP Rest API,
Say if i want to query a customer who's name is ABC, i can use a http get request like this
https://qb.sbfinance.intuit.com/v3/company/198445012/query?query=select Id from Customer where FullyQualifiedName%3D'ABC'
&3D is a url escape of '=', this works without any problem.
Now if the customer's name is A&B, I tried the query string like this
select Id from Customer where FullyQualifiedName='A&B'
After the url encoding, it looks like this
https://qb.sbfinance.intuit.com/v3/company/198445012/query?query=select Id from Customer where FullyQualifiedName%3D'A%26B'
It will fail.
Any Idea?
Update
The above urls i copied from the IPP's API explorer.
Here is the code, I am using DevDefined.OAuth
IConsumerRequest conReq = _oSession.Request();
conReq = conReq.Get();
conReq.AcceptsType = "application/xml";
//conReq = conReq.ForUrl(string.Format(#"https://qb.sbfinance.intuit.com/v3/company/{0}/query?query={1}", Settings.Default.QuickBooksOnlineRealmId, #"select * from Customer where DisplayName='ABC'")); if use this line, it works fine
conReq = conReq.ForUrl(string.Format(#"https://qb.sbfinance.intuit.com/v3/company/{0}/query?query={1}", Settings.Default.QuickBooksOnlineRealmId, #"select * from Customer where DisplayName='A&B'"));
try
{
string str = conReq.ReadBody();
catch (Exception ex)
{
//ex.Message
}
the returned xml data like this
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2014-03-20T06:24:12.408-07:00">
<Fault type="ValidationFault">
<Error code="4000">
<Message>Error parsing query</Message>
<Detail>QueryParserError: Invalid content. Lexical error at line 1, column 44. Encountered: <EOF> after : "\'A"</Detail>
</Error>
</Fault>
</IntuitResponse>
I am not 100% sure, yesterday when i test, it actually return something says the oauth failed. But this is what I got this morning.
Actually, you can try it within IPP's API explorer, it gives the same result.
The devdefined's code for ForUrl
public static IConsumerRequest ForUrl(this IConsumerRequest request, string url)
{
request.Context.RawUri = new Uri(url);
return request;
}
That will encode the url as
https://qb.sbfinance.intuit.com/v3/company/1122502005/query?query=select%20*%20from%20Customer%20where%20DisplayName='A&B'
Ok, finally, found the issue:
The real issue is Uri(url) won't escape the & in 'A&B' because it doesn't know if it is a url & or part of the data, So i changed the following line
conReq = conReq.ForUrl(string.Format(#"https://qb.sbfinance.intuit.com/v3/company/{0}/query?query={1}", Settings.Default.QuickBooksOnlineRealmId, #"select * from Customer where DisplayName='A&B'"));
as
conReq = conReq.ForUrl(string.Format(#"https://qb.sbfinance.intuit.com/v3/company/{0}/query?query={1}", Settings.Default.QuickBooksOnlineRealmId, Uri.EscapeDataString(#"select * from Customer where DisplayName='A&B'")));
use Uri.EscapeDataString to escape the data query string first.
If you create a customer with name 'A&B', then V3 service returns that customer object like below -
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2014-03-20T01:54:46.834-07:00">
<Customer domain="QBO" sparse="false">
<Id>10</Id>
<SyncToken>0</SyncToken>
<MetaData>
<CreateTime>2014-03-20T01:54:46-07:00</CreateTime>
<LastUpdatedTime>2014-03-20T01:54:47-07:00</LastUpdatedTime>
</MetaData>
<FullyQualifiedName>A&B</FullyQualifiedName>
<DisplayName>A&B</DisplayName>
<PrintOnCheckName>A&B</PrintOnCheckName>
<Active>true</Active>
<Taxable>true</Taxable>
<Job>false</Job>
<BillWithParent>false</BillWithParent>
<Balance>100.00</Balance>
<BalanceWithJobs>100.00</BalanceWithJobs>
<PreferredDeliveryMethod>Email</PreferredDeliveryMethod>
</Customer>
</IntuitResponse>
To retrieve this object by name, you need to use the following query
SELECT * FROM Customer WHERE DisplayName = 'A&B'
But it needs to be url encoded like following
SELECT+*+FROM+Customer+WHERE+DisplayName+%3D+%27A%26B%27
Java code to achieve this -
Customer customer = GenerateQuery.createQueryEntity(Customer.class);
String query = select($(customer)).where($(customer.getDisplayName()).eq("A&B")).generate();
// Query output - SELECT * FROM Customer WHERE DisplayName = 'A&B'
String encodedUrl = URLEncoder.encode(query, "UTF-8");
It works perfectly. (Devkit handles all these pretty well )
Hope this answers your qts.
Thanks
Please see an example here to escape special chars-
using Intuit.Ipp.Core;
using Intuit.Ipp.Data;
using Intuit.Ipp.LinqExtender;
using Intuit.Ipp.QueryFilter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
static class SampleCalls
{
public static Customer QueryCustomerByDisplayName(ServiceContext context, string displayName) {
displayName = displayName.Replace("'", "\\'"); //Escape special characters
QueryService<Customer> customerQueryService = new QueryService<Customer>(context);
return customerQueryService.Where(m => m.DisplayName == displayName).FirstOrDefault();
}
}
I am trying the Force.com Streaming API demo and I get the following error:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sf="urn:fault.partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body><soapenv:Fault>
<faultcode>UNKNOWN_EXCEPTION</faultcode>
<faultstring>UNKNOWN_EXCEPTION: Element type "soapenv:Envelope" must be followed by either attribute specifications, ">" or "/>". </faultstring>
<detail>
<sf:UnexpectedErrorFault xsi:type="sf:UnexpectedErrorFault">
<sf:exceptionCode>UNKNOWN_EXCEPTION</sf:exceptionCode>
<sf:exceptionMessage>Element type "soapenv:Envelope" must be followed by either attribute specifications, ">" or "/>".</sf:exceptionMessage>
</sf:UnexpectedErrorFault>
</detail>
</soapenv:Fault></soapenv:Body>
</soapenv:Envelope>
Line 22 has a misplaced double quote that is not caught by your compiler.
Replace this code:
private static final String ENV_START =
"
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'
+ "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
"xmlns:urn='urn:partner.soap.sforce.com'><soapenv:Body>";
With this code:
private static final String ENV_START =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'"
+ "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
"xmlns:urn='urn:partner.soap.sforce.com'><soapenv:Body>";