{"_id":"598cbd9a96193400190d8956","project":"54c0e51215af820d001a38a6","version":{"_id":"54f8de4e4339bb1900c8bffb","project":"54c0e51215af820d001a38a6","forked_from":"54f8de14c6cabe23005c02a2","__v":32,"createdAt":"2015-03-05T22:53:02.044Z","releaseDate":"2015-03-05T22:53:02.044Z","categories":["54f8de4e4339bb1900c8bffc","54f8de4e4339bb1900c8bffd","54f8de4e4339bb1900c8bffe","54f8de4e4339bb1900c8bfff","54f8de4e4339bb1900c8c000","54ff6057563d7419002d666e","55007b6ecfeeea17004717dc","5501d779f2ef1e0d003116eb","55116ef89f7c7619005f853b","554bb366f245703100ddd39f","554d226b374fec0d007e64db","555e09f18ab3180d001ac605","555e0b2b4f5e5a0d00836d77","561d1f8b92a0cc350018b24f","562a956c96b5f40d0026eb60","5654c3378a26202b00c17cb8","5697a94b0b09a41900b24546","5739d89e37b52e3200a3a3cc","57ac94252c0b220e00a94570","57ac97a1ad44fc0e003be066","57ac9a3a8f312d0e00e96c75","57ac9c187ae5c60e004ba3a3","58178bee62e4500f009404f6","581a39711a63870f008b621d","581a3b4f0c65b20f00247fcb","5926e0606c729e0f00595f95","5954033ea5bbca002d27ae91","596ce53e0aeafe00157eb1ba","596ce87a8b79f4001a8f6139","598cad2e96193400190d879a","598cbcd3dc20c6000fdfb9c3","598cbd8496193400190d8955","59fcc7c9591add0026c91457","5a020b7856ea82001c8c9342","5a09bc64a91882001c56c2ed","5a71fa2de9aa84007a8bccdb"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1"},"category":{"_id":"598cbd8496193400190d8955","project":"54c0e51215af820d001a38a6","version":"54f8de4e4339bb1900c8bffb","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-08-10T20:09:40.554Z","from_sync":false,"order":14,"slug":"purchase-order-line-items","title":"Purchase Order Line Items"},"user":"560000e90c703d1900952ff2","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-08-10T20:10:02.817Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"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.\n\nAfter 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.\n\nBelow is an example of creating a line item for purchase order #123:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl https://secure.fleetio.com/api/v1/purchase_orders/123/purchase_order_line_items \\\\\\n  -H 'Authorization: Token token=\\\"API_KEY\\\"' \\\\\\n\\t-H \\\"Account-Token: ACCOUNT_TOKEN\\\" \\\\\\n  -H \\\"Content-Type: application/json\\\" \\\\\\n  -X POST -d '{\\n\\t\\t\\\"part_id\\\": 12345,\\n    \\\"quantity\\\": 12,\\n    \\\"unit_cost\\\": 44.56\\\",\\n  }'\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nIn response, you will get something like:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n    \\\"id\\\": 29152,\\n    \\\"part_id\\\": 12345,\\n    \\\"quantity\\\": 12,\\n    \\\"total_quantity_received\\\": null,\\n    \\\"part_number\\\": \\\"Your part\\\",\\n    \\\"unit_cost\\\": 44.56,\\n    \\\"subtotal\\\": 534.72,\\n    \\\"created_at\\\": \\\"2017-08-10T13:48:14.401-05:00\\\",\\n    \\\"updated_at\\\": \\\"2017-08-10T13:49:39.689-05:00\\\"\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nIf you change your mind about the line item's quantity, you can perform a ``PATCH`` with the new line item id:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl https://secure.fleetio.com/api/v1/purchase_orders/123/purchase_order_line_items/29152 \\\\\\n  -H 'Authorization: Token token=\\\"API_KEY\\\"' \\\\\\n\\t-H \\\"Account-Token: ACCOUNT_TOKEN\\\" \\\\\\n  -H \\\"Content-Type: application/json\\\" \\\\\\n  -X PATCH -d '{\\n\\t\\t\\\"quantity\\\": 1\\n  }'\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nAnd finally, if you decided you don't want this line item anymore, just `DELETE` it:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl https://secure.fleetio.com/api/v1/purchase_orders/123/purchase_order_line_items/29153 \\\\\\n  -H 'Authorization: Token token=\\\"API_KEY\\\"' \\\\\\n\\t-H \\\"Account-Token: ACCOUNT_TOKEN\\\" \\\\\\n  -H \\\"Content-Type: application/json\\\" \\\\\\n  -X DELETE\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"reference-4","type":"basic","title":"Reference"}
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: [block:code] { "codes": [ { "code": "curl https://secure.fleetio.com/api/v1/purchase_orders/123/purchase_order_line_items \\\n -H 'Authorization: Token token=\"API_KEY\"' \\\n\t-H \"Account-Token: ACCOUNT_TOKEN\" \\\n -H \"Content-Type: application/json\" \\\n -X POST -d '{\n\t\t\"part_id\": 12345,\n \"quantity\": 12,\n \"unit_cost\": 44.56\",\n }'", "language": "curl" } ] } [/block] In response, you will get something like: [block:code] { "codes": [ { "code": "{\n \"id\": 29152,\n \"part_id\": 12345,\n \"quantity\": 12,\n \"total_quantity_received\": null,\n \"part_number\": \"Your part\",\n \"unit_cost\": 44.56,\n \"subtotal\": 534.72,\n \"created_at\": \"2017-08-10T13:48:14.401-05:00\",\n \"updated_at\": \"2017-08-10T13:49:39.689-05:00\"\n}", "language": "json" } ] } [/block] If you change your mind about the line item's quantity, you can perform a ``PATCH`` with the new line item id: [block:code] { "codes": [ { "code": "curl https://secure.fleetio.com/api/v1/purchase_orders/123/purchase_order_line_items/29152 \\\n -H 'Authorization: Token token=\"API_KEY\"' \\\n\t-H \"Account-Token: ACCOUNT_TOKEN\" \\\n -H \"Content-Type: application/json\" \\\n -X PATCH -d '{\n\t\t\"quantity\": 1\n }'", "language": "curl" } ] } [/block] And finally, if you decided you don't want this line item anymore, just `DELETE` it: [block:code] { "codes": [ { "code": "curl https://secure.fleetio.com/api/v1/purchase_orders/123/purchase_order_line_items/29153 \\\n -H 'Authorization: Token token=\"API_KEY\"' \\\n\t-H \"Account-Token: ACCOUNT_TOKEN\" \\\n -H \"Content-Type: application/json\" \\\n -X DELETE", "language": "curl" } ] } [/block]