Skip to content

Search is only available in production builds. Try building and previewing the site to test it out locally.

Purchase Order Functions

The Purchase Order drop-in provides 12 API functions for managing the complete purchase order workflow, including adding items to cart, approving, rejecting, canceling, and tracking purchase order status.

Version: 1.0.0
FunctionDescription
addPurchaseOrderCommentAdds a comment to a purchase order..
addPurchaseOrderItemsToCartAdds purchase order items to a cart..
approvePurchaseOrdersApproves one or more purchase orders..
cancelPurchaseOrdersCancels one or more purchase orders..
createPurchaseOrderApprovalRuleCreates a new purchase order approval rule..
currencyInfoAn async function that fetches currency information including the base currency code and available currency codes from GraphQL API..
deletePurchaseOrderApprovalRuleDeletes one or more purchase order approval rules..
getPurchaseOrderGets a single purchase order by UID..
getPurchaseOrderApprovalRuleRetrieves a specific purchase order approval rule by its unique identifier.
getPurchaseOrderApprovalRuleMetadataGets the current user’s purchase order approval rule metadata..
getPurchaseOrderApprovalRulesGets the current user’s purchase order approval rules with pagination support..
getPurchaseOrdersGets a list of purchase orders with optional filtering and pagination..
placeOrderForPurchaseOrderPlaces an order from an approved purchase order..
placePurchaseOrderPlaces a purchase order from a cart..
rejectPurchaseOrdersRejects one or more purchase orders..
updatePurchaseOrderApprovalRuleUpdates an existing purchase order approval rule..
validatePurchaseOrdersValidates one or more purchase orders..

Adds a comment to a purchase order.

const addPurchaseOrderComment = async (
uid: string,
comment: string
): Promise<PurchaseOrderCommentModel>
ParameterTypeReq?Description
uidstringYesThe unique identifier for the purchase order to which the comment will be added.
commentstringYesThe text content of the comment to add to the purchase order. Use this to provide context, approval notes, or communication between team members reviewing the purchase order.

Does not emit any drop-in events.

Returns PurchaseOrderCommentModel.

Adds purchase order items to a cart.

const addPurchaseOrderItemsToCart = async (
purchaseOrderUid: string,
cartId: string,
replaceExistingCartItems: boolean = false
): Promise<CartModel>
ParameterTypeReq?Description
purchaseOrderUidstringYesThe unique identifier for the purchase order containing the items to add to the cart.
cartIdstringYesThe unique identifier for the shopping cart. This ID is used to track and persist cart data across sessions.
replaceExistingCartItemsbooleanNoA boolean flag controlling cart merge behavior. When `true`, replaces all existing cart items with the purchase order items. When `false` (default), appends the purchase order items to existing cart contents.

Does not emit any drop-in events.

Returns CartModel.

Approves one or more purchase orders.

const approvePurchaseOrders = async (
uids: string | string[]
): Promise<{
errors: { message: string; type: string }[];
purchaseOrders: PurchaseOrderModel[];
}>
ParameterTypeReq?Description
uidsstring | string[]YesOne or more purchase order unique identifiers to approve. Can be a single UID string or an array of UIDs for batch approval operations.

Does not emit any drop-in events.

Promise<{
errors: { message: string; type: string }[];
purchaseOrders: PurchaseOrderModel[];
}>

See PurchaseOrderModel.

Cancels one or more purchase orders.

const cancelPurchaseOrders = async (
uids: string | string[]
): Promise<{
errors: { message: string; type: string }[];
purchaseOrders: PurchaseOrderModel[];
}>
ParameterTypeReq?Description
uidsstring | string[]YesOne or more purchase order unique identifiers to cancel. Can be a single UID string or an array of UIDs for batch cancellation operations.

Does not emit any drop-in events.

Promise<{
errors: { message: string; type: string }[];
purchaseOrders: PurchaseOrderModel[];
}>

See PurchaseOrderModel.

Creates a new purchase order approval rule.

const createPurchaseOrderApprovalRule = async (
input: any
): Promise<PurchaseOrderApprovalRuleModel>
ParameterTypeReq?Description
inputanyYesInput parameters for the operation.

Does not emit any drop-in events.

Returns PurchaseOrderApprovalRuleModel.

An async function that fetches currency information including the base currency code and available currency codes from GraphQL API.

const currencyInfo = async (): Promise<{
baseCurrencyCode: string;
availableCurrencyCodes: { text: string; value: string }[];
}>

Does not emit any drop-in events.

Promise<{
baseCurrencyCode: string;
availableCurrencyCodes: { text: string; value: string }[];
}>

Deletes one or more purchase order approval rules.

