# Create Invoice — Alegra

> Creates a new invoice in Alegra. See the documentation

- Key: `alegra-create-invoice`
- Type: Action (Write)
- Version: 0.0.3
- App: Alegra (`alegra`) — https://pipedream.com/apps/alegra.md
- This page (HTML): https://pipedream.com/apps/alegra/actions/create-invoice
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/alegra/actions/create-invoice/create-invoice.mjs

## Description

Creates a new invoice in Alegra. [See the documentation](https://developer.alegra.com/reference/post_invoices)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `status` | `string` | No | Status of the invoice. If this attribute is not sent and no associated payments are sent, the invoice is created in "draft". If payments are sent to the invoice, the invoice is created in "open". |
| `numberTemplateId` | `string` | No | Number template ID for the invoice. You can use this to automatically numbering. |
| `numberTemplatePrefix` | `string` | No | Number template prefix for the invoice. Send in case the numbering is manual. (Optional) |
| `numberTemplateNumber` | `string` | No | Number template number for the invoice. Send in case the numbering is manual. (Required) |
| `items` | `string[]` | Yes | Array of item objects (products/services) associated with the invoice. Example: [{"id": "123", "name": "Name", "price": "12.00", "quantity": "2"}]. See the documentation for further information. |
| `payments` | `string[]` | No | Array of objects indicating the payments made to the invoice. Example: [{"date": "YYYY-MM-DD", "account": "123123", "amount": "10,00"}]. See the documentation for further information. |
| `estimate` | `string` | No | Specifies the identifier of the quote you want to associate with the sales invoice, in this way, the quote is invoiced and the items specified in the items parameter are associated, not those in the quote. |
| `termsConditions` | `string` | No | Terms and conditions of the invoice. Maximum allowed length: 500. |
| `annotation` | `string` | No | Invoice notes, visible in the PDF or printed document. Maximum allowed length: 500. |
| `dueDate` | `string` | Yes | Invoice due date. Format yyyy-MM-dd. |
| `date` | `string` | Yes | Invoice date. Format yyyy-MM-dd. |
| `observations` | `string` | No | Invoice observations (not visible in the PDF or printed document). Maximum allowed length: 500. |
| `client` | `integer` | Yes | Client associated with the invoice Options are loaded from the connected account. |
| `seller` | `string` | No | Seller associated with the invoice. Options are loaded from the connected account. |
| `pricelist` | `string` | No | Price list associated with the invoice Options are loaded from the connected account. |
| `currency` | `object` | No | Object that includes the information of the currency and exchange rate associated with the invoice. It should only be included if the company has the multi-currency functionality active and has configured the selected currency. It must include the currency code (three letters according to ISO) and the exchange rate. |
| `retentions` | `string[]` | No | Array of retention objects indicating the retentions of the sales invoice. Example: [{"id": "123123", "amount": 10}]. See the documentation for further information. |
| `warehouse` | `string` | No | Warehouse associated with the invoice Options are loaded from the connected account. |
| `remissions` | `string[]` | No | Array of identifiers of the remissions to be invoiced, you can associate one or more remissions by simply indicating the id of each one in an array. The client of the remissions and the sales invoice must be the same. Only open remissions can be invoiced. In this way, the items of each remission will be invoiced, and you can also specify other items with the items parameter. Example: [{"id": 123, "items": [{"id": 123}], }]. See the documentation for further information. |
| `costCenter` | `string` | No | Cost center associated with the invoice Options are loaded from the connected account. |
| `comments` | `string[]` | No | Array of strings with each of the comments to be associated. Comments can be updated even if the sales invoice cannot be edited. |
| `periodicity` | `string` | No | Indicates the periodicity of the payments of the invoice installments. If you want to issue the invoice, the payment method is on credit this attribute becomes mandatory. |

## 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": "alegra",
      },
    },
  },
)

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: "alegra-create-invoice",
  arguments: {
    status: "Status",
    numberTemplateId: "Number Template 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: "alegra-create-invoice",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    alegra: { authProvisionId: "apn_xxxxxxx" },
    status: "Status",
    numberTemplateId: "Number Template 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": "alegra-create-invoice",
    "configured_props": {
      "alegra": { "authProvisionId": "apn_xxxxxxx" },
      "status": "Status",
      "numberTemplateId": "Number Template ID"
    }
  }'
```

---

- App: https://pipedream.com/apps/alegra.md · All apps: https://pipedream.com/apps
