Hi all! I am looking for some assistance with this error:
I have looked at similar posts in the forums, but was unable to find a conclusive answer. Basically I have an API call that looks like this:
https://tsnipeit.badcock.com/api/v1/hardware/?search=4K
This follows the documentation for the API: https://snipe-it.readme.io/reference/hardware-list
It looks for assets that have "4K" in the name. This works nicely in postman and also in the "test api" part of outsystems. I copied the response body to the body of the call so that it matches. Even then, when calling it, I get the error.
I know other responses to this problem mention that I could be receiving something different than what it's expecting, but I don't see where that would be the case. This is an example of one item that is returned: (I changed some real names so it's not exposed).
{ "total":33, "rows":[ { "id":3542, "name":"4K PRO WEBCAM", "asset_tag":"I00024047", "serial":"2112LZ03G1W9", "model":{ "id":172, "name":"SPEAKERS USB BRIO 4K" }, "model_number":"960-001105", "eol":null, "status_label":{ "id":2, "name":"Ready to Deploy", "status_type":"deployable", "status_meta":"deployed" }, "category":{ "id":14, "name":"PERIPHERALS" }, "manufacturer":{ "id":39, "name":"LOGITECH" }, "supplier":{ "id":1, "name":"CDW" }, "notes":null, "order_number":"1C5B10Z", "company":null, "location":null, "rtd_location":{ "id":7, "name":"IT Inventory" }, "image":null, "assigned_to":{ "id":442, "username":"vv", "name":"vv", "first_name":"vv", "last_name":"vv", "employee_number":null, "type":"user" }, "warranty_months":null, "warranty_expires":null, "created_at":{ "datetime":"2021-07-09 09:29:17", "formatted":"2021-07-09 09:29 AM" }, "updated_at":{ "datetime":"2021-07-14 13:46:32", "formatted":"2021-07-14 01:46 PM" }, "last_audit_date":null, "next_audit_date":null, "deleted_at":null, "purchase_date":{ "date":"2021-07-01", "formatted":"2021-07-01" }, "last_checkout":{ "datetime":"2021-07-14 13:46:32", "formatted":"2021-07-14 01:46 PM" }, "expected_checkin":null, "purchase_cost":"193.99", "checkin_counter":0, "checkout_counter":1, "requests_counter":0, "user_can_checkout":false, "custom_fields":{ "Requisition":{ "field":"_snipeit_requisition_2", "value":"3683", "field_format":"ANY" }, "Purchase Order":{ "field":"_snipeit_purchase_order_3", "value":"82375", "field_format":"ANY" }, "Date Received":{ "field":"_snipeit_date_received_4", "value":"2021-07-06", "field_format":"DATE" }, "COST OF SERVICE":{ "field":"_snipeit_cost_of_service_8", "value":null, "field_format":"NUMERIC" }, "EOL Date":{ "field":"_snipeit_eol_date_10", "value":null, "field_format":"DATE" } }, "available_actions":{ "checkout":true, "checkin":true, "clone":false, "restore":false, "update":true, "delete":false } } ] }
To note: I don't get this issue with the regular call, but when adding the "search" query parameter, I get the error. Not sure what makes the format change just because of that..?
Thanks all for the help!
[Edited by moderator 2022-08-29 16:36: formatted JSON]
Hi Vinicius,
From the error thrown, it looks like the output of the "custom_fields" field mapping is not inline with the defined API response structure.
If you could share a separate oml wherein you can copy the structure that you are using for capturing the API response, and provide a properly formed dummy response for the 26 to 28th record of your response then that will help in identifying the root cause.
Like Saurabh wrote (and which is probably also written in all those other posts with similar problems), this is caused by a mismatch between the structures you defined, and the actual JSON output. This is typically the result of a polymorphic output, where the JSON structure of the same method varies between calls, depending on the data supplied.
What is the best solution to handle it in your case I cannot tell, as I you supplied only a single output (i.e. only the "regular" and not the "search" variant, or vice verse) and no module.
Hi all!I have attached the OML. There are 2 data source actions, one for all and one with the search filter. As Kilian mentioned, the responses varies, but with a specified output structure specifically for a call with the "search" filter, I was under the impression it would not. As for the solution to this problem, I am a little stumped.
Here's the JSON of the 26th and 27th responses:
{ "total": 33, "rows": [ { "id": 354, "name": "MONITOR", "asset_tag": "I00008299", "serial": "SVNC4KR4", "model": { "id": 51, "name": "MONITOR 17 IN L171P" }, "model_number": "9417HC2", "eol": null, "status_label": { "id": 2, "name": "Ready to Deploy", "status_type": "deployable", "status_meta": "deployed" }, "category": { "id": 9, "name": "MONITORS" }, "manufacturer": { "id": 4, "name": "LENOVO" }, "supplier": { "id": 5, "name": "SAFARI MICRO" }, "notes": null, "order_number": null, "company": null, "location": null, "rtd_location": null, "image": null, "assigned_to": { "id": 324, "username": "ABTC1", "name": "ABTC1 Abbeville SC - AB", "first_name": "ABTC1", "last_name": "Abbeville SC - AB", "employee_number": null, "type": "user" }, "warranty_months": null, "warranty_expires": null, "created_at": { "datetime": "2020-11-20 16:08:58", "formatted": "2020-11-20 04:08 PM" }, "updated_at": { "datetime": "2020-11-20 16:08:58", "formatted": "2020-11-20 04:08 PM" }, "last_audit_date": null, "next_audit_date": null, "deleted_at": null, "purchase_date": null, "last_checkout": { "datetime": "2020-11-20 16:08:58", "formatted": "2020-11-20 04:08 PM" }, "expected_checkin": null, "purchase_cost": "147.00", "checkin_counter": 0, "checkout_counter": 1, "requests_counter": 0, "user_can_checkout": false, "custom_fields": { "Requisition": { "field": "_snipeit_requisition_2", "value": "548", "field_format": "ANY" }, "Purchase Order": { "field": "_snipeit_purchase_order_3", "value": "80919", "field_format": "ANY" }, "Date Received": { "field": "_snipeit_date_received_4", "value": "2016-04-27", "field_format": "DATE" }, "COST OF SERVICE": { "field": "_snipeit_cost_of_service_8", "value": null, "field_format": "NUMERIC" }, "EOL Date": { "field": "_snipeit_eol_date_10", "value": null, "field_format": "DATE" } }, "available_actions": { "checkout": true, "checkin": true, "clone": false, "restore": false, "update": true, "delete": false } }, { "id": 227, "name": "Exos X16 16TB", "asset_tag": "NI00990226", "serial": "ZL28Z4KC", "model": { "id": 40, "name": "Exos X16 16TB" }, "model_number": "ST16000NM002G", "eol": null, "status_label": { "id": 2, "name": "Ready to Deploy", "status_type": "deployable", "status_meta": "deployed" }, "category": { "id": 19, "name": "HARD DISK DRIVE" }, "manufacturer": { "id": 27, "name": "SEAGATE" }, "supplier": null, "notes": null, "order_number": null, "company": null, "location": { "id": 3, "name": "Data Center" }, "rtd_location": null, "image": "tsnipeit.badcock.com/uploads/models/assetmodel-dco4B3vpVdWrIrdqt.jpeg", "assigned_to": { "id": 315, "name": "PNAS07 (I00023365) - SG-6049P-E1CR45L+", "type": "asset" }, "warranty_months": null, "warranty_expires": null, "created_at": { "datetime": "2020-11-03 16:41:02", "formatted": "2020-11-03 04:41 PM" }, "updated_at": { "datetime": "2020-11-05 13:41:24", "formatted": "2020-11-05 01:41 PM" }, "last_audit_date": null, "next_audit_date": null, "deleted_at": null, "purchase_date": null, "last_checkout": { "datetime": "2020-11-05 13:41:23", "formatted": "2020-11-05 01:41 PM" }, "expected_checkin": null, "purchase_cost": null, "checkin_counter": 0, "checkout_counter": 1, "requests_counter": 0, "user_can_checkout": false, "custom_fields": [], "available_actions": { "checkout": true, "checkin": true, "clone": false, "restore": false, "update": true, "delete": false } } ] }
I think on record 27, the custom fields are empty, but I don't see why that'd break the format, since it's just an empty list.
[Edited by moderator 2022-08-30 08:54: formatted JSON]
that's the problem right there, in row 26 it is not a list, it is 5 objects, in row 27 it suddenly is an empty list.
this is also what your error message is saying, it can not parse a list when it is expecting an object
Indeed, it's what Dorine says, and I also predicted in my first reply. I think you have two problems here. The first is that OutSystems can't parse this output. You can fix that by using an OnAfterResponse, and replacing all instances of "custom_fields: []" by "custom_fields: {}" (you can use a Replace() for this). This will allow parsing the JSON again.
But I think the bigger problem is that it seems like those "custom_fields" indeed don't come in an array, but as a objects within an object. If they are variable, i.e. there's no fixed list of what those fields can be, you can never create a structure that has all possible custom fields, and hence you'll going to miss some (if it's something OutSystems doesn't know, i.e. you haven't defined it, then it'll silently ignore those).
To solve the last problem, you'll probably need to do a whole lot more pre-processing (or post-processing), possibly with the ArdoJSON Forge asset, I recall a "listify" action you can use to translate those variable-name objects to a list (but I'm by no means an expert in the matter).