### Java Quickstart - Getting Started Source: https://developers.taxjar.com/api/guides/java Instructions on how to add the TaxJar Java client library to your project using Maven or Gradle. ```APIDOC ## Getting Started with TaxJar Java Client This section guides you through adding the `taxjar-java` library to your project. ### Method Installation via package managers. ### Parameters None. ### Request Example **Maven:** ```xml com.taxjar taxjar-java 1.0.0 ``` **Gradle:** ```groovy compile "com.taxjar:taxjar-java:1.0.0" ``` After adding the dependency, run `mvn install` or use your IDE to install the dependencies. ``` -------------------------------- ### Java Quickstart - Sales Tax Calculations Source: https://developers.taxjar.com/api/guides/java Example of how to calculate sales tax for an order using the TaxJar Java client. ```APIDOC ## Calculating Sales Tax for an Order This section shows how to calculate sales tax for an order by providing origin and destination addresses, amounts, and line items. ### Method `client.taxForOrder(params)` ### Endpoint N/A (Client-side method) ### Parameters #### Request Body (Map) * **from_country** (string) - Required - The country you are shipping from. * **from_zip** (string) - Required - The zip code you are shipping from. * **from_state** (string) - Required - The state you are shipping from. * **from_city** (string) - Optional - The city you are shipping from. * **to_country** (string) - Required - The country the order is being shipped to. * **to_zip** (string) - Required - The zip code the order is being shipped to. * **to_state** (string) - Required - The state the order is being shipped to. * **to_city** (string) - Optional - The city the order is being shipped to. * **amount** (double) - Required - Total amount of the order, excluding shipping. * **shipping** (double) - Required - Total amount of shipping for the order. * **line_items** (List) - Optional - A list of items in the order, each with `id`, `product_tax_code`, and `unit_price`. ### Request Example ```java import com.taxjar.Taxjar; import com.taxjar.exception.TaxjarException; import com.taxjar.model.taxes.TaxResponse; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class TaxExample { public static void main(String[] args) { Taxjar client = new Taxjar(System.getenv("TAXJAR_API_KEY")); try { Map params = new HashMap<>(); params.put("from_country", "US"); params.put("from_zip", "92093"); params.put("from_state", "CA"); params.put("from_city", "San Diego"); params.put("to_country", "US"); params.put("to_zip", "90002"); params.put("to_state", "CA"); params.put("to_city", "Los Angeles"); params.put("amount", 16.5); params.put("shipping", 1.5); List lineItems = new ArrayList(); Map lineItem = new HashMap<>(); lineItem.put("id", 1); lineItem.put("product_tax_code", "31000"); lineItem.put("unit_price", 15); lineItems.add(lineItem); params.put("line_items", lineItems); TaxResponse res = client.taxForOrder(params); // Accessing response data System.out.println("Amount to Collect: " + res.tax.getAmountToCollect()); System.out.println("Rate: " + res.tax.getRate()); } catch (TaxjarException e) { e.printStackTrace(); } } } ``` ### Response #### Success Response (200) * **tax** (object) - Contains tax calculation details. * **order_total_amount** (double) - The total order amount. * **shipping** (double) - The shipping amount. * **taxable_amount** (double) - The amount on which tax is calculated. * **amount_to_collect** (double) - The total tax to collect. * **rate** (double) - The sales tax rate. * **has_nexus** (boolean) - Indicates if nexus is present. * **freight_taxable** (boolean) - Indicates if freight is taxable. * **tax_source** (string) - The source of tax calculation (e.g., 'destination'). * **breakdown** (object) - Detailed breakdown of tax by jurisdiction (can be empty). #### Response Example ```json { "tax": { "order_total_amount": 16.5, "shipping": 1.5, "taxable_amount": 15.0, "amount_to_collect": 1.35, "rate": 0.09, "has_nexus": true, "freight_taxable": true, "tax_source": "destination", "breakdown": {} } } ``` **Note:** For specific product tax codes, refer to the [TaxJar category list](https://developers.taxjar.com/api/reference/#categories). For just the tax rate of a location, consider using the `/v2/rates` endpoint. ``` -------------------------------- ### Gemfile Setup Source: https://developers.taxjar.com/api/guides/ruby Instructions on how to add the TaxJar Ruby gem to your project's Gemfile and install it. ```APIDOC ## Gemfile Setup ### Description Adds the `taxjar-ruby` gem to your application's Gemfile and installs it using `bundle install`. ### Method N/A (Configuration step) ### Endpoint N/A ### Parameters N/A ### Request Example ```ruby # Gemfile gem 'taxjar-ruby', require: 'taxjar' ``` ### Response N/A (Installation success) ### Success Response (200) N/A ### Response Example N/A ``` -------------------------------- ### Create Order Example with Error Handling Source: https://developers.taxjar.com/api/guides/go This snippet demonstrates how to create an order using the TaxJar Go client and how to handle potential errors returned by the API. ```APIDOC ## POST /v2/orders ### Description Creates a new sales tax order. This is typically used after a transaction is completed to calculate and record the final sales tax. ### Method `POST` ### Endpoint `/v2/orders` ### Parameters #### Request Body - **transaction_id** (string) - Optional - A unique identifier for the transaction. If not provided, TaxJar will generate one. - **transaction_date** (string) - Required - The date of the transaction in `YYYY/MM/DD` format. - **from_country** (string) - Required - The origin country for the transaction. - **from_zip** (string) - Required - The origin ZIP code for the transaction. - **from_state** (string) - Required - The origin state for the transaction. - **from_city** (string) - Required - The origin city for the transaction. - **from_street** (string) - Required - The origin street address for the transaction. - **to_country** (string) - Required - The destination country for the transaction. - **to_zip** (string) - Required - The destination ZIP code for the transaction. - **to_state** (string) - Required - The destination state for the transaction. - **to_city** (string) - Required - The destination city for the transaction. - **to_street** (string) - Required - The destination street address for the transaction. - **amount** (number) - Required - The total amount of the order before shipping and sales tax. - **shipping** (number) - Required - The amount of shipping charged for the order. - **sales_tax** (number) - Optional - The amount of sales tax collected. If not provided, TaxJar will calculate it. ### Request Example ```json { "transaction_date": "2015/05/14", "from_country": "US", "from_zip": "93101", "from_state": "CA", "from_city": "Santa Barbara", "from_street": "1218 State St", "to_country": "US", "to_zip": "90002", "to_state": "CA", "to_city": "Los Angeles", "to_street": "123 Palm Grove Ln", "amount": 16.5, "shipping": 1.5, "sales_tax": 0.95 } ``` ### Response #### Success Response (200) - **order** (object) - Contains the details of the created order, including calculated sales tax. #### Response Example ```json { "order": { "transaction_id": "12345", "user_id": "67890", "transaction_date": "2015/05/14", "created_date": "2024-01-01T10:00:00Z", "// ... other order details ...//", "tax_total": 0.95 } } ``` #### Error Handling When invalid data is sent or an error occurs, TaxJar returns a `Taxjar.Error` object. This can be asserted to inspect the error details. ### Error Response Example ```go if err := err.(*taxjar.Error); err != nil { fmt.Println(err.Status) // e.g., 406 fmt.Println(err.Err) // e.g., "Not Acceptable" fmt.Println(err.Detail) // e.g., "transaction_id is missing, transaction_id is empty" } ``` ``` -------------------------------- ### Error Handling Example Source: https://developers.taxjar.com/api/guides/java This example demonstrates how to catch `TaxjarException` when making API calls with the TaxJar Java SDK. It includes a sample of parameters for creating an order and how to access error details like the message and status code. ```APIDOC ## Error Handling When invalid data is sent to TaxJar or an error occurs, a `TaxjarException` is thrown. This exception contains the HTTP status code and error message associated with the failure. ### Method Java (using TaxJar SDK) ### Description This code snippet demonstrates how to use a try-catch block to handle potential `TaxjarException` errors during an API call. ### Request Example ```java import com.taxjar.Taxjar; import com.taxjar.exception.TaxjarException; import com.taxjar.model.transactions.OrderResponse; import java.util.HashMap; import java.util.Map; public class ErrorHandlingExample { public static void main(String[] args) { Taxjar client = new Taxjar(System.getenv("TAXJAR_API_KEY")); try { Map params = new HashMap<>(); params.put("transaction_date", "2015/05/04"); params.put("to_country", "US"); params.put("to_zip", "90002"); params.put("to_state", "CA"); params.put("amount", 17.45); params.put("shipping", 1.5); params.put("sales_tax", 0.95); OrderResponse res = client.createOrder(params); } catch (TaxjarException e) { // Handle the exception System.err.println("Error Message: " + e.getMessage()); System.err.println("Status Code: " + e.getStatusCode()); e.printStackTrace(); } } } ``` ### Common Error Response Codes | Error Code | Meaning | |------------|-------------------------------| | 400 | Bad Request | | 401 | Unauthorized | | 403 | Forbidden | | 404 | Not Found | | 405 | Method Not Allowed | | 406 | Not Acceptable | | 410 | Gone | | 422 | Unprocessable Entity | | 429 | Too Many Requests | | 500 | Internal Server Error | | 503 | Service Unavailable | ### Resources & Help - Java Sales Tax API Reference - General TaxJar API FAQs - taxjar-java on GitHub - taxjar-java on The Central Repository ``` -------------------------------- ### Install TaxJar Ruby Gem Source: https://developers.taxjar.com/api/guides/ruby This snippet shows how to add the taxjar-ruby gem to your project's Gemfile and install it using bundler. Ensure you have Ruby and Bundler installed. ```ruby gem 'taxjar-ruby', require: 'taxjar' ``` -------------------------------- ### Java Quickstart - Authentication Source: https://developers.taxjar.com/api/guides/java Demonstrates how to authenticate the TaxJar Java client using your API token. ```APIDOC ## Authenticating the TaxJar Java Client To interact with the TaxJar API, you need to authenticate using your API token. ### Method Instantiate the `Taxjar` client with your API key. ### Parameters * **TAXJAR_API_KEY** (string) - Required - Your TaxJar API token. ### Request Example ```java import com.taxjar.Taxjar; import com.taxjar.exception.TaxjarException; public class AuthenticationExample { public static void main(String[] args) { // Method A: Use `System.getenv` to retrieve an environment variable with your TaxJar API token Taxjar client = new Taxjar(System.getenv("TAXJAR_API_KEY")); // Method B: Useful for quick testing // Taxjar client = new Taxjar("[Your TaxJar API Key]"); } } ``` **Description:** It is recommended to use environment variables to store your API token to keep sensitive credentials out of your code. ``` -------------------------------- ### Authenticate TaxJar Go Client Source: https://developers.taxjar.com/api/guides/go Demonstrates how to authenticate the TaxJar Go client using an API key, either directly or via an environment variable. It shows the initialization of the TaxJar client with configuration. ```go package main import ( "os" "github.com/taxjar/taxjar-go" ) func main() { client := taxjar.NewClient(taxjar.Config{ APIKey: "48ceecccc8af930bd02597aec0f84a78", // Useful for quick testing }) client := taxjar.NewClient(taxjar.Config{ APIKey: os.Getenv("TAXJAR_API_KEY"), // Recommended }) } ``` -------------------------------- ### Authentication API Source: https://developers.taxjar.com/api/guides/go This section explains how to authenticate with the TaxJar API using your API token. It's recommended to use an environment variable for your API key. ```APIDOC ## Authentication ### Description Authenticate your requests to the TaxJar API by providing your API token. It is recommended to use environment variables to manage sensitive credentials like API keys. ### Method N/A (Client-side configuration) ### Endpoint N/A (Client-side configuration) ### Parameters #### Request Body - **APIKey** (string) - Required - Your TaxJar API token. Can be hardcoded for testing or preferably loaded from an environment variable like `TAXJAR_API_KEY`. ### Request Example ```go package main import ( "os" "github.com/taxjar/taxjar-go" ) func main() { // For quick testing (not recommended for production) client := taxjar.NewClient(taxjar.Config{ APIKey: "YOUR_API_KEY", }) // Recommended approach using environment variable client := taxjar.NewClient(taxjar.Config{ APIKey: os.Getenv("TAXJAR_API_KEY"), }) } ``` ### Response Authentication is handled during client initialization. No specific response for authentication itself, but subsequent API calls will either succeed or fail based on the validity of the token. ``` -------------------------------- ### Install TaxJar PHP Client using Composer Source: https://developers.taxjar.com/api/guides/php This snippet shows how to add the TaxJar PHP client to your project's dependencies using Composer. It assumes you have Composer installed globally. After running this command, a `composer.json` file will be updated or created, and the library will be downloaded into your project's `vendor` directory. ```json { "require": { "taxjar/taxjar-php": "^1.5" } } ``` ```bash composer require taxjar/taxjar-php ``` -------------------------------- ### Install TaxJar .NET Client via NuGet Source: https://developers.taxjar.com/api/guides/csharp Installs the TaxJar .NET client package using the NuGet Package Manager Console. This is the first step to integrating TaxJar's sales tax API into your .NET project. ```csharp PM> Install-Package TaxJar ``` -------------------------------- ### Install TaxJar Node Client and Configure Dependencies Source: https://developers.taxjar.com/api/guides/node This snippet shows how to add the TaxJar Node.js package as a dependency in your project's package.json file. It is essential for initializing the TaxJar client. ```json { "dependencies": { "taxjar": "^2.0.0" } } ``` -------------------------------- ### Example TaxJar Sales Tax Calculation Response Source: https://developers.taxjar.com/api/guides/node A truncated example of the JSON response received after calculating sales tax for an order using the TaxJar API. It shows key details like the total order amount, amount to collect, and taxability. ```json { "tax": { "order_total_amount": 16.5, "amount_to_collect": 1.16, "has_nexus": true, "freight_taxable": true, "tax_source": "destination", "breakdown": {} } } ``` -------------------------------- ### Add TaxJar Java Client Dependency Source: https://developers.taxjar.com/api/guides/java This snippet shows how to add the TaxJar Java client library to your project using Maven or Gradle. Ensure you have the correct version number. This is a prerequisite for using the TaxJar API in your Java application. ```xml com.taxjar taxjar-java 1.0.0 ``` ```gradle compile "com.taxjar:taxjar-java:1.0.0" ``` -------------------------------- ### Get Sales Tax Rate Source: https://developers.taxjar.com/api/guides/php Retrieve the sales tax rate for a specific location. This endpoint can be used to get the rate for a given ZIP code or a full address. ```APIDOC ## GET /v2/rates ### Description Retrieves the sales tax rate for a specific location. This endpoint can be used to get the rate for a given ZIP code or a full address. ### Method GET ### Endpoint /v2/rates ### Parameters #### Query Parameters - **country** (string) - Required - The country for which to retrieve the tax rate. - **state** (string) - Optional - The state for which to retrieve the tax rate. - **zip** (string) - Optional - The ZIP code for which to retrieve the tax rate. - **city** (string) - Optional - The city for which to retrieve the tax rate. - **street** (string) - Optional - The street address for which to retrieve the tax rate. ### Request Example ``` GET /v2/rates?zip=90210 ``` ### Response #### Success Response (200) - **country_rate** (number) - The sales tax rate for the country. - **state_rate** (number) - The sales tax rate for the state. - **county_rate** (number) - The sales tax rate for the county. - **city_rate** (number) - The sales tax rate for the city. - **combined_district_rate** (number) - The combined district tax rate. - **state_taxable_amount** (number) - The taxable amount for the state. - **county_taxable_amount** (number) - The taxable amount for the county. - **city_taxable_amount** (number) - The taxable amount for the city. - **combined_district_taxable_amount** (number) - The taxable amount for the combined district. - **total_rate** (number) - The total combined sales tax rate. - **jurisdictions** (object) - Details about the taxing jurisdictions. #### Response Example ```json { "country_rate": 0.05, "state_rate": 0.04, "county_rate": 0.01, "city_rate": 0, "combined_district_rate": 0, "state_taxable_amount": 100, "county_taxable_amount": 100, "city_taxable_amount": 100, "combined_district_taxable_amount": 100, "total_rate": 0.1, "jurisdictions": { ... } } ``` ``` -------------------------------- ### Calculate Sales Tax for an Order using Go Source: https://developers.taxjar.com/api/guides/go Shows how to calculate sales tax for an order using the TaxJar Go client. It includes details on passing address information, order amount, shipping, and line items. Error handling is also demonstrated. ```go package main import ( "fmt" "os" "github.com/taxjar/taxjar-go" ) func main() { client := taxjar.NewClient(taxjar.Config{ APIKey: os.Getenv("TAXJAR_API_KEY"), }) res, err := client.TaxForOrder(taxjar.TaxForOrderParams{ FromCountry: "US", FromZip: "92093", FromState: "CA", FromCity: "La Jolla", FromStreet: "9500 Gilman Dr", ToCountry: "US", ToZip: "90002", ToState: "CA", ToCity: "Los Angeles", ToStreet: "1727 E 107th St", Amount: 15, Shipping: 1.5, LineItems: []taxjar.TaxLineItem{ { ID: "1", Quantity: 1, ProductTaxCode: "20010", UnitPrice: 15, Discount: 0, }, }, }) if err != nil { // handle error } fmt.Printf("%+v", res.Tax) fmt.Println(res.Tax.AmountToCollect) } ``` -------------------------------- ### Authenticate TaxJar Client with API Key Source: https://developers.taxjar.com/api/guides/ruby Demonstrates how to initialize the TaxJar Ruby client using your API key. It shows both direct key usage for testing and recommended environment variable usage for security. ```ruby require 'taxjar' client = Taxjar::Client.new(api_key: '48ceecccc8af930bd02597aec0f84a78') # Useful for quick testing client = Taxjar::Client.new(api_key: ENV['TAXJAR_API_KEY']) # Recommended ``` -------------------------------- ### Python: Authenticate TaxJar Client Source: https://developers.taxjar.com/api/guides/python Demonstrates how to initialize the TaxJar Python client using an API key. It shows both a quick testing method with a hardcoded key and a recommended approach using environment variables for better security. ```python import taxjar client = taxjar.Client(api_key='9e0cd62a22f451701f29c3bde214') # Useful for quick testing client = taxjar.Client(api_key=os.environ.get('TAXJAR_API_KEY')) # Recommended ``` -------------------------------- ### Get Refund Transaction (PHP) Source: https://developers.taxjar.com/api/index Shows how to retrieve a refund transaction via the TaxJar PHP client. This example assumes you have installed the TaxJar SDK using Composer. It uses 'showRefund' with a transaction ID. ```php require __DIR__ . '/vendor/autoload.php'; $client = TaxJar\Client::withApiKey("9e0cd62a22f451701f29c3bde214"); $refund = $client->showRefund('321'); ``` -------------------------------- ### Configure TaxJar Sandbox Client (Go) Source: https://developers.taxjar.com/api/reference Initializes a TaxJar Go client using environment variables for the API key and the TaxJar sandbox API URL. ```go package main import ( "os" "github.com/taxjar/taxjar-go" ) func main() { client := taxjar.NewClient(taxjar.Config{ APIKey: os.Getenv("TAXJAR_SANDBOX_API_KEY"), APIURL: taxjar.SandboxAPIURL, }) } ``` -------------------------------- ### Show Customer - C# Source: https://developers.taxjar.com/api/reference Demonstrates fetching customer information using the TaxJar C# client. It initializes the API client with a key and calls the `ShowCustomer` method. ```csharp using Taxjar; var client = new TaxjarApi("9e0cd62a22f451701f29c3bde214"); var customer = client.ShowCustomer("123"); ``` -------------------------------- ### Calculate Sales Tax for an Order using TaxJar PHP Source: https://developers.taxjar.com/api/guides/php This PHP code snippet calculates sales tax for a given order using the TaxJar API. It requires the `taxjar/taxjar-php` client to be installed and authenticated. The function accepts detailed order information, including origin and destination addresses, amounts, shipping, and line items, returning a tax breakdown. ```php taxForOrder([ 'from_country' => 'US', 'from_zip' => '07102', 'from_state' => 'NJ', 'from_city' => 'Newark', 'from_street' => '49 Washington St', 'to_country' => 'US', 'to_zip' => '07306', 'to_state' => 'NJ', 'to_city' => 'Jersey City', 'to_street' => '54 Journal Square Plaza', 'amount' => 15, 'shipping' => 1.5, 'line_items' => [ [ 'quantity' => 1, 'unit_price' => 15 ] ] ]); /* Truncated Response: object(stdClass)#38 (9) { ["order_total_amount"] => float(16.5) ["shipping"] => float(1.5) ["taxable_amount"] => float(16.5) ["amount_to_collect"] => float(1.16) ["rate"] => float(0.07) ["has_nexus"] => bool(true) ["freight_taxable"] => bool(true) ["tax_source"] => string(11) "destination" ["breakdown"] => object(stdClass)#36 { ... } } */ echo $tax->amount_to_collect; echo $tax->rate; ``` -------------------------------- ### TaxJar API - Get Refund Transaction Details (Go Example) Source: https://developers.taxjar.com/api/index This Go code snippet demonstrates how to construct and send a GET request to the TaxJar API to retrieve details of an existing refund transaction. It includes the necessary parameters and shows how to handle the response. ```Go package main import ( "encoding/json" "fmt" "io/ioutil" "net/http" "strconv" ) func main() { transactionID := "12345" apiKey := "YOUR_TAXJAR_API_KEY" url := "https://api.taxjar.com/v2/transactions/refunds/" + transactionID client := &http.Client{} req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Set("Authorization", "Token token="+apiKey) req.Header.Set("Content-Type", "application/json") res, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println("Error reading response body:", err) return } var result map[string]interface{}/ err = json.Unmarshal(body, &result) if err != nil { fmt.Println("Error unmarshalling JSON:", err) return } fmt.Printf("%+v\n", result) } ``` -------------------------------- ### Show Customer - Go Source: https://developers.taxjar.com/api/reference Illustrates fetching customer details with the TaxJar Go client. It involves creating a client with configuration, including the API key, and handling potential errors from `ShowCustomer`. ```go package main import ( "fmt" "github.com/taxjar/taxjar-go" ) func main() { client := taxjar.NewClient(taxjar.Config{ APIKey: "9e0cd62a22f451701f29c3bde214", }) res, err := client.ShowCustomer("123") if err != nil { fmt.Println(err) } else { fmt.Println(res.Customer) } } ``` -------------------------------- ### TaxJar API Refund Transaction Request Example Source: https://developers.taxjar.com/api/reference This example demonstrates how to make a GET request to the TaxJar API to retrieve an existing refund transaction. It shows the endpoint structure and highlights the required `transaction_id` parameter. This is a fundamental operation for managing refund data. ```http GET https://api.taxjar.com/v2/transactions/refunds/:transaction_id ``` -------------------------------- ### Introduction Source: https://developers.taxjar.com/api/index Information about the TaxJar API, including base URLs for production and sandbox environments. ```APIDOC ## Introduction ### API Endpoint ``` https://api.taxjar.com/v2/ ``` ### Sandbox API Endpoint ``` https://api.sandbox.taxjar.com/v2/ ``` Welcome to the TaxJar Sales Tax API! You can use our API to get information on sales tax rates, categories or upload transactions. We currently provide API clients for the following languages: * Ruby Sales Tax API _via RubyGems as`taxjar-ruby`_ * Python Sales Tax API _via PyPI as`taxjar`_ * PHP Sales Tax API _via Composer as`taxjar/taxjar-php`_ * Node Sales Tax API _via NPM as`taxjar`_ * C# / .NET Sales Tax API _via NuGet as`TaxJar`_ * Java Sales Tax API _via Maven & Gradle as `com.taxjar:taxjar-java`_ * Go Sales Tax API _as`taxjar` from `github.com/taxjar/taxjar-go`_ ``` -------------------------------- ### Get Sales Tax Rates by Location (PHP) Source: https://developers.taxjar.com/api/reference Provides PHP code examples for using the TaxJar API to get sales tax rates. Demonstrates requests using ZIP codes, ZIP+4 codes, and includes optional parameters for detailed location accuracy. ```php require __DIR__ . '/vendor/autoload.php'; $client = TaxJar\Client::withApiKey("9e0cd62a22f451701f29c3bde214"); // United States (ZIP+4) $rates = $client->ratesForLocation('90404-3370'); // United States (ZIP w/ Optional Params) $rates = $client->ratesForLocation('90404', [ 'city' => 'Santa Monica', 'state' => 'CA', 'country' => 'US' ]); // United States (ZIP+4 w/ Street Address for Rooftop Accuracy) $rates = $client->ratesForLocation('05495-2086', [ 'street' => '312 Hurricane Lane', 'city' => 'Williston', 'state' => 'VT', 'country' => 'US' ]); ``` -------------------------------- ### Authentication Source: https://developers.taxjar.com/api/guides/ruby Demonstrates how to authenticate the TaxJar client using an API key, recommending environment variables for security. ```APIDOC ## Authentication ### Description Authenticates the TaxJar client by providing your API token. It's recommended to use environment variables for secure credential management. ### Method N/A (Client initialization) ### Endpoint N/A ### Parameters N/A ### Request Example ```ruby require 'taxjar' # For quick testing: client = Taxjar::Client.new(api_key: 'YOUR_API_KEY') # Recommended (using environment variable): client = Taxjar::Client.new(api_key: ENV['TAXJAR_API_KEY']) ``` ### Response N/A (Authentication is part of client setup) ### Success Response (200) N/A ### Response Example N/A ``` -------------------------------- ### Get TaxJar Nexus Regions (API) Source: https://developers.taxjar.com/api/reference Direct API call to retrieve nexus regions. This uses a simple cURL example with authentication. ```bash $ curl https://api.taxjar.com/v2/nexus/regions \ -H "Authorization: Bearer 9e0cd62a22f451701f29c3bde214" ``` -------------------------------- ### Error Handling Source: https://developers.taxjar.com/api/guides/php This section describes how TaxJar handles errors, including the exceptions thrown and a reference for common HTTP status codes. ```APIDOC ## Error Handling ### Description When invalid data is sent to TaxJar or an error occurs during processing, a `TaxJar\Exception` is thrown. This exception contains the HTTP status code and an error message. ### Method All Methods ### Endpoint All Endpoints ### Parameters None ### Request Example ```php createOrder([ 'transaction_date' => '2015/05/14', 'to_country' => 'US', 'to_zip' => '90002', 'to_state' => 'CA', 'amount' => 16.5, 'shipping' => 1.5, 'sales_tax' => 0.95 ]); } catch (TaxJar\Exception $e) { // Catch the exception and access its properties echo "Error Message: " . $e->getMessage(); echo "HTTP Status Code: " . $e->getStatusCode(); } ``` ### Response #### Error Response Codes - **400** Bad Request – Your request format is bad. - **401** Unauthorized – Your API key is wrong. - **403** Forbidden – The resource requested is not authorized for use. - **404** Not Found – The specified resource could not be found. - **405** Method Not Allowed – You tried to access a resource with an invalid method. - **406** Not Acceptable – Your request is not acceptable. - **410** Gone – The resource requested has been removed from our servers. - **422** Unprocessable Entity – Your request could not be processed. - **429** Too Many Requests – You’re requesting too many resources! Slow down! - **500** Internal Server Error – We had a problem with our server. Try again later. - **503** Service Unavailable – We’re temporarily offline for maintenance. Try again later. #### Exception Object Properties - **message** (string) - The error message returned by the API. - **statusCode** (integer) - The HTTP status code of the error response. ``` -------------------------------- ### Introduction and Endpoints Source: https://developers.taxjar.com/api/reference Overview of the TaxJar API and its base endpoints for production and sandbox environments. ```APIDOC ## Introduction ### API Endpoint `https://api.taxjar.com/v2/` ### Sandbox API Endpoint `https://api.sandbox.taxjar.com/v2/` Welcome to the TaxJar Sales Tax API! You can use our API to get information on sales tax rates, categories or upload transactions. ``` -------------------------------- ### Get TaxJar Nexus Regions (Java) Source: https://developers.taxjar.com/api/reference An example of fetching nexus regions using the TaxJar Java client. Includes basic error handling for TaxjarException. ```java import com.taxjar.Taxjar; import com.taxjar.exception.TaxjarException; import com.taxjar.model.nexus.RegionResponse; public class NexusRegionsExample { public static void main(String[] args) { Taxjar client = new Taxjar("9e0cd62a22f451701f29c3bde214"); try { RegionResponse res = client.nexusRegions(); } catch (TaxjarException e) { e.printStackTrace(); } } } ``` -------------------------------- ### TaxJar API Authentication Examples Source: https://developers.taxjar.com/api/reference Demonstrates how to authenticate with the TaxJar API using API keys across multiple programming languages. Ensure you replace the placeholder API key with your actual key. These examples cover client initialization for Ruby, Python, Node.js, PHP, .NET, Java, and Go. ```ruby require "taxjar" client = Taxjar::Client.new(api_key: "9e0cd62a22f451701f29c3bde214") ``` ```python import taxjar client = taxjar.Client(api_key='9e0cd62a22f451701f29c3bde214') ``` ```javascript const Taxjar = require('taxjar'); const client = new Taxjar({ apiKey: '9e0cd62a22f451701f29c3bde214' }); ``` ```php require __DIR__ . '/vendor/autoload.php'; $client = TaxJar\Client::withApiKey("9e0cd62a22f451701f29c3bde214"); ``` ```csharp using Taxjar; var client = new TaxjarApi("9e0cd62a22f451701f29c3bde214"); ``` ```java import com.taxjar.Taxjar; import com.taxjar.exception.TaxjarException; public class AuthenticationExample { public static void main(String[] args) { Taxjar client = new Taxjar("9e0cd62a22f451701f29c3bde214"); } } ``` ```go package main import "github.com/taxjar/taxjar-go" func main() { client := taxjar.NewClient(taxjar.Config{ APIKey: "9e0cd62a22f451701f29c3bde214", }) } ``` -------------------------------- ### Sales Tax Calculations Source: https://developers.taxjar.com/api/guides/php Calculate sales tax for an order by providing origin and destination addresses, order amount, shipping costs, and line items. ```APIDOC ## POST /v2/taxes ### Description Calculates the sales tax for a given order based on origin and destination addresses, order amount, shipping, and line items. ### Method POST ### Endpoint /v2/taxes ### Parameters #### Request Body - **from_country** (string) - Required - The country of origin for the shipment. - **from_zip** (string) - Required - The ZIP code of origin for the shipment. - **from_state** (string) - Required - The state of origin for the shipment. - **from_city** (string) - Optional - The city of origin for the shipment. - **from_street** (string) - Optional - The street address of origin for the shipment. - **to_country** (string) - Required - The destination country for the shipment. - **to_zip** (string) - Required - The destination ZIP code for the shipment. - **to_state** (string) - Required - The destination state for the shipment. - **to_city** (string) - Optional - The destination city for the shipment. - **to_street** (string) - Optional - The destination street address for the shipment. - **amount** (number) - Required - The total amount of the order, excluding shipping. - **shipping** (number) - Required - The total shipping amount for the order. - **line_items** (array) - Optional - An array of line item objects, each with quantity, unit_price, and optionally product_tax_code. - **quantity** (number) - Required - The quantity of the item. - **unit_price** (number) - Required - The unit price of the item. - **product_tax_code** (string) - Optional - The TaxJar product tax code for the item. ### Request Example ```json { "from_country": "US", "from_zip": "07102", "from_state": "NJ", "from_city": "Newark", "from_street": "49 Washington St", "to_country": "US", "to_zip": "07306", "to_state": "NJ", "to_city": "Jersey City", "to_street": "54 Journal Square Plaza", "amount": 15, "shipping": 1.5, "line_items": [ { "quantity": 1, "unit_price": 15 } ] } ``` ### Response #### Success Response (200) - **order_total_amount** (number) - The total amount of the order including shipping. - **shipping** (number) - The shipping amount for the order. - **taxable_amount** (number) - The amount of the order that is subject to tax. - **amount_to_collect** (number) - The total amount of tax to collect. - **rate** (number) - The sales tax rate for the order. - **has_nexus** (boolean) - Indicates if the seller has nexus in the destination state. - **freight_taxable** (boolean) - Indicates if shipping is taxable. - **tax_source** (string) - The tax calculation method used (e.g., 'destination'). - **breakdown** (object) - A detailed breakdown of tax by jurisdiction. #### Response Example ```json { "order_total_amount": 16.5, "shipping": 1.5, "taxable_amount": 16.5, "amount_to_collect": 1.16, "rate": 0.07, "has_nexus": true, "freight_taxable": true, "tax_source": "destination", "breakdown": { ... } } ``` ``` -------------------------------- ### Show Customer - Java Source: https://developers.taxjar.com/api/reference Provides an example of retrieving customer data using the TaxJar Java SDK. It includes necessary imports, client initialization with an API key, and exception handling for the `showCustomer` call. ```java import com.taxjar.Taxjar; import com.taxjar.exception.TaxjarException; import com.taxjar.model.transactions.CustomerResponse; public class ShowCustomerExample { public static void main(String[] args) { Taxjar client = new Taxjar("9e0cd62a22f451701f29c3bde214"); try { CustomerResponse res = client.showCustomer("123"); } catch (TaxjarException e) { e.printStackTrace(); } } } ``` -------------------------------- ### Get TaxJar Nexus Regions (Python) Source: https://developers.taxjar.com/api/reference Fetches nexus regions using the TaxJar Python client. Ensure the 'taxjar' library is installed and provide your API key. ```python import taxjar client = taxjar.Client(api_key='9e0cd62a22f451701f29c3bde214') nexus_regions = client.nexus_regions() ``` -------------------------------- ### Show Customer - PHP Source: https://developers.taxjar.com/api/reference Provides an example of retrieving customer data using the TaxJar PHP client. It includes autoloading dependencies, initializing the client with an API key, and calling `showCustomer`. ```php require __DIR__ . '/vendor/autoload.php'; $client = TaxJar\Client::withApiKey("9e0cd62a22f451701f29c3bde214"); $customer = $client->showCustomer('123'); ``` -------------------------------- ### Get TaxJar Nexus Regions (Node.js) Source: https://developers.taxjar.com/api/reference Obtains nexus regions via the TaxJar Node.js client. This example demonstrates asynchronous handling with Promises. Requires the 'taxjar' package. ```javascript const Taxjar = require('taxjar'); const client = new Taxjar({ apiKey: '9e0cd62a22f451701f29c3bde214' }); client.nexusRegions().then(res => { res.regions; // Array of nexus regions }); ``` -------------------------------- ### Create Sales Tax Order using TaxJar API in Go Source: https://developers.taxjar.com/api/guides/go This Go code snippet demonstrates how to create a sales tax order using the TaxJar API. It requires the taxjar-go client library and an API key. The function takes various order details as input and returns the created order or an error. ```go package main import ( "fmt" "os" "github.com/taxjar/taxjar-go" ) func main() { client := taxjar.NewClient(taxjar.Config{ APIKey: os.Getenv("TAXJAR_API_KEY"), }) res, err := client.CreateOrder(taxjar.CreateOrderParams { TransactionID: "123", TransactionDate: "2015/05/14", FromCountry: "US", FromZip: "93101", FromState: "CA", FromCity: "Santa Barbara", FromStreet: "1218 State St", ToCountry: "US", ToZip: "90002", ToState: "CA", ToCity: "Los Angeles", ToStreet: "123 Palm Grove Ln", Amount: 16.5, Shipping: 1.5, SalesTax: 0.95, LineItems: []taxjar.OrderLineItem{ { ID: "1", Quantity: 1, ProductIdentifier: "12-34243-9", Description: "Fuzzy Widget", ProductTaxCode: "20010", UnitPrice: 15.0, SalesTax: 0.95, }, }, }) if err != nil { // handle error } fmt.Printf("%+v", res.Order) fmt.Println(res.Order.TransactionID) fmt.Println(res.Order.SalesTax) } ```