data-src=../../../../../includes/commerce-only.md

addPurchaseOrderItemsToCart mutation

The addPurchaseOrderItemsToCart mutation adds all purchase order items to the shopping cart. The request must specify a cart_id and a purchase_order_uid. If the value of replace_existing_cart_items is set to true, the mutation deletes the pre-existing items from the purchase order. Otherwise, the mutation merges the pre-existing items with the new items.

Syntax

mutation {
  addPurchaseOrderItemsToCart(
    input: AddPurchaseOrderItemsToCartInput!
  ){
    AddProductsToCartOutput
  }
}

Reference

The addPurchaseOrderItemsToCart reference provides detailed information about the types and fields defined in this mutation.

Example usage

The following example adds all purchase order items to the shopping cart.

Request:

mutation {
  addPurchaseOrderItemsToCart(
    input: {
      purchase_order_uid: "MQ==",
      cart_id: "hJUrIcPm77uCyYkSTBRGyjSvS40mw1Qd",
      replace_existing_cart_items: false
    }
  ) {
    cart {
      id
      items {
        product {
          sku
        }
      }
    }
    user_errors {
      message
      code
    }
  }
}

Response:

{
  "data": {
    "addPurchaseOrderItemsToCart": {
      "cart": {
        "id": "hJUrIcPm77uCyYkSTBRGyjSvS40mw1Qd",
        "items": [
          {
            "product": {
              "sku": "Simple-product"
            }
          }
        ]
      },
      "user_errors": []
    }
  }
}