> ## Documentation Index
> Fetch the complete documentation index at: https://docs.glue.wtf/llms.txt
> Use this file to discover all available pages before exploring further.

# QuickBooks Online Example Glues

> React to QuickBooks Online events and combine invoice data with Slack.

## Log newly created customers

This Glue runs whenever a customer is created in the connected QuickBooks Online company and logs the webhook event.

```typescript theme={null}
import { glue } from "jsr:@streak-glue/runtime";

glue.quickbooks.onCustomerCreated((event): void => {
  console.log("New QuickBooks customer created:", event);
});
```

## Send new invoice details to Slack

QuickBooks webhook events contain the company and entity IDs, but not the full invoice. This Glue uses those IDs to fetch the invoice and its customer from the QuickBooks Online Accounting API, then posts the details to the `#new-invoices` Slack channel.

```typescript theme={null}
import { glue } from "jsr:@streak-glue/runtime";

const quickBooksCredentials = glue.quickbooks.createCredentialFetcher();
const slackCredentials = glue.slack.createBotMessageSendingCredentialFetcher();

glue.quickbooks.onInvoiceCreated(async (event): Promise<void> => {
  const { accessToken, realmId } = await quickBooksCredentials.get();
  const headers = {
    Accept: "application/json",
    Authorization: `Bearer ${accessToken}`,
  };

  const invoiceResponse = await fetch(
    `https://quickbooks.api.intuit.com/v3/company/${realmId}/invoice/${event.intuitentityid}`,
    { headers },
  );
  const invoice = (await invoiceResponse.json()).Invoice;

  const customerResponse = await fetch(
    `https://quickbooks.api.intuit.com/v3/company/${realmId}/customer/${invoice.CustomerRef.value}`,
    { headers },
  );
  const customer = (await customerResponse.json()).Customer;

  // Slack channel names do not include the leading # here.
  await glue.slack.sendMessageAsBot(
    slackCredentials,
    "new-invoices",
    `New invoice ${invoice.DocNumber} for ${customer.DisplayName}: $${invoice.TotalAmt}`,
  );
});
```
