GeneBe
asked on
API CALL IN VBSCRIPT
this api call "http://localhost:44382/api/IPauthinfo/IP0054870896"
I have a c# program that give me the result in swagger:
Response body
Download
<AuthInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<AuthId>IP0054870940 </AuthId>
<AuthNbr>IP0054870940</Aut hNbr>
<RequestingProvName>Sulliv an, Jon M</RequestingProvName>
<EffectiveDate>6/4/2020 12:00:00 AM</EffectiveDate>
<ExpireDate>6/9/2020 12:00:00 AM</ExpireDate>
<UnitsApproved>5</UnitsApp roved>
<UnitsUsed>
</UnitsUsed>
<AScode>ME</AScode>
<ARcode>M6</ARcode>
<DiagCode>J45.998</DiagCod e>
<LocationCode>31</Location Code>
<ProcedureCode>
</ProcedureCode>
</AuthInfo>
can I have a code in VBSscript that can do the api call and write it to the screen.
I have a c# program that give me the result in swagger:
Response body
Download
<AuthInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<AuthId>IP0054870940 </AuthId>
<AuthNbr>IP0054870940</Aut
<RequestingProvName>Sulliv
<EffectiveDate>6/4/2020 12:00:00 AM</EffectiveDate>
<ExpireDate>6/9/2020 12:00:00 AM</ExpireDate>
<UnitsApproved>5</UnitsApp
<UnitsUsed>
</UnitsUsed>
<AScode>ME</AScode>
<ARcode>M6</ARcode>
<DiagCode>J45.998</DiagCod
<LocationCode>31</Location
<ProcedureCode>
</ProcedureCode>
</AuthInfo>
can I have a code in VBSscript that can do the api call and write it to the screen.
ASKER
I just want to Post this to theURL = "http://localhost:44382/api/IPauthinfo/IP0054870940"
and get a response.
and get a response.
I just explained how. Did you give it a try with your own data? Below may help you get started.
or
theURL ="http://localhost:44382/api/IPauthinfo/IP0054870940"
DataToSend = ""
dim xmlhttp
set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST",theURL,false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send DataToSend
Response.ContentType = "text/xml"
Response.Write xmlhttp.responsexml.xml ' this is your response from the post but probably not used in your case
Set xmlhttp = nothing
or
theURL ="http://localhost:44382/api/IPauthinfo/IP0054870940"
DataToSend = ""
dim xmlhttp
set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST",theURL,false
xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlhttp.send DataToSend
Response.ContentType = "text/xml"
Response.Write xmlhttp.responsetext ' this is your response from the post but probably not used in your case
Set xmlhttp = nothing
ASKER
I get this error with that code.
What is the error?
Before starting you need to know:
The code I have provided is using classic asp and the vbscript Response.Write may need to be changed to Wscript.Echo. Watch for those types of errors.
Before starting you need to know:
- GET or POST?
- Do you need to pass any type of authorization or token?
- What parameters if any to pass in the header?
- What parameters to pass if any in the body or url?
- What type of output are you expecting?
The code I have provided is using classic asp and the vbscript Response.Write may need to be changed to Wscript.Echo. Watch for those types of errors.
ASKER
http://localhost:44382/api/IPauthinfo/IP0054870940 web service is running. when I put it in IE it returns the response. so I just want to make this call and be able to see the results in a msgbox or wscript.echo
Gene,
I am not sure where the break down is.
I have provided all of this information already.
The API call to the url will output text. xml or json to the body via Response.Write xmlhttp.responsetext. If you call the script using the command line, you will get out put there. I would suggest using postman. It makes working with api development easier.
I am not sure where the break down is.
I have provided all of this information already.
- Using responsetext vs responsexml.xml See line 9
- Using wscript echo instead of response.write
The API call to the url will output text. xml or json to the body via Response.Write xmlhttp.responsetext. If you call the script using the command line, you will get out put there. I would suggest using postman. It makes working with api development easier.
ASKER
it's not working for plain vbscript. I am not using asp. I think there is a conflict with VBScript and the web service I created using .NET Core 3.1. I think I will just use the json Content-Type. do you have any plain VBScript code the uses json and prints the response to screen using Wscript echo?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.
Your welcome.
As you run into an error that you are not sure of, just post a new question and make sure to include the code you are posting (obfuscating anything private) and include the exact error you are getting with the line number and word for word error detail.
As you run into an error that you are not sure of, just post a new question and make sure to include the code you are posting (obfuscating anything private) and include the exact error you are getting with the line number and word for word error detail.
In my example, I am sending xml to the screen
Open in new window
Instead of xmlhttp.responsexml.xml you can use responseText if you are going to parse something else like json or raw text or html.
The trick is to send the xml, you have to build it line by line.
Open in new window
Where I have
Open in new window
You would useOpen in new window