When getting a list of purchase orders from the purchase_orders endpoint of the SWSD API it is not including custom fields. Any ideas on how to retrieve the custom values in a purchase order via the API?
BenG if the purchase order you're looking at was created before you added custom fields to purchase orders module, you may not see those fields in the API response. Once you update the custom fields on that PO or create a new PO you should see the fields. Let me know if that solves it for you!
I created a new purchase order and confirmed the custom fields are not being returned by the API. Included sample json output from the API for this purchase order along with a screenshot of the custom fields. The custom field exists in the scope 'Global' from the Service Desk->Custom Fields setup page(in case purchase order specific custom fields need to be created somewhere else that I am not yet aware of)?
{"id":298415,"name":"Test - Custom Fields Present(in API view) on new purchase order?","href":"/purchase_orders/298415.json","number":1377,"state":"Draft","notes":"API Test - Not an actual purchase order request. Seeing if custom fields are returned via API on new purchase orders.","requester":{"id":5551080,"name":"Ben","href":"/users/5551080"},"buyer":{"id":5551080,"name":"Ben","href":"/users/5551080"},"vendor":{"id":468801,"name":"Amazon","href":"/vendors/468801"},"created_at":"2022-10-31T10:47:16.000-07:00","updated_at":"2022-10-31T10:47:16.000-07:00","order_date":"2022-10-31T00:00:00.000-07:00","purchase_order_items":[],"total_cost":"0.01 USD","currency":"USD","tax":0.0,"shipping_handling":0.01,"billing_address":"n/a","shipping_address":"","payment_terms":"","terms_conditions":"","site":{"id":128244,"name":"test name","href":"/sites/128244"},"department":{"id":185447,"name":"Information Technology","href":"/departments/185447"}}
I created a new purchase order and confirmed the custom fields are not being returned by the API. Included sample json output from the API for this purchase order along with a screenshot of the custom fields. The custom field exists in the scope 'Global' from the Service Desk->Custom Fields setup page(in case purchase order specific custom fields need to be created somewhere else that I am not yet aware of)?
{"id":298415,"name":"Test - Custom Fields Present(in API view) on new purchase order?","href":"/purchase_orders/298415.json","number":1377,"state":"Draft","notes":"API Test - Not an actual purchase order request. Seeing if custom fields are returned via API on new purchase orders.","requester":{"id":5551080,"name":"Ben","href":"/users/5551080"},"buyer":{"id":5551080,"name":"Ben","href":"/users/5551080"},"vendor":{"id":468801,"name":"Amazon","href":"/vendors/468801"},"created_at":"2022-10-31T10:47:16.000-07:00","updated_at":"2022-10-31T10:47:16.000-07:00","order_date":"2022-10-31T00:00:00.000-07:00","purchase_order_items":[],"total_cost":"0.01 USD","currency":"USD","tax":0.0,"shipping_handling":0.01,"billing_address":"n/a","shipping_address":"","payment_terms":"","terms_conditions":"","site":{"id":128244,"name":"test name","href":"/sites/128244"},"department":{"id":185447,"name":"Information Technology","href":"/departments/185447"}}
For this most recent test I used the below url and headers. The API is not returning the custom field information for my recently created purchase order with this combination of url/headers.
api.samanage.com/purchase_orders.json
{"X-Samanage-Authorization": "Bearer <TOKEN REMOVED>",
"Content-Type": "application/json",
"Accept": "application/vnd.samanage.v2.1+json"}
Your question about which endpoint I'm using led me to try the xml endpoint instead of the json endpoint. The xml endpoint did return the custom fields so it seems I'll need to switch to that endpoint instead of json.
Thanks much for the help here
SolarWinds solutions are rooted in our deep connection to our user base in the THWACK® online community. More than 195,000 members are here to solve problems, share technology and best practices, and directly contribute to our product development process.