Error Code 4: Invalid value passed for JSONString
Okay, I want to start by saying I know I'm a terrible scripter, so sorry if this is a dumb mistake. I just can't figure it out, even with LLM help.
Here's my code:
- // --- Input Variables ---
- customer_id = salesorder.get("customer_id");
- so_id = salesorder.get("salesorder_id");
- org_id = organization.get("organization_id");
- so_lines = salesorder.get("line_items");
- // --- Build Retainer Body ---
- retainer_body = Map();
- retainer_body.put("customer_id", customer_id);
- // --- Handle Custom Fields (Correctly as a List) ---
- cf_list = list();
- so_cf = Map();
- so_cf.put("index", 1);
- so_cf.put("show_on_pdf", false);
- so_cf.put("value", so_id);
- so_cf.put("label", "Sales Order");
- cf_list.add(so_cf);
- retainer_body.put("custom_fields", cf_list);
- // --- Handle Line Items (Correctly as a List) ---
- line_list = list();
- for each line in so_lines
- {
- line_map = Map();
- line_map.put("description", line.get("group_name") + " " + line.get("description"));
- line_map.put("rate", line.get("item_total"));
- line_list.add(line_map);
- }
- retainer_body.put("line_items", line_list);
- info "Final payload being sent: " + retainer_body;
- // --- API Call with Correct Syntax ---
- retainer_invoice = invokeurl
- [
- url: "https://www.zohoapis.com/inventory/v1/retainerinvoices?organization_id="+org_id
- type: POST
- parameters: retainer_body
- connection: "zom"
- ];
- info retainer_invoice;
- // --- Return Success ---
- resultMap = Map();
- resultMap.put("message", "Retainer Invoice created from Sales Order: " + so_id);
- resultMap.put("code", 0);
Shockingly, I managed to do this almost entirely by myself. The only error that the LLM accurately caught was that my code for the custom field was not properly formatted as a list.
The error / log I'm getting is below:
I assume there's something wrong with the formatting of the retainer_invoice map being sent in the API call?
Here's the entirety of that map, as copied from the log:
- {"customer_id":"2245303000022841066","custom_fields":[{"index":1,"show_on_pdf":false,"value":"2245303000144413026","label":"Sales Order"}],"line_items":[{"description":"Pet Door - WM-L (blk) Pet Door - WM-L (blk)","rate":379},{"description":"Pet Door - DM-L (brwn) Pet Door - DM-L (brwn)","rate":798}]}
Any guidance would be greatly appreciated.