Purchase order line items are very simple - they contain a part, along with its quantity and unit cost. You can only create, edit, and delete line items if the purchase order's state is in draft
, pending_approval
, or rejected
. If you try to make any changes to a purchase order's line items outside those state, you will get a HTTP 403 (Forbidden) error.
After you create a purchase order, it will be in a draft
state. Once you have the purchase order's number, you can hit the /purchase_orders/:number/purchase_order_line_items
url to create, edit, or delete line items.
Below is an example of creating a line item for purchase order #123:
curl https://secure.fleetio.com/api/v1/purchase_orders/123/purchase_order_line_items \
-H 'Authorization: Token token="API_KEY"' \
-H "Account-Token: ACCOUNT_TOKEN" \
-H "Content-Type: application/json" \
-X POST -d '{
"part_id": 12345,
"quantity": 12,
"unit_cost": 44.56",
}'
In response, you will get something like:
{
"id": 29152,
"part_id": 12345,
"quantity": 12,
"total_quantity_received": null,
"part_number": "Your part",
"unit_cost": 44.56,
"subtotal": 534.72,
"created_at": "2017-08-10T13:48:14.401-05:00",
"updated_at": "2017-08-10T13:49:39.689-05:00"
}
If you change your mind about the line item's quantity, you can perform a PATCH
with the new line item id:
curl https://secure.fleetio.com/api/v1/purchase_orders/123/purchase_order_line_items/29152 \
-H 'Authorization: Token token="API_KEY"' \
-H "Account-Token: ACCOUNT_TOKEN" \
-H "Content-Type: application/json" \
-X PATCH -d '{
"quantity": 1
}'
And finally, if you decided you don't want this line item anymore, just DELETE
it:
curl https://secure.fleetio.com/api/v1/purchase_orders/123/purchase_order_line_items/29153 \
-H 'Authorization: Token token="API_KEY"' \
-H "Account-Token: ACCOUNT_TOKEN" \
-H "Content-Type: application/json" \
-X DELETE