UNPKG

@agnostack/taxjar-request

Version:

Please contact agnoStack via info@agnostack.com for any questions

98 lines (78 loc) 2.04 kB
# @agnostack/taxjar-request > 🎮 Minimal [TaxJar](https://developers.taxjar.com/api/reference/) API request library for Node ## Installation ```bash yarn add @agnostack/taxjar-request # npm install @agnostack/taxjar-request ``` ## Quickstart (OAuth) ```js const { createClient } = require('@agnostack/taxjar-request'); // import { createClient } from '@agnostack/taxjar-request' const taxjar = new createClient({ api_key: '...' // taxjar API Token. }); taxjar .get('categories') .then(console.log) .catch(console.error); taxjar .post('taxes', { to_country: 'US', to_zip: '60056', to_state: 'IL', shipping: 10, amount: 290, nexus_addresses: [ { country: 'US', state: 'IL' } ] }) .then(console.log) .catch(console.error); taxjar .put('transactions/orders/123', { amount: 17, shipping: 2, line_items: [ { quantity: 1, product_identifier: '12-34234-0', unit_price: 15, discount: 0, sales_tax: 0.95 } ] }) .then(console.log) .catch(console.error); ``` ## Kitchen sink ```js const taxjar = new createClient({ api_key: '...', api_domain: '...', version: 'v2', headers: { // ... } }); ``` ## Custom headers per request The API provides you the ability to send various request headers that change the way data is stored or retrieved. By default this library will encode all data as JSON, however you can customise this by setting your own `Content-Type` header as an additional argument to `get`, `post`, `put` and `delete`. **Note**: If you add the `Content-Type` custom header to `post`, `put` or `delete` you will need to encode `data` yourself. ```js const taxjar = new createClient({ api_key: '...' }); const headers = { 'X-My-Header': 'custom' }; taxjar .get('products/types', headers) .then(console.log) .catch(console.error); ``` _Contact [Adam Grohs](https://www.linkedin.com/in/adamgrohs/) @ [agnoStack](https://agnostack.com/) for any questions._