We've Moved! Please visit our new and improved forum over at our new portal: https://portal.plumvoice.com/hc/en-us/community/topics
Getting Data from HTTP Header
Getting Data from HTTP Header
In the HTTP response from an API there is a variable stored in the HTTP header that I would like to expose to my VXML. Is it possible, and if so, how would I go about obtaining this variable's value in the VXML?
Re: Getting Data from HTTP Header
Hi,
You should use another programming language like PHP to parse the HTTP header and to pass the relevant data to your VXML, like so:
If you'd like access to the raw XML your API is returning, you can also use the <data> tag to get the raw XML response, and then the script tag to use Javascript to parse it, like this:
Regards,
Plum Support
You should use another programming language like PHP to parse the HTTP header and to pass the relevant data to your VXML, like so:
Code: Select all
<?php
// Get relevant HTTP headers data here
$HTTP_header_data = 'Hello world!';
header('Content-type: text/xml');
echo '<?xml version="1.0"?>';
?>
<vxml version="2.0">
<form id="my_form">
<block>
<prompt>><?= $HTTP_header_data ?></prompt>
<exit/>
</block>
</form>
</vxml>
If you'd like access to the raw XML your API is returning, you can also use the <data> tag to get the raw XML response, and then the script tag to use Javascript to parse it, like this:
Code: Select all
<vxml version="2.0">
<form id="my_form">
<block>
<data name="API_response" src="http://myAPIurl.com" method="raw" enctype="application/xml" rawexpr="rawxml"/>
<script>
<![CDATA[
var HTTP_headers = API_response.documentElement.getElementsByTagName('header').item(0).firstChild.toString();
]]>
</script>
<prompt>Your HTTP header data is <value expr="HTTP_headers"/></prompt>
<exit/>
</block>
</form>
</vxml>
Plum Support
Plum Support
http://www.plumvoice.com
http://www.plumvoice.com
Re: Getting Data from HTTP Header
It seems like the first solution is only going to get my the HTTP header of a page, not from an API response, since it is not tied to any particular API/data call. Is this correct?
As for the second solution, how does using the raw method type change what is received in the response to the data call? I have data calls in my VXML that use the raw method and this does not seem to expose the header via the named data object specified in the data tag.
As for the second solution, how does using the raw method type change what is received in the response to the data call? I have data calls in my VXML that use the raw method and this does not seem to expose the header via the named data object specified in the data tag.
Re: Getting Data from HTTP Header
PHP can get the HTTP headers from a URL that you specify. For more details, please take a look at PHP's documentation: http://php.net/manual/en/function.get-headers.php
Using the "raw" method in the data tag doesn't reveal the HTTP headers as in the status code/date/server data etc, but it does give you access to the headers in a raw XML response from your API (assuming your API returns raw XML)
In order to better assist you, could you give us an example of how you are calling your API within your IVR application? And also let us know what HTTP header data you wish to access.
Using the "raw" method in the data tag doesn't reveal the HTTP headers as in the status code/date/server data etc, but it does give you access to the headers in a raw XML response from your API (assuming your API returns raw XML)
In order to better assist you, could you give us an example of how you are calling your API within your IVR application? And also let us know what HTTP header data you wish to access.
Plum Support
http://www.plumvoice.com
http://www.plumvoice.com
Re: Getting Data from HTTP Header
In this case I am looking to get a value placed in the header by a Vordel security gateway called the X-Correlation-ID. Each API call is assigned a unique X-Correlation-ID.
I confirmed with the API developers that they are returning raw xml.
Here are a couple examples of API calls in a couple of our applications:
Example 1
Note, in this example the response happens to contain an element named header, but it is not the HTTP header.
For this API call I see in the log:
Response Code Initial Request: 00
LOCAL: *****
LOCAL: *****
LOCAL: *****
LOCAL: *****
LOCAL: *****Document Element = Responsebhnums:response
LOCAL: *****Document Element = Response Atrribute 0 : http://www.blackhawknetwork.com/bhnums
LOCAL: *****Document Element = Response Atrribute 1 : http://www.w3.org/2001/XMLSchema-instance
LOCAL: *****Document Element = Response Atrribute 2 : http://www.blackhawknetwork.com/bhnums
LOCAL: *****Document Element = Response Atrribute 3 : http://www.blackhawknetwork.com/bhnums transaction.xsd
LOCAL: *****
LOCAL: *****document element response first child = header : header
LOCAL: *****
LOCAL: *****document element response first child header 1st child = : h1
LOCAL: *****document element response first child header 1st child child = : 01
LOCAL: *****
LOCAL: *****document element response first child header 2nd child = : h2
LOCAL: *****document element response first child header 2nd child child = : 02
LOCAL: *****
LOCAL: *****document element response first child header 3rd child = : h3
LOCAL: *****document element response first child header 3rd child child = : 00
LOCAL: *****
LOCAL: *****document element response second child message = : message
...
TypeError: request.documentElement.getElementsByTagName("Header").item(0) has no properties line 1
Example 2
For this API call I see in the log:
OCAL: *****cardStatusResponse Document Element :response
LOCAL: *****
LOCAL: *****cardStatusResponse document element response first child : statusinfo
LOCAL: *****cardStatusResponse document element statusinfo child node 0 : status
LOCAL: *****cardStatusResponse document element status child node 0 : code
LOCAL: *****cardStatusResponse document element status child node 1 : description
....
TypeError: cardStatusResponse.documentElement.getElementsByTagName("Header").item(0) has no properties line 1
I confirmed with the API developers that they are returning raw xml.
Here are a couple examples of API calls in a couple of our applications:
Example 1
Note, in this example the response happens to contain an element named header, but it is not the HTTP header.
Code: Select all
<data name="request" src="https://plumvoicepp.blackhawk-net.com:464/bhnumsxml" method="raw" enctype="application/xml" rawexpr="rawxml" />
<block>
<log label="response_code"> Response Code Initial Request: <value expr="response_code" /> </log>
<!-- <log expr="'*****headers lowercase ' +getValueFirstLevelSafe(request, 'headers')"/>
<log expr="'*****headers lowercase ' +getValueFirstLevelSafe(request, 'X-Correlation-ID')"/>
<log expr="'*****headers lowercase ' +getValueFirstLevelSafe(request, 'X-Correlation Id')"/>
<log expr="'*****headers lowercase ' +getValueFirstLevelSafe(request, 'X-Correlation-id')"/>
<log expr="'*****headers lowercase ' +getValueFirstLevelSafe(request, 'X-Correlation-id')"/>
<log expr="'*****headers lowercase ' +getValueFirstLevelSafe(request, 'X-correlation-id')"/> -->
<log expr="'*****'"/>
<log expr="'*****'"/>
<log expr="'*****'"/>
<log expr="'*****'"/>
<log expr="'*****Document Element = Response' +request.documentElement.toString()"/>
<log expr="'*****Document Element = Response Atrribute 0 : ' +request.documentElement.attributes.item(0).toString()"/>
<log expr="'*****Document Element = Response Atrribute 1 : ' +request.documentElement.attributes.item(1).toString()"/>
<log expr="'*****Document Element = Response Atrribute 2 : ' +request.documentElement.attributes.item(2).toString()"/>
<log expr="'*****Document Element = Response Atrribute 3 : ' +request.documentElement.attributes.item(3).toString()"/>
<log expr="'*****'"/>
<log expr="'*****document element response first child = header : ' +request.documentElement.firstChild.toString()"/>
<log expr="'*****'"/>
<log expr="'*****document element response first child header 1st child = : ' +request.documentElement.firstChild.childNodes.item(0).toString()"/>
<log expr="'*****document element response first child header 1st child child = : ' +request.documentElement.firstChild.childNodes.item(0).firstChild.toString()"/>
<log expr="'*****'"/>
<log expr="'*****document element response first child header 2nd child = : ' +request.documentElement.firstChild.childNodes.item(1).toString()"/>
<log expr="'*****document element response first child header 2nd child child = : ' +request.documentElement.firstChild.childNodes.item(1).firstChild.toString()"/>
<log expr="'*****'"/>
<log expr="'*****document element response first child header 3rd child = : ' +request.documentElement.firstChild.childNodes.item(2).toString()"/>
<log expr="'*****document element response first child header 3rd child child = : ' +request.documentElement.firstChild.childNodes.item(2).firstChild.toString()"/>
<log expr="'*****'"/>
<log expr="'*****document element response second child message = : ' +request.documentElement.firstChild.nextSibling.toString()"/>
...
<log expr="'***** Header ' +request.documentElement.getElementsByTagName('Header').item(0).firstChild.toString()"/>
</block>
Response Code Initial Request: 00
LOCAL: *****
LOCAL: *****
LOCAL: *****
LOCAL: *****
LOCAL: *****Document Element = Responsebhnums:response
LOCAL: *****Document Element = Response Atrribute 0 : http://www.blackhawknetwork.com/bhnums
LOCAL: *****Document Element = Response Atrribute 1 : http://www.w3.org/2001/XMLSchema-instance
LOCAL: *****Document Element = Response Atrribute 2 : http://www.blackhawknetwork.com/bhnums
LOCAL: *****Document Element = Response Atrribute 3 : http://www.blackhawknetwork.com/bhnums transaction.xsd
LOCAL: *****
LOCAL: *****document element response first child = header : header
LOCAL: *****
LOCAL: *****document element response first child header 1st child = : h1
LOCAL: *****document element response first child header 1st child child = : 01
LOCAL: *****
LOCAL: *****document element response first child header 2nd child = : h2
LOCAL: *****document element response first child header 2nd child child = : 02
LOCAL: *****
LOCAL: *****document element response first child header 3rd child = : h3
LOCAL: *****document element response first child header 3rd child child = : 00
LOCAL: *****
LOCAL: *****document element response second child message = : message
...
TypeError: request.documentElement.getElementsByTagName("Header").item(0) has no properties line 1
Example 2
Code: Select all
<data name="cardStatusResponse"
srcexpr="'https://plumvoicepp.blackhawk-net.com:464/services/cardmanagementservices/v3/card/status'"
namelist="card.number card.expiration channel.id" />
<log expr="'*****cardStatusResponse Document Element :' +cardStatusResponse.documentElement.toString()"/>
<log expr="'*****'"/>
<log expr="'*****cardStatusResponse document element response first child : ' +cardStatusResponse.documentElement.firstChild.toString()"/>
<log expr="'*****cardStatusResponse document element statusinfo child node 0 : ' +cardStatusResponse.documentElement.firstChild.childNodes.item(0).toString()"/>
<log expr="'*****cardStatusResponse document element status child node 0 : ' +cardStatusResponse.documentElement.firstChild.childNodes.item(0).childNodes.item(0).toString()"/>
<log expr="'*****cardStatusResponse document element status child node 1 : ' +cardStatusResponse.documentElement.firstChild.childNodes.item(0).childNodes.item(1).toString()"/>
<log expr="'*****'"/>
....
<log expr="'***** Header ' +cardStatusResponse.documentElement.getElementsByTagName('Header').item(0).firstChild.toString()"/>
OCAL: *****cardStatusResponse Document Element :response
LOCAL: *****
LOCAL: *****cardStatusResponse document element response first child : statusinfo
LOCAL: *****cardStatusResponse document element statusinfo child node 0 : status
LOCAL: *****cardStatusResponse document element status child node 0 : code
LOCAL: *****cardStatusResponse document element status child node 1 : description
....
TypeError: cardStatusResponse.documentElement.getElementsByTagName("Header").item(0) has no properties line 1
Re: Getting Data from HTTP Header
Hi,
Currently, there is no way to do this strictly in VXML. You will have to use a server side language like PHP as our platform does not support accessing HTTP headers.
Perhaps you could send X-Correlation-ID as part of your raw XML response instead of in the HTTP headers? You should also reach out your account manager if you'd like to make a feature request.
Regards,
Plum Support
Currently, there is no way to do this strictly in VXML. You will have to use a server side language like PHP as our platform does not support accessing HTTP headers.
Perhaps you could send X-Correlation-ID as part of your raw XML response instead of in the HTTP headers? You should also reach out your account manager if you'd like to make a feature request.
Regards,
Plum Support
Plum Support
http://www.plumvoice.com
http://www.plumvoice.com