const deletePurchaseOrderApprovalRule = async (
uids: string | string[]
): Promise<{
deletePurchaseOrderApprovalRule: {
errors: { message?: string; type?: string }[];
};
}>
ParameterTypeReq?Description
uidsstring | string[]YesOne or more approval rule unique identifiers to delete. Can be a single UID string or an array of UIDs for batch deletion. This permanently removes the approval rules from the purchase order workflow.

Does not emit any drop-in events.

Promise<{
deletePurchaseOrderApprovalRule: {
errors: { message?: string; type?: string }[];
};
}>

Gets a single purchase order by UID.

const getPurchaseOrder = async (
uid: string
): Promise<{
purchaseOrder: PurchaseOrderModel;
}>
ParameterTypeReq?Description
uidstringYesThe unique identifier for the purchase order to retrieve. Returns complete purchase order details including items, status, history, comments, and approval information.

Does not emit any drop-in events.

Promise<{
purchaseOrder: PurchaseOrderModel;
}>

See PurchaseOrderModel.

Retrieves a specific purchase order approval rule by its unique identifier. This function fetches detailed information about an approval rule including its configuration, applicable roles, approval conditions, and approvers.

const getPurchaseOrderApprovalRule = async (
id: string
): Promise<PurchaseOrderApprovalRuleModel>
ParameterTypeReq?Description
idstringYesSee function signature above

Does not emit any drop-in events.

Returns PurchaseOrderApprovalRuleModel.

Gets the current user’s purchase order approval rule metadata.

const getPurchaseOrderApprovalRuleMetadata = async (): Promise<PurchaseOrderApprovalRuleMetadataModel>

Does not emit any drop-in events.

Returns PurchaseOrderApprovalRuleMetadataModel.

Gets the current user’s purchase order approval rules with pagination support.

const getPurchaseOrderApprovalRules = async (
currentPage: number = DEFAULT_PAGE_INFO.currentPage,
pageSize: number = DEFAULT_PAGE_INFO.pageSize
): Promise<{
totalCount: number;
pageInfo: {
currentPage: number;
pageSize: number;
totalPages: number;
};
items: PurchaseOrderApprovalRuleModel[];
}>
ParameterTypeReq?Description
currentPagenumberNoThe page number for pagination (1-indexed). Used to navigate through multiple pages of approval rules.
pageSizenumberNoThe number of approval rules to return per page. Controls how many rules appear on each page of results.

Does not emit any drop-in events.

Promise<{
totalCount: number;
pageInfo: {
currentPage: number;
pageSize: number;
totalPages: number;
};
items: PurchaseOrderApprovalRuleModel[];
}>

See PurchaseOrderApprovalRuleModel.

Gets a list of purchase orders with optional filtering and pagination.

const getPurchaseOrders = async (
filter?: any,
pageSize: number = 20,
currentPage: number = 1
): Promise<{
totalCount: number;
pageInfo: {
currentPage: number;
pageSize: number;
totalPages: number;
};
purchaseOrderItems: PurchaseOrderModel[];
}>
ParameterTypeReq?Description
filteranyNoSee function signature above
pageSizenumberNoThe number of purchase orders to return per page. Controls how many orders appear on each page of results.
currentPagenumberNoThe page number for pagination (1-indexed). Used to navigate through multiple pages of purchase orders.

Does not emit any drop-in events.

Promise<{
totalCount: number;
pageInfo: {
currentPage: number;
pageSize: number;
totalPages: number;
};
purchaseOrderItems: PurchaseOrderModel[];
}>

See PurchaseOrderModel.

Places an order from an approved purchase order.

const placeOrderForPurchaseOrder = async (
purchaseOrderUid: string
): Promise<CustomerOrderModel>
ParameterTypeReq?Description
purchaseOrderUidstringYesSee function signature above

Does not emit any drop-in events.

Returns CustomerOrderModel.

Places a purchase order from a cart.

const placePurchaseOrder = async (
cartId: string
): Promise<{ purchaseOrder: PurchaseOrderModel }>
ParameterTypeReq?Description
cartIdstringYesThe unique identifier for the shopping cart. This ID is used to track and persist cart data across sessions.

Emits the purchase-order/placed event.

Returns { purchaseOrder: PurchaseOrderModel }. See PurchaseOrderModel.

Rejects one or more purchase orders.

const rejectPurchaseOrders = async (
uids: string | string[]
): Promise<{
errors: { message: string; type: string }[];
purchaseOrders: PurchaseOrderModel[];
}>
ParameterTypeReq?Description
uidsstring | string[]YesOne or more purchase order unique identifiers to reject. Can be a single UID string or an array of UIDs for batch rejection operations.

Does not emit any drop-in events.

Promise<{
errors: { message: string; type: string }[];
purchaseOrders: PurchaseOrderModel[];
}>

See PurchaseOrderModel.

Updates an existing purchase order approval rule.

