# Create Credit Note — Xero Accounting

> Creates a new credit note.

- Key: `xero_accounting_api-create-credit-note`
- 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/create-credit-note
- Hints: destructive · open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/xero_accounting_api/actions/create-credit-note/create-credit-note.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 credit note Options are loaded from the connected account. |
| `contactName` | `string` | No | Name of the contact associated to the credit note. If there is no contact matching this name, a new contact is created. |
| `contactNumber` | `string` | No | Number of the contact associated to the credit note. If there is no contact matching this name, a new contact is created. |
| `type` | `string` | Yes | See Credit Note Types |
| `date` | `string` | No | The date the credit note is issued YYYY-MM-DD. If the Date element is not specified then it will default to the current date based on the timezone setting of the organisation |
| `status` | `string` | No | See Credit Note Status Codes |
| `lineAmountTypes` | `string` | No | See Invoice Line Amount Types |
| `lineItems` | `object` | No | See Invoice Line Items |
| `currencyCode` | `string` | No | Currency used for the Credit Note |
| `creditNoteNumber` | `string` | No | ACCRECCREDIT - Unique alpha numeric code identifying credit note ( when missing will auto-generate from your Organisation Invoice Settings) ACCPAYCREDIT - non-unique alpha numeric code identifying credit note. This value will also display as Reference in the UI. |
| `reference` | `string` | No | ACCRECCREDIT only - additional reference number |
| `sentToContact` | `boolean` | No | Boolean to indicate if a credit note has been sent to a contact via the Xero app (currently read only) |
| `currencyRate` | `string` | No | The currency rate for a multicurrency invoice. If no rate is specified, the XE.com day rate is used |
| `brandingThemeId` | `string` | No | See BrandingThemes |

## 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-create-credit-note",
  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-create-credit-note",
  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-create-credit-note",
    "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
