Graeme McGilvray
asked on
currencylayer API intergrate to ASP
Hi all, I am new to this, so as much break down as possible would be extremely appreciated
I have got this currencylayer API:
http://apilayer.net/api/live?access_key=accesskey¤cies=AUD&source=USD&format=1
the outcome, is what I want to put into ASP to do some converting
Thanks in advance
I have got this currencylayer API:
http://apilayer.net/api/live?access_key=accesskey¤cies=AUD&source=USD&format=1
the outcome, is what I want to put into ASP to do some converting
Thanks in advance
the output of that API is a json string. what are you trying to do with your ASP code or what you trying to display from this output?
ASKER
I would like the USD to AUD rate (which currently is 1.351717) and use that to auto update my pricing as i buy from overseas in foreign currency
the json string returned an invalid output.
can you provide a valid request here?
{
"success":false,
"error":{
"code":101,
"type":"invalid_access_key",
"info":"You have not supplied a valid API Access Key. [Technical Support: support@apilayer.com]"
}
}
can you provide a valid request here?
ASKER
I can, but that would mean giving out my access key, which is private
This is the output thou:
This is the output thou:
{
"success":true,
"terms":"https:\/\/currencylayer.com\/terms",
"privacy":"https:\/\/currencylayer.com\/privacy",
"timestamp":1467120967,
"source":"USD",
"quotes":{
"USDAUD":1.351717
}
}
ASKER
Anything Ryan?
Hi Good day,
You can look at aspjson for handling JSON with VBScript
http://code.google.com/p/aspjson/
You can also use Javascript as your classic asp server side scripting language, which would involve you rewriting your server http request in Javascript, but it would make the json part of the page much easier.
You can even use VBS and JS in the same page, eg
<%@ Language=javascript %>
<script language="VBScript" runat="server">
Set xmlhttp = CreateObject("Msxml2.Serve rXMLHTTP.6 .0")
xmlhttp.open "GET", "http://someip:8080/Publisher/Titles/Paging/0,0,tc?output=json", 0
xmlhttp.send ""
Response.AddHeader "Content-Type", "application/json;charset= UTF-8"
Response.Charset = "UTF-8"
pageReturn = xmlhttp.responseText
Set xmlhttp = Nothing
</script>
<% var resultcount = pageReturn.Titles.resultCo unt;
var moreresources = pageReturn.Titles.moreReso urces;
%>
<html>
<body>
<%=resultcount%>, <%=moreresources%>
</body>
</html>
You can look at aspjson for handling JSON with VBScript
http://code.google.com/p/aspjson/
You can also use Javascript as your classic asp server side scripting language, which would involve you rewriting your server http request in Javascript, but it would make the json part of the page much easier.
You can even use VBS and JS in the same page, eg
<%@ Language=javascript %>
<script language="VBScript" runat="server">
Set xmlhttp = CreateObject("Msxml2.Serve
xmlhttp.open "GET", "http://someip:8080/Publisher/Titles/Paging/0,0,tc?output=json", 0
xmlhttp.send ""
Response.AddHeader "Content-Type", "application/json;charset=
Response.Charset = "UTF-8"
pageReturn = xmlhttp.responseText
Set xmlhttp = Nothing
</script>
<% var resultcount = pageReturn.Titles.resultCo
var moreresources = pageReturn.Titles.moreReso
%>
<html>
<body>
<%=resultcount%>, <%=moreresources%>
</body>
</html>
ASKER
Hi Charles and thank you very much for this. As I said I am very new to APIs, unfortunately i dont understand much of it.
the outcome I am looking for is:
'1.351717' - I want to put this into something I can use eg CurrConvert='TheAPIOutput'
I tried to copy and paste the code you have suggested and replace the string with my API
However it is coming up with an error:
Microsoft VBScript compilation error '800a0401'
Expected end of statement
the outcome I am looking for is:
'1.351717' - I want to put this into something I can use eg CurrConvert='TheAPIOutput'
I tried to copy and paste the code you have suggested and replace the string with my API
However it is coming up with an error:
Microsoft VBScript compilation error '800a0401'
Expected end of statement
var resultcount = pageReturn.Titles.resultCount;
-----------------------------------------------^
ASKER
Charles?
sorry for being late to reply.
knowing that you wish to get the value of "USDAUD" from the return string.
just another question before we proceed, do you want to do it in ASP or JavaScript? reason being it's quite easy to read a JSON string from JavaScript.
knowing that you wish to get the value of "USDAUD" from the return string.
just another question before we proceed, do you want to do it in ASP or JavaScript? reason being it's quite easy to read a JSON string from JavaScript.
ASKER
Hi Ryan, as long as I can use the out in my ASP querys, it wouldnt matter (however just saying that, prob ASP)
Chhers
Chhers
you probably can try this:
and change the method from POST to GET if necessary.
<%
Dim oXMLHTTP
Dim strStatusTest
Set oXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")
url = "http://apilayer.net/api/live?access_key=accesskey¤cies=AUD&source=USD&format=1"
CurrValue = 0
oXMLHTTP.Open "POST", url, False
oXMLHTTP.Send
If oXMLHTTP.Status = 200 Then
GetTextFromUrl = oXMLHTTP.responseText
Arr = Split(GetTextFromUrl, vbCrLf)
for i = 0 to ubound(Arr)
if instr(Arr(i), "USDAUD") > 0 then
CurrValue = CDbl(Split(Arr(i),":")(1))
exit for
end if
next
End If
response.Write("GetTextFromUrl = " & GetTextFromUrl & "<br><br>CurrValue = " & CurrValue)
%>
you may change the URL to put in the valid parametersand change the method from POST to GET if necessary.
ASKER
Hi Ryan and thanks for that, have replaced the accesskey and for this msg:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'CDbl'
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'CDbl'
CurrValue = CDbl(Split(Arr(i),":")(1))
maybe you can just use:
the code I provided has been tested before I posted.
CurrValue = Split(Arr(i),":")(1)
the code I provided has been tested before I posted.
ASKER
Hi Ryan, have just changed it, seems to have moved onto something else now
Microsoft VBScript runtime error '800a000d'
Type mismatch: '[string: "true, "terms""]' <-- coming from the API by the looks
Microsoft VBScript runtime error '800a000d'
Type mismatch: '[string: "true, "terms""]' <-- coming from the API by the looks
CurrValue = Split(Arr(i),":")(1)
unfortunately i don't have IIS6 for troubleshooting.
maybe you can try add this at the beginning of your scripts and see if that resolved your error?
maybe you can try add this at the beginning of your scripts and see if that resolved your error?
<%@ LANGUAGE="VBScript"%>
ASKER
Hi Ryan, I have just added that, same error
can we know what's the value of GetTextFromUrl if you response it out?
and can you run any other asp pages in your machine?
response.write(GetTextFromUrl)
response.end
try view and copy paste the output here?and can you run any other asp pages in your machine?
ASKER
All other ASP pages run perfectly fine on my site (and alot of them)
unable to get a response out of GetTextFromUrl because the code errors before it get to its line
unable to get a response out of GetTextFromUrl because the code errors before it get to its line
can you try run this and what you get from here?
<%
Dim oXMLHTTP
Dim strStatusTest
Set oXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")
url = "http://apilayer.net/api/live?access_key=accesskey¤cies=AUD&source=USD&format=1"
oXMLHTTP.Open "POST", url, False
oXMLHTTP.Send
If oXMLHTTP.Status = 200 Then
GetTextFromUrl = oXMLHTTP.responseText
response.Write(GetTextFromUrl)
response.End
End If
%>
ASKER
Hi Ryan
here is the output:
here is the output:
{ "success":true, "terms":"https:\/\/currencylayer.com\/terms", "privacy":"https:\/\/currencylayer.com\/privacy", "timestamp":1468289826, "source":"USD", "quotes":{ "USDAUD":1.320981 } }
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I think we have a winner! :)
GetTextFromUrl = { "success":true, "terms":"https:\/\/currencylayer.com\/terms", "privacy":"https:\/\/currencylayer.com\/privacy", "timestamp":1468293132, "source":"USD", "quotes":{ "USDAUD":1.318202 } }
CurrValue = 1.318202
coool, eventually we make it right!