# Create Purchase Bill — Xero Accounting

> Creates a new purchase bill.

- Key: `xero_accounting_api-xero-create-purchase-bill`
- Type: Action (Write)
- Version: 0.1.4
- App: Xero Accounting (`xero_accounting_api`) — https://pipedream.com/apps/xero-accounting-api.md
- This page (HTML): https://pipedream.com/apps/xero-accounting-api/actions/xero-create-purchase-bill
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/xero_accounting_api/actions/xero-create-purchase-bill/xero-create-purchase-bill.mjs

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `tenantId` | `string` | Yes | Select an organization tenant to use, or provide a tenant ID Options are loaded from the connected account. |
| `contactId` | `string` | No | ID of the contact associated to the invoice. Options are loaded from the connected account. |
| `contactName` | `string` | No | Name of the contact associated to the invoice. If there is no contact matching this name, a new contact is created. |
| `lineItems` | `any` | Yes | See LineItems. The LineItems collection can contain any number of individual LineItem sub-elements. At least * one * is required to create a complete Invoice. |
| `date` | `string` | No | Date invoice was issued - YYYY-MM-DD. If the Date element is not specified it will default to the current date based on the timezone setting of the organisation. |
| `dueDate` | `string` | No | Date invoice is due - YYYY-MM-DD. |
| `lineAmountType` | `string` | No | Line amounts are exclusive of tax by default if you don't specify this element. See Line Amount Types |
| `purchaseBillNumber` | `string` | No | Non-unique alpha numeric code identifying purchase bill (printable ASCII characters only). This value will also display as Reference in the UI. |
| `reference` | `string` | No | Additional reference number (max length = 255) |
| `brandingThemeId` | `string` | No | See BrandingThemes |
| `url` | `string` | No | URL link to a source document - shown as "Go to [appName]" in the Xero app |
| `currencyCode` | `string` | No | The currency that invoice has been raised in (see Currencies) |
| `currencyRate` | `string` | No | The currency rate for a multicurrency invoice. If no rate is specified, the XE.com day rate is used. (max length = [18].[6]) |
| `status` | `string` | No | See Invoice Status Codes |
| `sentToContact` | `string` | No | Boolean to set whether the invoice in the Xero app should be marked as "sent". This can be set only on invoices that have been approved |
| `plannedPaymentDate` | `string` | No | Shown on purchase bills (Accounts Payable) when this has been set |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "xero_accounting_api",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "xero_accounting_api-xero-create-purchase-bill",
  arguments: {
    tenantId: "Tenant ID",
    contactId: "Contact ID",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "xero_accounting_api-xero-create-purchase-bill",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    xero_accounting_api: { authProvisionId: "apn_xxxxxxx" },
    tenantId: "Tenant ID",
    contactId: "Contact ID",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "xero_accounting_api-xero-create-purchase-bill",
    "configured_props": {
      "xero_accounting_api": { "authProvisionId": "apn_xxxxxxx" },
      "tenantId": "Tenant ID",
      "contactId": "Contact ID"
    }
  }'
```

---

- App: https://pipedream.com/apps/xero-accounting-api.md · All apps: https://pipedream.com/apps
