Skip to content

Instantly share code, notes, and snippets.

@lakshmantgld
Last active May 2, 2024 04:24
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save lakshmantgld/fc846a0f69747c48bddbdfdca1f134af to your computer and use it in GitHub Desktop.
Save lakshmantgld/fc846a0f69747c48bddbdfdca1f134af to your computer and use it in GitHub Desktop.
Free Sales Tax API based on Postal code by Avalara

Sales Tax API

There are many companies providing sales tax API. Out of all the companies, Avalara offers free API service for sales Tax. This gist is all about setting up avalara API and querying it.

The Free-To-Use API by avalara has some restrictions. Usage of this API is subject to rate limits. Users who exceed the rate limit will receive HTTP response code 429 - Too Many Requests. The requirement for this API is to create an avalara free trail account. You can create a free account using this link create free account.

Once you have filled the form from above link, you will get an e-mail containing temporary credentials to login the avalara account. The e-mail will look something like this:

Avalara e-mail

Now, lets look into the salesTaxAPI. The API is called TaxRatesByPostalCode. It needs an Authoriaztion header. For free account, the authorization value should be base64Encoded value of accountId:licenseKey. The accountId and licenseKey can be obtained from the mail that you received from avalara.

Here is Axios example of TaxRatesByPostalCode:

var axios = require('axios');

axios({
  method:'get',
  url:'https://sandbox-rest.avatax.com/api/v2/taxrates/bypostalcode?country=<COUNTRY>&postalCode=<POSTAL-CODE>',
  headers: {'Authorization': 'Basic ' + <Base64Encoded(ACCOUNT-ID + ':' + LICENSE-KEY)>}
})
  .then(function (response) {
    console.log(response.data);
  })
  .catch(function (error) {
    console.log(error.response.data);
  });

Fill the above required values like COUNTRY, POSTAL-CODE, Base64Encoded(ACCOUNT-ID + ':' + LICENSE-KEY). Assuming the Country as US and postalCode as 98101. The response will look like this:

{
    "totalRate": 0.101,
    "rates": [
        {
            "rate": 0.065,
            "name": "WA STATE TAX",
            "type": "State"
        },
        {
            "rate": 0,
            "name": "WA COUNTY TAX",
            "type": "County"
        },
        {
            "rate": 0.036,
            "name": "WA CITY TAX",
            "type": "City"
        }
    ]
}
@mkellyxp
Copy link

mkellyxp commented Jan 6, 2022

Just a heads up that this will ONLY work for US as of when i'm posting this. If you try another country you'll get.

[description] => The free TaxRates API is for use in the US only. Please use CreateTransaction() for tax rates in countries other than the US.

I'm working on an api wrapper for that too

@Imjustdave2
Copy link

Looks like the Free aspect is now long gone :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment