### Install Dependencies with Bun Source: https://github.com/nytely-official/quickbooks-api/blob/main/CONTRIBUTING.md Installs project dependencies using the Bun package manager. Ensure Bun version 1.2.1 or higher is installed before running this command. ```bash bun install ``` -------------------------------- ### Install QuickBooks API SDK Source: https://github.com/nytely-official/quickbooks-api/blob/main/README.md Instructions for installing the QuickBooks API SDK using either Bun or npm package managers. ```bash bun add quickbooks-api # or npm install quickbooks-api ``` -------------------------------- ### Initialize QuickBooks API Client Source: https://github.com/nytely-official/quickbooks-api/blob/main/README.md Illustrates the initialization of the ApiClient for QuickBooks, requiring an authenticated AuthProvider and specifying the environment (e.g., Sandbox). ```typescript import { ApiClient, Environment } from 'quickbooks-api'; const apiClient = new ApiClient(authProvider, Environment.Sandbox); ``` -------------------------------- ### Run Tests with Bun Source: https://github.com/nytely-official/quickbooks-api/blob/main/CONTRIBUTING.md Executes the project's test suite using the Bun test runner. All tests must pass before submitting a pull request. ```bash bun test ``` -------------------------------- ### Initialize Auth Provider Source: https://github.com/nytely-official/quickbooks-api/blob/main/README.md Demonstrates how to initialize the AuthProvider for QuickBooks API, including client ID, client secret, redirect URI, and required scopes. ```typescript import { AuthProvider, Environment, AuthScopes } from 'quickbooks-api'; const authProvider = new AuthProvider('YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', 'YOUR_REDIRECT_URI', [ AuthScopes.Accounting, AuthScopes.OpenId, ]); ``` -------------------------------- ### Fetch Paginated Invoices Source: https://github.com/nytely-official/quickbooks-api/blob/main/README.md Demonstrates how to fetch invoices from the QuickBooks API, including handling pagination and applying search options like maximum results and ordering. ```typescript import { ApiClient, Environment, InvoiceStatus, InvoiceOptions } from 'quickbooks-api'; // Example: Get all invoices (with search options and pagination) let hasNextPage = true; let page = 1; const paginatedInvoices = []; while (hasNextPage) { // Setup the Invoice const invoiceOptions: InvoiceOptions = { searchOptions: { maxResults: 10, page: page, orderBy: { field: 'Id', direction: 'DESC' }, }, }; // Get the Invoices const searchResponse = await apiClient.invoices.getAllInvoices(invoiceOptions); // Add the Invoices to the List paginatedInvoices.push(...searchResponse.results); // Check if there is a next page hasNextPage = searchResponse.hasNextPage; // Increment the Page page++; } // Get the list of Paid Invoice const paidInvoices = await apiClient.invoices.getAllInvoices({ status: InvoiceStatus.Paid }); ``` -------------------------------- ### Generate Authorization URL Source: https://github.com/nytely-official/quickbooks-api/blob/main/README.md Shows how to generate the authorization URL required to initiate the OAuth 2.0 flow for QuickBooks API authentication. Users should be redirected to this URL. ```typescript const authUrl = authProvider.generateAuthUrl(); // Redirect user to authUrl.toString() ``` -------------------------------- ### Handle QuickBooks API Callback Source: https://github.com/nytely-official/quickbooks-api/blob/main/README.md Provides a function to handle the callback from QuickBooks after user authorization, exchanging the authorization code for an access token and logging it. ```typescript import type { UserAuthResponse } from 'quickbooks-api'; async function handleCallback(query: UserAuthResponse) { try { const token = await authProvider.exchangeCode(query.code, query.realmId); console.log('Access Token:', token.accessToken); } catch (error) { console.error('Authentication failed:', error); } } ``` -------------------------------- ### QuickBooks API Token Management Source: https://github.com/nytely-official/quickbooks-api/blob/main/README.md Details the methods available on the AuthProvider for managing access tokens, including refreshing, revoking, and securely serializing/deserializing tokens for storage. ```typescript // `refresh()`: Refreshes the access token. // `revoke()`: Revokes the access token. // `serializeToken(secretKey: string)`: Securely encrypts and serializes the token for storage. // `deserializeToken(serialized: string, secretKey: string)`: Decrypts and restores the serialized token. // Important: Store tokens securely using `serializeToken` and `deserializeToken`. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.