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

# How to Create a Vendor in the AS

> For Vendor Creation, how to create a vendor record in the Accounting System from a DRAFT Pleo vendor, and handle a failed attempt safely.

This how-to covers creating the vendor record in the Accounting System from a detected `DRAFT` Pleo Vendor.

Run this after [How to Detect Draft Vendors](https://developers.pleo.io/docs/current/how-tos/accounting-integrations/vendors/how-to-detect-draft-vendors.md), which covers detecting the `DRAFT` Vendor in Pleo.

## Prerequisites

Before you begin:

* You have completed [How to Detect Draft Vendors](https://developers.pleo.io/docs/current/how-tos/accounting-integrations/vendors/how-to-detect-draft-vendors.md) and have the `DRAFT` Vendor's details and Pleo `id`
* Your integration can call the target Accounting System's own API to create a vendor record

## Scenario

This how-to continues from the [How to Detect Draft Vendors](https://developers.pleo.io/docs/current/how-tos/accounting-integrations/vendors/how-to-detect-draft-vendors.md) scenario: a `DRAFT` Vendor "Greenfield Logistics" was detected in Pleo with `id: c27ed4d6-3d3d-458e-8f3f-735fdf32a3bc`.

## Steps

Remember

While this Vendor is being created and activated, a [Vendor Sync](https://developers.pleo.io/docs/current/how-tos/accounting-integrations/imports/vendors/how-to-create-vendors.md) run could happen at the same time and archive or duplicate it.

To prevent that, your integration needs to hold the per-company concurrency lock before starting this step. It's the same lock Vendor Sync uses.

Keep holding it through [How to Activate a Vendor in Pleo](https://developers.pleo.io/docs/current/how-tos/accounting-integrations/vendors/how-to-activate-vendor-in-pleo.md) too. Only let it go once activation succeeds, or once you abandon this Vendor under your own retry-abandonment policy.

See [Interaction with Vendor Sync](https://developers.pleo.io/docs/current/integration-design/exports/vendors/integration-design-vendor-creation-create-and-activate.md#interaction-with-vendor-sync) for the full race this prevents.

### 1. Create the Vendor in the AS

Using the `DRAFT` Vendor's `name`, `country`, `defaultCurrency`, `registrationNumber`, and `taxRegistrationNumber`, create the corresponding vendor record in the Accounting System.

**Example Pseudo:**

```pseudo theme={null}
asVendor = createVendorInAS({
    name:                  draftVendor.name,
    country:               draftVendor.country,
    defaultCurrency:       draftVendor.defaultCurrency,
    registrationNumber:    draftVendor.registrationNumber,
    taxRegistrationNumber: draftVendor.taxRegistrationNumber,
    // If the AS supports a custom reference/memo field, store draftVendor.id
    // (and draftVendor.companyId, for multi-company integrations) here now.
    // Handling Edge Cases below needs this for exact retry lookups, not name matching.
    referenceField:        draftVendor.id
})

// asVendor now has an AS-assigned identifier, used as externalId,
// and optionally an AS-assigned account code, used as code
```

Remember

This request is made against the Accounting System's own API, not Pleo's. The exact request shape depends on the target AS.

Note

`registrationNumber` and `taxRegistrationNumber` may arrive from Pleo as an empty string (`""`) when not set, see the note in [How to Detect Draft Vendors](https://developers.pleo.io/docs/current/how-tos/accounting-integrations/vendors/how-to-detect-draft-vendors.md#example-webhook-payload). Normalise these before sending them to the AS, most systems expect an omitted field or `null` rather than an empty string for "no value."

#### Example Result

| Field | Value |
| - | - |
| AS-assigned identifier (→ `externalId`) | `AS-VENDOR-7841` |
| AS-assigned account code (→ `code`) | `2041` |

***

## Handling Edge Cases

**AS creation fails:** do not call activate. Leave the Vendor as `DRAFT` in Pleo and retry on the next detection cycle.

```pseudo theme={null}
try:
    asVendor = createVendorInAS(draftVendor)
    activateVendor(draftVendor.id, asVendor.externalId, asVendor.code)
catch ASCreationError:
    log("Failed to create vendor in AS, will retry")
    // leave vendor as DRAFT, do not call activate
```

Remember

If a retry can't confirm whether a previous attempt already created the AS record, creating a new one anyway risks a duplicate.

To avoid that, check for an existing AS vendor first. The match must be exact, not fuzzy: don't match on `name`, since two distinct vendors can share a name (false positive), or the AS can normalise the name on save (false negative).

Instead, where the Accounting System supports a custom reference or memo field on vendor records, store the `DRAFT` Vendor's Pleo `id` there at creation time. If your integration serves multiple Pleo companies against the same AS, also store the `companyId`. Use that stored `id` (and `companyId`) for retry lookups.

See [If AS Creation Fails](https://developers.pleo.io/docs/current/integration-design/exports/vendors/integration-design-vendor-creation-create-and-activate.md#if-as-creation-fails) for the full failure-handling design this follows.

***

## Result

The table below recaps the outcome for this Vendor so far.

| Vendor | Pleo State Before | Action | Pleo State After |
| - | - | - | - |
| Greenfield Logistics | DRAFT | Created in AS | DRAFT (unchanged) |

The vendor now exists in the Accounting System, with an AS-assigned `externalId` and, optionally, a `code`. It remains `DRAFT` in Pleo until you report these identifiers back via activation.

***

## What Comes Next?

[How to Activate a Vendor in Pleo →](https://developers.pleo.io/docs/current/how-tos/accounting-integrations/vendors/how-to-activate-vendor-in-pleo.md)

***

this how-to is part of:

[Vendor Creation Workflow Guide](https://developers.pleo.io/docs/current/guides/vendor-creation-workflow-guide.md)

***

## Related Reading

* [How to Detect Draft Vendors](https://developers.pleo.io/docs/current/how-tos/accounting-integrations/vendors/how-to-detect-draft-vendors.md)
* [How to Activate a Vendor in Pleo](https://developers.pleo.io/docs/current/how-tos/accounting-integrations/vendors/how-to-activate-vendor-in-pleo.md)
* [Create and Activate Vendors Integration Design](https://developers.pleo.io/docs/current/integration-design/exports/vendors/integration-design-vendor-creation-create-and-activate.md)
* [Platform Capabilities: Vendor Creation](https://developers.pleo.io/docs/current/platform/exports/vendors/vendor-creation-overview.md)

***
