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 API functions that enable you to programmatically control behavior, fetch data, and integrate with Adobe Commerce backend services.

Version: 0.0.1
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..

addPurchaseOrderComment

Adds a comment to a purchase order.

const addPurchaseOrderComment = async (
uid: string,
comment: string
): Promise<PurchaseOrderCommentModel>
ParameterTypeReq?Description
uidstringYesSee function signature above
commentstringYesSee function signature above

Events

Does not emit any drop-in events.

Returns

Returns PurchaseOrderCommentModel.


addPurchaseOrderItemsToCart

Adds purchase order items to a cart.

const addPurchaseOrderItemsToCart = async (
purchaseOrderUid: string,
cartId: string,
replaceExistingCartItems: boolean = false
): Promise<CartModel>
ParameterTypeReq?Description
purchaseOrderUidstringYesSee function signature above
cartIdstringYesThe unique identifier for the shopping cart. This ID is used to track and persist cart data across sessions.
replaceExistingCartItemsbooleanNoSee function signature above

Events

Does not emit any drop-in events.

Returns

Returns CartModel.


approvePurchaseOrders

Approves one or more purchase orders.

const approvePurchaseOrders = async (
uids: string | string[]
): Promise<{
errors: { message: string; type: string }[];
purchaseOrders: PurchaseOrderModel[];
}>
ParameterTypeReq?Description
uidsstring | string[]YesSee function signature above

Events

Does not emit any drop-in events.

Returns

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


cancelPurchaseOrders

Cancels one or more purchase orders.

const cancelPurchaseOrders = async (
uids: string | string[]
): Promise<{
errors: { message: string; type: string }[];
purchaseOrders: PurchaseOrderModel[];
}>
ParameterTypeReq?Description
uidsstring | string[]YesSee function signature above

Events

Does not emit any drop-in events.

Returns

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


createPurchaseOrderApprovalRule

Creates a new purchase order approval rule.

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

Events

Does not emit any drop-in events.

Returns

Returns PurchaseOrderApprovalRuleModel.


currencyInfo

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 }[];
}>

Events

Does not emit any drop-in events.

Returns

Returns:

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

deletePurchaseOrderApprovalRule

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[]YesSee function signature above

Events

Does not emit any drop-in events.

Returns

Returns:

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

getPurchaseOrder

Gets a single purchase order by UID.

const getPurchaseOrder = async (
uid: string
): Promise<{
purchaseOrder: PurchaseOrderModel;
}>
ParameterTypeReq?Description
uidstringYesSee function signature above

Events

Does not emit any drop-in events.

Returns

Returns Promise<{ purchaseOrder: PurchaseOrderModel; }>. See PurchaseOrderModel.


getPurchaseOrderApprovalRule

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

Events

Does not emit any drop-in events.

Returns

Returns PurchaseOrderApprovalRuleModel.


getPurchaseOrderApprovalRuleMetadata

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

const getPurchaseOrderApprovalRuleMetadata = async (): Promise<PurchaseOrderApprovalRuleMetadataModel>

Events

Does not emit any drop-in events.

Returns

Returns PurchaseOrderApprovalRuleMetadataModel.


getPurchaseOrderApprovalRules

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
currentPagenumberNoSee function signature above
pageSizenumberNoSee function signature above

Events

Does not emit any drop-in events.

Returns

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


getPurchaseOrders

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
pageSizenumberNoSee function signature above
currentPagenumberNoSee function signature above

Events

Does not emit any drop-in events.

Returns

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


placeOrderForPurchaseOrder

Places an order from an approved purchase order.

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

Events

Does not emit any drop-in events.

Returns

Returns CustomerOrderModel.


placePurchaseOrder

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.

Events

Emits the purchase-order/placed event.

Returns

Returns { purchaseOrder: PurchaseOrderModel }. See PurchaseOrderModel.


rejectPurchaseOrders

Rejects one or more purchase orders.

const rejectPurchaseOrders = async (
uids: string | string[]
): Promise<{
errors: { message: string; type: string }[];
purchaseOrders: PurchaseOrderModel[];
}>
ParameterTypeReq?Description
uidsstring | string[]YesSee function signature above

Events

Does not emit any drop-in events.

Returns

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


updatePurchaseOrderApprovalRule

Updates an existing purchase order approval rule.

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

Events

Does not emit any drop-in events.

Returns

Returns PurchaseOrderApprovalRuleModel.


validatePurchaseOrders

Validates one or more purchase orders.

const validatePurchaseOrders = async (
uids: string | string[]
): Promise<{
errors: { message: string; type: string }[];
purchaseOrders: PurchaseOrderModel[];
}>
ParameterTypeReq?Description
uidsstring | string[]YesSee function signature above

Events

Does not emit any drop-in events.

Returns

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


Data Models

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

CartModel

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;
}>;
}

CustomerOrderModel

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;
}

PurchaseOrderApprovalRuleMetadataModel

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

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

PurchaseOrderApprovalRuleModel

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;
}>;
}[];
}

PurchaseOrderCommentModel

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;
};
}

PurchaseOrderModel

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;
};
}