I'm trying to make a call out to a third party using http post. I can get this to work using the Send Http Post Request trigger with a document template. My issue is i need to get a response from the third party and store that information for use in another call. it doesn't appear to be an option inside the trigger unless I'm missing something. I tried to use the rbv_api.sendHttpPost API, but that appears to only work if I'm sending json and not xml.
Is this something that is possible?
Hello,
Does the third party service provider have an option that will return the data as XML?
Thank you,
Gian
Yes, I get an xml response back from the Send Http Post Request trigger. I'm just not sure how to do anything with the response.
Hello,
I believe you can use javascript code to read the XML response. Please see this forum post at http://stackoverflow.com/.../using-xmlhttprequest-reading-xml-data
Hope this helps.
Thank you,
Gian
Hi Gian,
Thanks for your response. I understand that i can parse through an xml response with javascript. I came across a couple posts similar to the one you sent. What I don't understand is where I would put that code. When I call the Send Http Post Trigger on create, it sends the xml correctly to my third party. That call has a response containing an ID that I need to use for a subsequent call. I don't see anywhere on the trigger setup where I can tell Rollbase what to do with the response. I assumed I couldn't put anything in the document template either since the whole thing is sent in the Http request.
Unless I am missing something, it appears the Send Http Post Request trigger is only useful when you are sending something to a third party and not expecting a response.
There is a way to process HTTP response in subsequent triggers through rbv_api.getSharedValue() API. However now we have much easier way: rbv_api.sendHttpPost() API in Object Script triggers. Use rbv_api.parseXML() to parse XML response.
I have tried the rbv_api.sentHttpPost and have not had any success in gettting a valid response from the third party. It appears to be limited to the fact that the parameters I have to pass through this trigger must be in name/value pairs and their service is expecting pure xml. If there is a trick to making that work, I would love to hear it.
Any other thoughts?
Please try
rbv_api.sendJSONRequest(url, data, method, contentType, username, password, headers)
Pass your XML as "data" parameter.
That worked to get my response. Thank you very much for the help.
i'm trying to use the parse xml api and the results are not what I would have expected. Here is the code I have showing what I'm debugging.
var resp = rbv_api.sendJSONRequest(url, data, method, contentType, null, null, null);
var root = rbv_api.parseXML(resp);
var nodes = root.getChildNodes();
for (var k=0; k<nodes.length; k++) {
var child = nodes.item(k);
rbv_api.println("Tag="+child.getTagName());
var nodes2 = child.getChildNodes();
for (var n=0; n<nodes2.length; n++) {
var child2 = nodes2.item(n);
var x = child2.getNodeValue();
rbv_api.println("Value="+x);
}
}
rbv_api.println('Root');
rbv_api.printArr(root);
rbv_api.println('\n Nodes');
rbv_api.printArr(nodes);
rbv_api.println('\n Child');
rbv_api.printArr(child);
rbv_api.println('\n Child2');
rbv_api.printArr(child2);
rbv_api.println('\n XML Response');
rbv_api.print(resp);
Here is what I get back from that code:
Tag=Response
Value=null
Value=null
Value=null
Value=null
Value=null
Value=null
Value=null
Value=null
Root
[TransactionSetupResponse: null]
Nodes
[TransactionSetupResponse: null]
Child
[Response: null]
Child2
[TransactionSetup: null]
XML Response
All I need to get is the TransactionSetupID from the response.
Thanks again for your help on this.
If you only want to extract a single value from XML document, try using XPATH API:
rbv_api.evalXpath(xmlString, xpathExpr)
Traversing DOM structure may be tedious exercise.
I'm still not getting a value I can use. I've never used the Xpath before.
This is what I'm trying to pass:
var myXpath = "/TransactionSetupResponse/Response/Transaction/TransactionSetupID";
var transactionSetupID = rbv_api.evalXpath(resp, myXpath);
rbv_api.printArr(transactionSetupID);
This is my xml response:
This is what is being returned using the rbv_api.evalXpath:
com.sun.org.apache.xml.internal.dtm.ref.DTMNodeList@55c66a53
Try this:
var myXpath = "/TransactionSetupResponse/Response/Transaction/TransactionSetupID/text()";
var res = rbv_api.evalXpath(resp, myXpath);
for (var k=0; k<res.length; k++)
rbv_api.println("Result: "+res.item(k));
var transactionSetupID = res.item(0).getNodeValue();
rbv_api.println("transactionSetupID="+transactionSetupID);
More info: documentation.progress.com/.../index.html
That worked perfectly! Thank you very much for your help.