> ## 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.

export const CreateVendorInASDiagram = () => {
  const [isDark, setIsDark] = useState(false);
  useEffect(() => {
    const check = () => setIsDark(document.documentElement.classList.contains("dark"));
    check();
    const observer = new MutationObserver(check);
    observer.observe(document.documentElement, {
      attributes: true,
      attributeFilter: ["class"]
    });
    return () => observer.disconnect();
  }, []);
  const nodeFill = isDark ? "#212222" : "#EEF4F4";
  const nodeStroke = isDark ? "#848989" : "#E1E6E6";
  const nodeTextStyle = isDark ? ",color:#EEF4F4" : ",color:#131414";
  const s2Fill = isDark ? "#212222" : "#EEF4F4";
  const s2Stroke = isDark ? "#848989" : "#212222";
  const s2TextStyle = isDark ? ",color:#EEF4F4" : ",color:#212222";
  const linkStyle = isDark ? "" : "linkStyle default stroke:#848989,stroke-width:1px;";
  const diagram = `
%%{init: {"themeVariables": {"fontSize": "10px"}}}%%
flowchart LR
    S1["1. Create Vendor in the AS"] --> S2["AS-assigned externalId<br>(+ optional code)"]

click S1 "#1-create-the-vendor-in-the-as"

style S1 white-space:normal,fill:${nodeFill},stroke:${nodeStroke}${nodeTextStyle}
style S2 white-space:normal,fill:${s2Fill},stroke:${s2Stroke},stroke-dasharray:5 5${s2TextStyle}
${linkStyle}
`;
  return <Mermaid chart={diagram} />;
};

export const VendorCreationWorkflowDiagramTopNav = ({highlight}) => {
  const [isDark, setIsDark] = useState(false);
  useEffect(() => {
    const check = () => setIsDark(document.documentElement.classList.contains("dark"));
    check();
    const observer = new MutationObserver(check);
    observer.observe(document.documentElement, {
      attributes: true,
      attributeFilter: ["class"]
    });
    return () => observer.disconnect();
  }, []);
  const nodeFill = isDark ? "#212222" : "#EEF4F4";
  const nodeStroke = isDark ? "#848989" : "#E1E6E6";
  const nodeTextStyle = isDark ? ",color:#EEF4F4" : ",color:#131414";
  const subgraphFill = isDark ? "#131414" : "#ffffff";
  const subgraphStroke = isDark ? "#848989" : "#6B7070";
  const subgraphTextStyle = isDark ? ",color:#EEF4F4" : ",color:#6B7070";
  const linkStyle = isDark ? "" : "linkStyle default stroke:#848989,stroke-width:1px;";
  const highlightStyle = highlight ? `style ${highlight} stroke:#FEB6FE,stroke-width:2px` : "";
  const diagram = `
%%{init: {"themeVariables": {"fontSize": "16px"}}}%%
flowchart LR

subgraph Pleo1["Pleo"]
    A["1. Create Vendor in Pleo"]
end

subgraph Integration["Integration"]
    B["2. Detect Draft<br>Vendor<br>"]
    C["3. Create Vendor<br>in AS<br>"]
    B --> C
end

subgraph Pleo2["Pleo"]
    D["4. Activate Vendor in Pleo"]
end

A --> B
C --> D

click A "/docs/current/how-tos/accounting-integrations/vendors/how-to-create-vendors-in-pleo"
click B "/docs/current/how-tos/accounting-integrations/vendors/how-to-detect-draft-vendors"
click C "/docs/current/how-tos/accounting-integrations/vendors/how-to-create-vendor-in-as"
click D "/docs/current/how-tos/accounting-integrations/vendors/how-to-activate-vendor-in-pleo"

style A white-space:normal,fill:${nodeFill},stroke:${nodeStroke}${nodeTextStyle}
style B white-space:normal,fill:${nodeFill},stroke:${nodeStroke}${nodeTextStyle}
style C white-space:normal,fill:${nodeFill},stroke:${nodeStroke}${nodeTextStyle}
style D white-space:normal,fill:${nodeFill},stroke:${nodeStroke}${nodeTextStyle}

style Pleo1 fill:${subgraphFill},stroke:${subgraphStroke}${subgraphTextStyle}
style Integration fill:${subgraphFill},stroke:${subgraphStroke}${subgraphTextStyle}
style Pleo2 fill:${subgraphFill},stroke:${subgraphStroke}${subgraphTextStyle}

${highlightStyle}
${linkStyle}
`;
  return <Mermaid chart={diagram} />;
};

