Developer Resources > Examples

Purchase Orders

When managing Purchase Orders you might want to use the Public API to integrate.

In this case, the actions you will have to perform are quite simple

  1. Create a Purchase Order
  2. Add inventory when receiving
  3. Change the quantity received from the purchase order
  4. Change the purchase order status

Create a Purchase Order

This is the very first part of managing Purchase Orders via Public API, an example of what the purchase_order_create mutation looks like is the following:

mutation {
  purchase_order_create(
    data: {
      po_date: "2020-01-01"
      po_number: "TestPOExample"
      subtotal: "230:00"
      shipping_price: "0.00"
      total_price: "230.00"
      warehouse_id: "V2FyZWhvdXNlOjgwNzU="
      line_items: [
        {
          sku: "testSKU12345"
          quantity: 5
          expected_weight_in_lbs: "1.00"
          vendor_id: "VmVuZG9yOjE1NjE2Mw=="
          quantity_received: 0
          quantity_rejected: 0
          price: "230.00"
          product_name: "Product for testing Purchase Orders"
          fulfillment_status: "pending"
          sell_ahead: 0
        }
      ]
      fulfillment_status: "pending"
      discount: "0.00"
      vendor_id: "VmVuZG9yOjE1NjE2Mw=="
    }
  ) {
    request_id
    complexity
  }
}

Add inventory when receiving

The next thing you might want to do with the Purchase Order is to start receiving the products into the warehouse. To be able to do this you can use the inventory_add mutation

mutation{
  inventory_add(data:{
    sku:"12258196226120",
    warehouse_id:"V2FyZWhvdXNlOjgwNzU=",
    quantity:1000
    reason: "Added from PO Nr.123"
  }){
    request_id
    complexity
    warehouse_product{
      id
    account_id
    on_hand
    inventory_bin
    }
  }
}

And add inventory for all the products in the Purchase Order.

If you have many products you could also use the Inventory Sync feature to bulk add them.

Change the quantity received from the purchase order

Now that you added the quantity on the products you will need to change the received quantity for the products inside the Purchase Order.

To be able to do this, you will have to use the purchase_order_update to update the quantity_received

mutation {
  purchase_order_update(
    data: {
      po_id: "503386"
      line_items: { sku: "1122334457", quantity_received: 1 }
    }
  ) {
    request_id
    complexity
  }
}

NOTE:

  • The quantity_received amount is accumulative, so each time you send the mutation it will add that amount to the received quantity. For example, if you send the mutation above twice, the quantity_received will be 2

Change the purchase order status

The last step is to close the Purchase Order after all the items are received.

To be able to do this you will need to use the purchase_order_close mutation

mutation{
  purchase_order_close(data: {
    po_id:"503387"
  }){
    request_id
    complexity
  }
}

NOTE:

  • This mutation will only change the purchase order status, but it will not affect inventory.