{“error_message”: “A purchase order already exists with that po_id ‘20200924-RLETEST’ for company_id 430062”, “param”: null}
here is hson object sent:
{“po_id”:“20200924-RLETEST”,“supplier”:51734,“warehouse”:48037,“shipping_amount”:0.0,“tax_amount”:0.0,“discount_amount”:0.0,“shipping_method”:" another AS400 Spot",“payment_method”:“AS400 SO#: 2567890”,“instructions”:"These are special instructions newly PUT”}
Ahh, I see what’s going on. You’ll want to exclude po_id from the BODY when PUTting unless you actually want to change the po_id to something else.
It is checking to make sure the po_id in the body doesn’t already exist before it changes it, which it does in this case because it’s the PO you’re updating.
In general, most of our PUT methods only require you to send the elements that you’re updating, so they behave more like PATCH.
Yes, it is in our pipeline to completely overhaul our API documentation and we’ll post any updates here on the forum.
Regarding POs…
Creating POs is a bit of a rabbit hole. Right now there is no POST method on the /purchase_order/ endpoint, and PUTting can only update, not create.
POs are currently created with the /product/<sku>/buy/<supplier_id>/ endpoint. This endpoint will either create or update an existing PO depending on the elements passed and whether or not a matching PO is already open.
The body for the endpoint takes the following:
POST /product/<sku>/buy/<supplier_id>/
{
"warehouse": <warehouse_id>,
"quantity": <quantity of sku>,
"unit_price": <unit price of sku>
}
If you already have a PO open for supplier A, warehouse 123 and you POST to the buy endpoint with another sku, it’ll append it to the currently open PO. If there is no open PO with the supplier/warehouse combo then it’ll create a new one.
Similarly, if the sku already exists on the PO, then it’ll check to see if the unit price is the same. If it is, then it’ll simply add the quantities to the existing line. If the unit price is different then it’ll add a new line with the quantity at the different unit price.
We do have plans to add a POST endpoint for purchase orders and I’ll update you here on the forum when we do.
Thank you.
A followup qiestion, I could test but maybe you could answer… Can I change a po_id by sending a different po-id in payload to the endpoint of the original po-id?
Ex PUT to /purchase-order/1234/ with a po-id of 5678 in the po-id field of the json payload?