export const WhatComesNext = ({children, href}) => <div className="mt-4">
    <a href={href} className="btn-primary">
      {children} →
    </a>
  </div>;

export const NoteCallout = ({title, children}) => <div className="callout-box callout-note">
    <div className="callout-row">
      <span className="callout-icon">
        <svg width="22" height="22" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M208,104a79.86,79.86,0,0,1-30.59,62.92A24.29,24.29,0,0,0,168,186v6a8,8,0,0,1-8,8H96a8,8,0,0,1-8-8v-6a24.11,24.11,0,0,0-9.3-19A79.87,79.87,0,0,1,48,104.45C47.76,61.09,82.72,25,126.07,24A80,80,0,0,1,208,104Z" opacity="0.2" /><path d="M176,232a8,8,0,0,1-8,8H88a8,8,0,0,1,0-16h80A8,8,0,0,1,176,232Zm40-128a87.55,87.55,0,0,1-33.64,69.21A16.24,16.24,0,0,0,176,186v6a16,16,0,0,1-16,16H96a16,16,0,0,1-16-16v-6a16,16,0,0,0-6.23-12.66A87.59,87.59,0,0,1,40,104.49C39.74,56.83,78.26,17.14,125.88,16A88,88,0,0,1,216,104Zm-16,0a72,72,0,0,0-73.74-72c-39,.92-70.47,33.39-70.26,72.39a71.65,71.65,0,0,0,27.64,56.3A32,32,0,0,1,96,186v6h64v-6a32.15,32.15,0,0,1,12.47-25.35A71.65,71.65,0,0,0,200,104Zm-16.11-9.34a57.6,57.6,0,0,0-46.56-46.55,8,8,0,0,0-2.66,15.78c16.57,2.79,30.63,16.85,33.44,33.45A8,8,0,0,0,176,104a9,9,0,0,0,1.35-.11A8,8,0,0,0,183.89,94.66Z" /></svg>
      </span>
      <div>
        {title && <div className="callout-title">
            {title}
          </div>}
        <div className="callout-body">
          {children}
        </div>
      </div>
    </div>
  </div>;

export const RememberCallout = ({title, children}) => <div className="callout-box callout-remember">
    <div className="callout-row">
      <span className="callout-icon">
        <svg width="22" height="22" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" fill="currentColor"><path d="M229.66,98.34,172.39,155.8c11.46,22.93-1.72,45.86-10.11,57a8,8,0,0,1-12,.83L42.34,105.76A8,8,0,0,1,43,93.85c29.65-23.92,57.4-10,57.4-10l57.27-57.46a8,8,0,0,1,11.31,0L229.66,87A8,8,0,0,1,229.66,98.34Z" opacity="0.2" /><path d="M235.32,81.37,174.63,20.69a16,16,0,0,0-22.63,0L98.37,74.49c-10.66-3.34-35-7.37-60.4,13.14a16,16,0,0,0-1.29,23.78L85,159.71,42.34,202.34a8,8,0,0,0,11.32,11.32L96.29,171l48.29,48.29A16,16,0,0,0,155.9,224c.38,0,.75,0,1.13,0a15.93,15.93,0,0,0,11.64-6.33c19.64-26.1,17.75-47.32,13.19-60L235.33,104A16,16,0,0,0,235.32,81.37ZM224,92.69h0l-57.27,57.46a8,8,0,0,0-1.49,9.22c9.46,18.93-1.8,38.59-9.34,48.62L48,100.08c12.08-9.74,23.64-12.31,32.48-12.31A40.13,40.13,0,0,1,96.81,91a8,8,0,0,0,9.25-1.51L163.32,32,224,92.68Z" /></svg>
      </span>
      <div>
        {title && <div className="callout-title">
            {title}
          </div>}
        <div className="callout-body">
          {children}
        </div>
      </div>
    </div>
  </div>;

