Error Code 4: Invalid value passed for JSONString

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:
  1. // --- Input Variables ---
  2. customer_id = salesorder.get("customer_id");
  3. so_id = salesorder.get("salesorder_id");
  4. org_id = organization.get("organization_id");
  5. so_lines = salesorder.get("line_items");

  6. // --- Build Retainer Body ---
  7. retainer_body = Map();
  8. retainer_body.put("customer_id", customer_id);

  9. // --- Handle Custom Fields (Correctly as a List) ---
  10. cf_list = list();
  11. so_cf = Map();
  12. so_cf.put("index", 1);
  13. so_cf.put("show_on_pdf", false);
  14. so_cf.put("value", so_id);
  15. so_cf.put("label", "Sales Order");
  16. cf_list.add(so_cf);
  17. retainer_body.put("custom_fields", cf_list);

  18. // --- Handle Line Items (Correctly as a List) ---
  19. line_list = list();
  20. for each line in so_lines
  21. {
  22. line_map = Map();
  23. line_map.put("description", line.get("group_name") + " " + line.get("description"));
  24. line_map.put("rate", line.get("item_total"));
  25. line_list.add(line_map);
  26. }
  27. retainer_body.put("line_items", line_list);
  28. info "Final payload being sent: " + retainer_body;

  29. // --- API Call with Correct Syntax ---
  30. retainer_invoice = invokeurl
  31. [
  32. url: "https://www.zohoapis.com/inventory/v1/retainerinvoices?organization_id="+org_id
  33. type: POST
  34. parameters: retainer_body
  35. connection: "zom"
  36. ];

  37. info retainer_invoice;

  38. // --- Return Success ---
  39. resultMap = Map();
  40. resultMap.put("message", "Retainer Invoice created from Sales Order: " + so_id);
  41. 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:
  1. {"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.


      Zoho Campaigns Resources


        • Desk Community Learning Series


        • Digest


        • Functions


        • Meetups


        • Kbase


        • Resources


        • Glossary


        • Desk Marketplace


        • MVP Corner


        • Word of the Day


        • Ask the Experts


          Zoho CRM Plus Resources

            Zoho Books Resources


              Zoho Subscriptions Resources

                Zoho Projects Resources


                  Zoho Sprints Resources


                    Zoho Orchestly Resources


                      Zoho Creator Resources


                        Zoho WorkDrive Resources



                          Zoho CRM Resources

                          • CRM Community Learning Series

                            CRM Community Learning Series


                          • Tips

                            Tips

                          • Functions

                            Functions

                          • Meetups

                            Meetups

                          • Kbase

                            Kbase

                          • Resources

                            Resources

                          • Digest

                            Digest

                          • CRM Marketplace

                            CRM Marketplace

                          • MVP Corner

                            MVP Corner




                            Zoho Writer Writer

                            Get Started. Write Away!

                            Writer is a powerful online word processor, designed for collaborative work.

                              Zoho CRM コンテンツ






                                ご検討中の方