Updating an existing record (PUT)
Up to this point, we have used a POST command, generally on a collection endpoint, in order for Spire server to create a new entity (customer, sales order, inventory item). You use a PUT when you want to operate on a specific entity endpoint, and make a change (change a customer name, update a ROP on an inventory item). Remember here that Spire obeys business rules, so you won’t be able to change a value that you were not allowed to change within Spire desktop. For example, you may change an items sell price. You may not change an items average cost price.
For example, let’s change the description of an inventory item. We have determined the inventory items endpoint is;
http://localhost:10880/api/v2/companies/Testco/inventory/items/1
This indicates that this is the inventory items with the internal ID “1”, and is part of the company “Testco”.
Let use the following command;
curl -X PUT -i -u RNOTMAN:12345_rsety --data "{\"description\":\"New and improved widget\"}" -H "Content-Type: application/json" https://localhost:10880/api/v2/companies/Testco/inventory/items/1 -k --insecure -o -v
If we login to Spire desktop, we can confirm that the items description has been changed.
Notice that we only had to “PUT” the attributes that needed to be changed. This is true of most objects you might want to change in Spire. One exception is the sales and purchases objects. Here it’s important to “PUT” the entire contents of an order back when making changes. This is important because Spire reconciles the changes and re-instates the order lines per the contents of the JSON data you sent to reflect the change. Key here is that this is not only how you change the order details, but also how you delete lines from a sales order (by sending back to Spire server an amended sales order representation).