Invoke URL With Zoho Creator and Multi Part Form Data

Invoke URL With Zoho Creator and Multi Part Form Data

Hi, I have been trying to get an external API working with Zoho creator, I have managed to get loads of different API's working fine over the past few months but I have a problem getting the syntax right for this specific API. I think this is the first time an API I have been connecting to has asked for multipart/form data. I have read the documentation for this a dozen times but as it has notes for one service, do this for another service I can't make any sense of it... I usually manage to use the help and examples to get anything working we need but this one has evaded me. 


The API is Anvil PDF, we are looking to use this service to allow us to send off a modular HTML document constructed in deluge to return a multi-page PDF for quotes, jobsheets etc as we need something a bit more heavy duty than the Zoho Creator Record Templates now and the ability to create more than one page with a proper header and footer.

The JSON object construction works fine and in copy and paste to PostMan it worked.

The API is responding with "required property missing" so I know the API URL and Key are working fine, I just know I'm not  putting then JSON object in the correct place! I have been using PostMan to test this too so I know it all works fine in Postman. My code is below including all my random notes on what is doing what:

  1. void ANVIL.HTML_Generate_Test_RB(int recordID)
  2. {
  3. //Added 18:40 - 11/07/22 - RB
  4. //This is a TEST function to assess the concept of creating a JSON object to send to the ANVIL HTML to PDF API
  5. //The idea is we add HTML to each element on a Jobsheet or similar, then when we want the PDF we simply PULLLL all that data together using code...
  6. //Soooo.... Top Level recordID WILL BE the Jobsheet Form, the various elements will link to HTML snippets...
  7. //Here we go, initially this will just POP the code up for testing, IF it works it will be linked into the Anvil API to return the PDF File, for now I will just copy the code into Postman and do it manually.
  8. //
  9. //Hard coded record ID for testing. 
  10. recordID = 102653000000237355;
  11. //Fetch the Jobsheet we are working with....
  12. jobsheet = Jobsheet[ID == recordID];
  13. //
  14. grabAnvil = Anvil_JSON_Objects[ID == jobsheet.Jobsheet_Templates.Anvil_JSON_Objects];
  15. //Pull Out the Multiline field which holds the JSON object to send off...
  16. grabAnvil_ML = grabAnvil.JSON_Object_Multi_Line;
  17. //info "Multi Line Straight From App: " + grabAnvil_ML;
  18. //Pull the unique CSS reference we inserted so we know where to insert the new CSS
  19. grabCSSREF = grabAnvil.CSS_Insert_Unique_Ref;
  20. //
  21. cssHardcode = "body { font-size: 14px; color: #171717; }.header-one { text-decoration: underline; }.header-two { font-style: underline; }";
  22. //Patch the CSS into the CSS Slot
  23. grabAnvil_ML = grabAnvil_ML.replaceFirst(grabCSSREF,cssHardcode);
  24. //
  25. //info "Multi Line With CSS Splice: " + grabAnvil_ML;
  26. //
  27. grabHTMLREF = grabAnvil.HTML_Insert_Unique_Ref;
  28. htmlHardCode = "<h1 class='header-one'>What is Lorem Ipsum? RB1</h1><p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the <strong>1500s</strong>, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p><h3 class='header-two'>Where does it come from?</h3><p><table><tr><th>Company</th><th>Contact</th><th>Country</th></tr><tr><td>AlfredsFutterkiste</td><td>MariaAnders</td><td>Germany</td></tr><tr><td>CentrocomercialMoctezuma</td><td>FranciscoChang</td><td>Mexico</td></tr></table></p>";
  29. //
  30. grabAnvil_ML = grabAnvil_ML.replaceFirst(grabHTMLREF,htmlHardCode);
  31. //
  32. //-------------Send Code Off to Anvil PDF---------------------//
  33. //API URL
  34. inputURL = "https://app.useanvil.com/api/v1/generate-pdf";
  35. //Assemble the bodyMap
  36. bodyMap = Map();
  37. bodyMap.put("payload",grabAnvil_ML);
  38. //Assemble the headerMap
  39. headerMap = Map();
  40. //Encode the Key and add to header
  41. apiKey = "HIDDENKEY:";
  42. encodedToken = zoho.encryption.base64Encode(apiKey);
  43. headerMap.put("Authorization","Basic " + encodedToken);
  44. //HELP!! The next bit is where I need to add the grabAnvil_ML (Which contains the JSON object) and add it in so it goes off the the API as multipart/Form data
  45. paramatersMap = Map();
  46. //I am fairly sure the next line is where I am getting it wrong!
  47. paramatersMap = {"paramName":"payload","content":"multipart/form-data","stringPart":"true"};
  48. //
  49. pdfResponse = invokeurl
  50. [
  51. url :inputURL
  52. type :POST
  53. parameters:bodyMap
  54. headers:headerMap
  55. files:paramatersMap
  56. ];
  57. //
  58. info pdfResponse;
  59. }

Any help would be VERY welcome! Thanks


    Zoho Marketing Automation

            Zoho Pagesense Resources

              Zoho SalesIQ Resources



                    Zoho TeamInbox Resources

                      Zoho DataPrep Resources



                        Zoho CRM Plus Resources

                          Zoho Books Resources


                            Zoho Subscriptions Resources

                              Zoho Desk Resources

                                Zoho Projects Resources


                                  Zoho Sprints Resources


                                    Qntrl Resources


                                      Zoho Creator Resources


                                        Zoho WorkDrive Resources




                                            Zoho Campaigns Resources

                                              Zoho CRM Resources

                                                      Design. Discuss. Deliver.

                                                      Create visually engaging stories with Zoho Show.

                                                      Get Started Now