<VendorCreationWorkflowDiagramTopNav highlight="C" />

<div className="border-[1px] rounded-none p-4 bg-[#ffffff] border-[#FEB6FE] dark:bg-[#131414] dark:border-[#FEB6FE]">
  <CreateVendorInASDiagram />
</div>

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](/docs/current/how-tos/accounting-integrations/vendors/how-to-detect-draft-vendors), which covers detecting the `DRAFT` Vendor in Pleo.

## Prerequisites

Before you begin:

* You have completed [How to Detect Draft Vendors](/docs/current/how-tos/accounting-integrations/vendors/how-to-detect-draft-vendors) 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](/docs/current/how-tos/accounting-integrations/vendors/how-to-detect-draft-vendors) scenario: a `DRAFT` Vendor "Greenfield Logistics" was detected in Pleo with `id: c27ed4d6-3d3d-458e-8f3f-735fdf32a3bc`.

## Steps

<RememberCallout title="Remember">
  While this Vendor is being created and activated, a [Vendor Sync](/docs/current/how-tos/accounting-integrations/imports/vendors/how-to-create-vendors) run could happen at the same time and archive or duplicate it.

  <br />

  <br />

  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.

  <br />

  <br />

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

  <br />

  <br />

  See [Interaction with Vendor Sync](/docs/current/integration-design/exports/vendors/integration-design-vendor-creation-create-and-activate#interaction-with-vendor-sync) for the full race this prevents.
</RememberCallout>

### 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
```

<RememberCallout title="Remember">
  This request is made against the Accounting System's own API, not Pleo's. The exact request shape depends on the target AS.
</RememberCallout>

<NoteCallout title="Note">
  `registrationNumber` and `taxRegistrationNumber` may arrive from Pleo as an empty string (`""`) when not set, see the note in [How to Detect Draft Vendors](/docs/current/how-tos/accounting-integrations/vendors/how-to-detect-draft-vendors#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."
</NoteCallout>

#### 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
```

<RememberCallout title="Remember">
  If a retry can't confirm whether a previous attempt already created the AS record, creating a new one anyway risks a duplicate.

  <br />

  <br />

  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).

  <br />

  <br />

  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.

  <br />

  <br />

  See [If AS Creation Fails](/docs/current/integration-design/exports/vendors/integration-design-vendor-creation-create-and-activate#if-as-creation-fails) for the full failure-handling design this follows.
</RememberCallout>

***

## 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?

<WhatComesNext href="/docs/current/how-tos/accounting-integrations/vendors/how-to-activate-vendor-in-pleo">
  How to Activate a Vendor in Pleo
</WhatComesNext>

***

<div className="text-xs uppercase" style={{ fontVariant: 'small-caps' }}>
  this how-to is part of:
</div>

<div className="mt-4 flex flex-wrap gap-2">
  <a
    href="/docs/current/guides/vendor-creation-workflow-guide"
    className="inline-flex items-center rounded-full border border-gray-300 dark:border-gray-600
px-3 py-1 text-xs font-medium
bg-white dark:bg-[#1f262b] text-black dark:text-white
hover:bg-gray-100 dark:hover:bg-[#2b2f33]
transition-colors"
  >
    Vendor Creation Workflow Guide
  </a>
</div>

***

## Related Reading

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

***
