AlmondTill/G3N API

addPurchaseOrderLines

mutation · in the family Purchasing

What it does

Add more lines to a purchase order you have not sent yet — the way a big order gets built up.

Append lines to a draft PurchaseOrder: the same per-line gates as create (the variant tenant-scoped + active + stocked, the receiving LF active + owned by the buying org, the unit cost in the PO currency, requireCatalogItem ⇒ a live OVI, quantity ≥ the OVI moq); the distinct variant × receiving-LF law holds over the whole document (a key already on the order refuses VALIDATION/INVALID naming the holding lineNo); lineNo mints from the monotonic nextLineNo; the document total refuses past the ceiling. ONE transaction — the row Puts + the header rollups. A live post-draft doc refuses CONFLICT/REF_STATE. Requires the doc current revision + the unrestricted capability. NO reason — the edit class.

Before you call

A bearer session from an API key (see Authentication and key hygiene) or a signed-in user.

Capability area: Purchasing — Purchase orders, returns to vendors, vendor invoices and supplier records.

Roles that may call it:

What happens

Each new line takes the next line number on the order; a number already used is never handed out again, so receipts and vendor bills keep pointing at the same line forever.

Careful

Only while the order is still a draft. The same product going to the same receiving location can appear once — raise that line’s quantity instead of adding a second one.

Arguments

NameTypeRequiredNotes
inputAddPurchaseOrderLinesInput AddPurchaseOrderLinesInput!yesAppend-input for addPurchaseOrderLines.
revisionID ID!yesThe revision id you read on the record; the change is refused if an edit landed in the meantime.

Concurrency

Send the record’s current revision from your last read as revision. A stale revision is refused as CONFLICT/REVISION_STALE — read the record again and retry with the new value.

Returns

PurchaseOrder PurchaseOrder! — A purchase order: an org orders variants x quantities x receiving LFs from ONE enabled vendor (the OrgVendor enablement — immutable at birth). Lines live in their OWN rows since and stay draft-editable wholesale; currency is the OrgVendor purchasingCurrency snapshot; received/closed_short are immutable non-doomed history; cancelled is the ONE doomed terminal (lists filter it). Re-running the same verb resumes a stalled walk; on a healthy in-flight order it refuses CONFLICT/IN_PROGRESS naming the progress.

Example request

graphql
mutation ExampleAddPurchaseOrderLines($input: AddPurchaseOrderLinesInput!, $revision: ID!) {
  addPurchaseOrderLines(input: $input, revision: $revision) {
    id
    sysId
    type
    caption
    status
    parentId
    rootId
    createdAt
    updatedAt
    revisionNum
    revision
    orgVendorId
    currency
    paymentTerms
    incotermCode
    vendorReference
    notes
    lineCount
    openLineCount
    nextLineNo
    receivingReceiptId
  }
}

Variables:

json
{
  "input": {
    "purchaseOrderId": "01900000-0000-7000-8000-da3499da0000",
    "lines": [
      {
        "variantId": "01900000-0000-7000-8000-8433b0260000",
        "logicalFacilityId": "01900000-0000-7000-8000-10c08c590000"
      }
    ]
  },
  "revision": "01900000-0000-7000-8000-b7960e180000"
}

Send it with the envelope naming the version: "extensions": {"at": {"version": {"name":"genesis","number":0}}}.

Example response

json
{
  "data": {
    "addPurchaseOrderLines": {
      "id": "01900000-0000-7000-8000-da3499da0000",
      "sysId": "PO-EXMP-0000-000F",
      "type": "PurchaseOrder",
      "caption": "Blue jeans",
      "status": "draft",
      "parentId": "01900000-0000-7000-8000-eacdfcfd0000",
      "rootId": "01900000-0000-7000-8000-a1295a650000",
      "createdAt": "2027-01-31T00:00:00.000Z",
      "updatedAt": "2027-01-31T00:00:00.000Z",
      "revisionNum": 1,
      "revision": "01900000-0000-7000-8000-53c6eea90000",
      "orgVendorId": "01900000-0000-7000-8000-67df2a7f0000",
      "currency": "USD",
      "paymentTerms": "<payment terms>",
      "incotermCode": "BJ-001",
      "vendorReference": "<vendor reference>",
      "notes": "Restock before the weekend.",
      "lineCount": 1,
      "openLineCount": 1,
      "nextLineNo": 1,
      "receivingReceiptId": "01900000-0000-7000-8000-1c0205630000"
    }
  },
  "extensions": {
    "at": {
      "callId": "01EXAMPLE-CALL-ID",
      "version": {
        "requested": {
          "name": "genesis",
          "number": 0
        },
        "serviced": {
          "name": "genesis",
          "number": 0
        }
      }
    }
  }
}

Errors this call can answer