Connecting to API Using ASP

asp-Logo Included here you will find simple sample code for parsing the Database Interface API in XML. The first example returns primary data for a given jurisdiction - the result containing the United States Post Office. Some ZIP codes include multiple cities and sometimes multiple tax jurisdictions, so the second example shows how to go down the hierarchy and parse the XML.

Basic: mssql-basic.asp

		<%

Dim xmlhttp
Dim DataToSend
Dim strUser
strUser = "sample"
Dim strPassword
strPassword = "password"
Dim strZip
strZip = "90210"

Dim postUrl
postUrl = "https://api.zip2tax.com/TaxRate-USA.xml?username="&strUser&"&password="&strPassword&"&zip="&strZip

Set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "GET",postUrl,false
xmlhttp.send
Response.ContentType = "charset=utf-8"

Set xmlDoc = CreateObject("MSXML2.DOMDocument") 'creating the parser object
xmlDoc.LoadXml(xmlhttp.responseText)

Set itemList = xmlDoc.SelectNodes("/z2tLookup/addressInfo/addresses/address")
For Each itemAttrib In itemList
    
    Dim zip_code : zip_code = itemAttrib.SelectSingleNode("zipCode").text
    Dim place : place = itemAttrib.SelectSingleNode("place").text
    Dim county : county = itemAttrib.SelectSingleNode("county").text
    Dim state : state = itemAttrib.SelectSingleNode("state").text
Next

Set itemTaxList = xmlDoc.SelectNodes("/z2tLookup/addressInfo/addresses/address/salesTax/rateInfo")
For Each itemAttrib In itemTaxList
    
    Dim taxRate : taxRate = itemAttrib.SelectSingleNode("taxRate").text
Next

Dim count:  count = 0
Set itemTaxList = xmlDoc.SelectNodes("/z2tLookup/addressInfo/addresses/address/notes/noteDetail")
For Each itemAttrib In itemTaxList  
    if count = 1 then
        Dim shipping_note : shipping_note = itemAttrib.SelectSingleNode("note").text
    end if
    count = count + 1
Next

Dim shipping : shipping = 0
if shipping_note = "Shipping charges are not taxable" then
        shipping = 1
end if

Response.Write "Zip Code: " & zip_code &  vbCrLf
Response.Write "Sales Tax Rate: " & taxRate &  vbCrLf
Response.Write "Post Office City: " & place &  vbCrLf
Response.Write "County: " & county &  vbCrLf
Response.Write "State: " & state &  vbCrLf
Response.Write "Shipping Taxable: " & shipping &  vbCrLf


set xmlhttp = nothing
%>


		

 

Breakout: mssql-breakout.asp

		
<%

Dim xmlhttp
Dim DataToSend
Dim strUser
strUser = "sample"
Dim strPassword
strPassword = "password"
Dim strZip
strZip = "90210"

Dim postUrl
postUrl = "https://api.zip2tax.com/TaxRate-USA.xml?username="&strUser&"&password="&strPassword&"&zip="&strZip


Set xmlhttp = server.Createobject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "GET",postUrl,false

xmlhttp.send

Response.ContentType = "charset=utf-8"



Set xmlDoc = CreateObject("MSXML2.DOMDocument") 'creating the parser object
xmlDoc.LoadXml(xmlhttp.responseText)



Set itemList = xmlDoc.SelectNodes("/z2tLookup/addressInfo/addresses/address")
For Each itemAttrib In itemList
    
    Dim zip_code : zip_code = itemAttrib.SelectSingleNode("zipCode").text
    Dim place : place = itemAttrib.SelectSingleNode("place").text
    Dim county : county = itemAttrib.SelectSingleNode("county").text
    Dim state : state = itemAttrib.SelectSingleNode("state").text
Next

Set itemTaxList = xmlDoc.SelectNodes("/z2tLookup/addressInfo/addresses/address/salesTax/rateInfo")
For Each itemAttrib In itemTaxList
    
    Dim taxRate : taxRate = itemAttrib.SelectSingleNode("taxRate").text
