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

@balancer-team/quickbooks

v0.0.15

Published

QuickBooks JavaScript Client

Downloads

929

Readme

QuickBooks JavaScript Client

JavaScript client for QuickBooks. Easily connect to the QuickBooks API. Make queries and create objects. TypeScript definitions are built in.

Install

npm i @balancer-team/quickbooks

Configure

import { QuickBooks } from '@balancer-team/quickbooks'

export const qb = new QuickBooks({
  clientId: 'YOUR_CLIENT_ID',
  clientSecret: 'YOUR_CLIENT_SECRET',
  redirectUri: 'YOUR_REDIRECT_URI',
  environment: 'SANDBOX_OR_PRODUCTION',
})

Get Auth URL

Begin the OAuth 2.0 flow by getting the auth url.

const authUrl = qb.getAuthUrl()

Get Access Token from Grant

Complete the OAuth 2.0 flow by using the grant details to retrieve the access token.

const token = await qb.getTokenFromGrant({
  code: 'GRANT_CODE',
  state: 'STATE_STRING',
  realmId: 'REALM_ID',
})

Access and Refresh Tokens

The token is an object that includes the access and refresh tokens, the realm ID, expirations, and other metadata. Tokens aren't stored in the qb instance. You must write your own application logic to manage tokens. This makes it easier to create multi-tenant applications, where different tokens have to be used for different users.

Intuit's access tokens are valid for one hour, and refresh tokens are valid for 100 days. You should ensure you are using an active access token by calling the following function. If the access token is still valid, it will simply return the token. If it needs to be refreshed, it will send the request to Intuit and obtain the refreshed token.

const validToken = await qb.getValidToken(staleToken) // -->
// {
//   access_token: 'eyJlbmMiOiJBMTI4...',
//   refresh_token: 'AB11734177244q21...',
//   token_type: 'bearer',
//   realm_id: '8241451349686734',
//   expires_in: 3600,
//   expires_at: 1725454384,
//   x_refresh_token_expires_in: 8726400,
//   x_refresh_token_expires_at: 1733918044,
// }

General-purpose Query Request

The QuickBooks API uses queries to access resources. Unlike most APIs, It is not necessary to specify an endpoint when retrieving a resource. Instead, the resource is specified in a SQL-like query language. Refer to the API Explorer for structuring your queries.

const vendors = await qb.query({
  token: token,
  query: 'select * from Vendor',
})

General-purpose Post Request

Use any endpoint and create any object using a general-purpose post request. Refer to the API Explorer for endpoints and object structures.

const createdJournalEntry = await qb.post({
  token: token,
  endpoint: '/journalentry',
  body: newJournalEntry,
})