npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

avalara-taxrates

v1.0.1

Published

Node.js helper library for the Avalara TaxRates.com API

Downloads

4

Readme

Avalara TaxRates API client for node.js

This is a simple library to make it easier to interface with the Avalara TaxRates REST API. TaxRates will provide the overall rate and a breakdown of the rate's components for a U.S. or Canadian street address or zip/postal code.

You must register for a unique key to use this API. The TaxRates API is separate from other Avalara APIs and has its own registration. Please see our authentication documentation for a current link to the Tax Rates API registration.

##Methods

The library has two methods.

To ensure the definitions of API variables are consistent across multiple libraries, we keep a master reference of what API variables mean/represent. The phrase "see definitions" below is linked to it, though most should be self-explanatory.

For optional arguments, you may leave empty, but include the comma, e.g.: getTaxByAddress(APIKey, street, , state, country, , callback);

##Validation

The library gently validates the required data elements in both methods and will throw an exception with an error message if it detects a non-conforming element.

When throwing the exception, it will also print debug information about the method arguments to the console.

##Return Values

Each will return a JavaScript object.

If the call fails and there has been a 4xx status code returned by the server, object.error will be true and the object will have the following properties:

  • object.code - the 4xx HTTP status code returned by the server
  • object.message - what that status code likely indicates. Complete list of 4xx codes.

If the call succeeds, object.error will be false and the object will otherwise conform to the API documentation for the response object (the library will parse the returned JSON into a JavaScript object and return it with an added "error" variable with a value of false).

Sample Code

This code demonstrates both methods, using a single callback to handle both (as the response format is currently the same), and outputs their results to the console.

Install our node package: npm install avalara-taxrates

Please note that these method calls are asynchronous and will not necessarily return in order.

var taxrates = require('avalara-taxrates');

var APIKey = "YOUR API KEY - GET ONE AT taxratesapi.avalara.com";

//get tax rate by street address
taxrates.taxByAddress(APIKey, "1100 2nd Ave.", "Seattle", "WA", "USA", "98101", mycaller);

//get tax rate by zip code
taxrates.taxByZip(APIKey,"USA","91436", mycaller);

//process rate object
function mycaller(res){
  if(!res.error){
    console.log("Total Rate: " + res.totalRate);
    console.log("\nBreakdown...: ");

    for(var i in res.rates){
      console.log("\n\nRate " + (parseInt(i) + 1));
      console.log("Rate: " + res.rates[i].rate);
      console.log("Name: " + res.rates[i].name);
      console.log("Type: " + res.rates[i].type);     
      }

      //print a separator after each API call result set
      console.log("\n\n===================================\n\n");

  } else {
    console.log("ERROR:\n");
    console.log("Code: " + res.code);
    console.log("Message: " + res.message);
  }
}