const updatePurchaseOrderApprovalRule = async (
input: any
): Promise<PurchaseOrderApprovalRuleModel>
ParameterTypeReq?Description
inputanyYesInput parameters for the operation.

Does not emit any drop-in events.

Returns PurchaseOrderApprovalRuleModel.

Validates one or more purchase orders.

const validatePurchaseOrders = async (
uids: string | string[]
): Promise<{
errors: { message: string; type: string }[];
purchaseOrders: PurchaseOrderModel[];
}>
ParameterTypeReq?Description
uidsstring | string[]YesOne or more purchase order unique identifiers to validate. Checks whether the purchase orders exist, are in a valid state, and can be processed for the requested operation.

Does not emit any drop-in events.

Promise<{
errors: { message: string; type: string }[];
purchaseOrders: PurchaseOrderModel[];
}>

See PurchaseOrderModel.

The following data models are used by functions in this drop-in.

The CartModel object is returned by the following functions: addPurchaseOrderItemsToCart.

interface CartModel {
cart: {
id: string;
items: {
uid: string;
quantity: number;
product: {
uid: string;
name: string;
sku: string;
};
}[];
pagination?: {
currentPage: number;
pageSize: number;
totalPages: number;
totalCount: number;
};
};
userErrors: Array<{
message: string;
}>;
}

The CustomerOrderModel object is returned by the following functions: placeOrderForPurchaseOrder.

interface CustomerOrderModel {
appliedCoupons: Coupon[];
appliedGiftCards: GiftCard[];
availableActions: string[];
billingAddress: CustomerAddress;
carrier: string;
comments: string[];
creditMemos: any[];
customerInfo: CustomerInfo;
email: string;
giftMessage: string;
giftReceiptIncluded: boolean;
giftWrapping: any;
id: string;
invoices: any[];
isVirtual: boolean;
items: OrderItem[];
itemsEligibleForReturn: any[];
number: string;
orderDate: string;
orderStatusChangeDate: string;
paymentMethods: PaymentMethod[];
printedCardIncluded: boolean;
returns: any;
shipments: Shipment[];
shippingAddress: CustomerAddress;
shippingMethod: string;
status: string;
token: string;
total: OrderTotal;
}

The PurchaseOrderApprovalRuleMetadataModel object is returned by the following functions: getPurchaseOrderApprovalRuleMetadata.

interface PurchaseOrderApprovalRuleMetadataModel {
availableAppliesTo: CompanyRole[];
availableRequiresApprovalFrom: CompanyRole[];
}

The PurchaseOrderApprovalRuleModel object is returned by the following functions: createPurchaseOrderApprovalRule, getPurchaseOrderApprovalRule, getPurchaseOrderApprovalRules, updatePurchaseOrderApprovalRule.

interface PurchaseOrderApprovalRuleModel {
createdAt: string;
createdBy: string;
description: string;
updatedAt: string;
name: string;
status: string;
uid: string;
appliesToRoles: {
id: string;
name: string;
usersCount: number;
permissions: Array<{
id: string;
sortOrder: number;
text: string;
}>;
}[];
condition: {
attribute: string;
operator: string;
quantity: number;
amount: {
currency: string;
value: number;
};
};
approverRoles: {
id: string;
name: string;
usersCount: number;
permissions: Array<{
id: string;
sortOrder: number;
text: string;
}>;
}[];
}

The PurchaseOrderCommentModel object is returned by the following functions: addPurchaseOrderComment.

interface PurchaseOrderCommentModel {
createdAt: string;
text: string;
uid: string;
author: {
allowRemoteShoppingAssistance: boolean;
confirmationStatus: string;
createdAt: string;
dateOfBirth: string;
email: string;
firstname: string;
gender: number;
jobTitle: string;
lastname: string;
middlename: string;
prefix: string;
status: string;
structureId: string;
suffix: string;
telephone: string;
};
}

The PurchaseOrderModel object is returned by the following functions: approvePurchaseOrders, cancelPurchaseOrders, getPurchaseOrder, getPurchaseOrders, placePurchaseOrder, rejectPurchaseOrders, validatePurchaseOrders.

interface PurchaseOrderModel {
typename: string;
uid: string;
number: string;
status: string;
availableActions: string[];
approvalFlow:
| {
ruleName: string;
events: Array<{
message: string;
name: string;
role: string;
status: string;
updatedAt: string;
}>;
}[]
| [];
comments?: Array<{
uid: string;
createdAt: string;
author: {
firstname: string;
lastname: string;
email: string;
};
text: string;
}>;
createdAt: string;
updatedAt: string;
createdBy: {
firstname: string;
lastname: string;
email: string;
};
historyLog?: Array<{
activity: string;
createdAt: string;
message: string;
uid: string;
}>;
quote: QuoteProps | null;
order: {
orderNumber: string;
id: string;
};
}