Next

Dim count:  count = 0
Set itemTaxList = xmlDoc.SelectNodes("/z2tLookup/addressInfo/addresses/address/notes/noteDetail")
For Each itemAttrib In itemTaxList  
    if count = 1 then
        Dim shipping_note : shipping_note = itemAttrib.SelectSingleNode("note").text
    end if
    count = count + 1
Next

Dim shipping : shipping = 0
if shipping_note = "Shipping charges are not taxable" then
        shipping = 1
end if


Response.Write "Zip Code: " & zip_code &  vbCrLf
Response.Write "Sales Tax Rate: " & taxRate &  vbCrLf
Response.Write "Post Office City: " & place &  vbCrLf
Response.Write "County: " & county &  vbCrLf
Response.Write "State: " & state &  vbCrLf
Response.Write "Shipping Taxable: " & shipping &  vbCrLf

count = 0
Set itemTaxList = xmlDoc.SelectNodes("/z2tLookup/addressInfo/addresses/address/salesTax/rateInfo/rateDetails/rateDetail")
For Each itemAttrib In itemTaxList  

If count = 0 Then

Response.Write "Sales Tax Rate State: " & itemAttrib.SelectSingleNode("taxRate").text & vbCrLf
count = count + 1

ElseIf count = 1 Then

Response.Write "Sales Tax Rate County: " & itemAttrib.SelectSingleNode("taxRate").text & vbCrLf
count = count + 1

ElseIf count = 2 Then

Response.Write "Sales Tax Rate City: " & itemAttrib.SelectSingleNode("taxRate").text &  vbCrLf
count = count + 1

 ElseIf count = 3 Then

Response.Write "Sales Tax Rate Special: " & itemAttrib.SelectSingleNode("taxRate").text & vbCrLf
count = count + 1
End If
Next

Response.Write "Sales Tax Reporting_Code Total: " & "(n/a)" & vbCrLf
Response.Write "Sales Tax Reporting_Code State: " & "(n/a)" & vbCrLf

    count = 0
Set itemTaxList = xmlDoc.SelectNodes("/z2tLookup/addressInfo/addresses/address/salesTax/rateInfo/rateDetails/rateDetail")
For Each itemAttrib In itemTaxList  
    if count = 1 then
        Response.Write "Sales Tax Rate Special: " & itemAttrib.SelectSingleNode("jurisdictionCode").text & vbCrLf
    end if
    count = count + 1
Next

set xmlhttp = nothing
%>


		

 

Sample ZIP Code Range

In the sample ZIP code range (90001 - 90999), the following ZIP codes contain multiple tax rates; which can be used to test the return of multiple rows:

  • 90304
  • 90601
  • 90631
Terms of service: At Zip2Tax, your security and confidentiality are our highest priority. We will never share your e-mail address or any other personally identifiable information (PII) with any other person or company. Please review our full privacy policy. License: Please refer to our end user license agreement. Cancellation and Refund Policy: Please refer to our refund policy prior to purchase.
Copyright © 2006-2018 Zip2Tax, LLC. All rights reserved. Zip2Tax and Spot-On™ are trademarks of Zip2Tax, LLC, reg. pending U.S. Pat. & Tm. Off., S/N 86/613550 and 86/613547.

Quantcast
Quantcast
IP Address: 34.204.52.4
JavaScript: Fail
loggedd: none
WSPhilly03/DBPhilly03/CCProd

Don't have an account?

Sign up for a free trial here
If you do not have an account, please provide the information below.


Already have an account?
Free trial close Thank You!

Please check your email for your Username and Password.

If you do not receive your email shortly, check your SPAM folder for mail from "info@Zip2Tax.com" or call us at 1-866-492-8494, Monday - Friday 8am - 5pm EST.
Zip2Tax Password recovery close Password recovery

Please provide your registered email to verify and send password.



submit