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:
- void ANVIL.HTML_Generate_Test_RB(int recordID)
- {
- //Added 18:40 - 11/07/22 - RB
- //This is a TEST function to assess the concept of creating a JSON object to send to the ANVIL HTML to PDF API
- //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...
- //Soooo.... Top Level recordID WILL BE the Jobsheet Form, the various elements will link to HTML snippets...
- //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.
- //
- //Hard coded record ID for testing.
- recordID = 102653000000237355;
- //Fetch the Jobsheet we are working with....
- jobsheet = Jobsheet[ID == recordID];
- //
- grabAnvil = Anvil_JSON_Objects[ID == jobsheet.Jobsheet_Templates.Anvil_JSON_Objects];
- //Pull Out the Multiline field which holds the JSON object to send off...
- grabAnvil_ML = grabAnvil.JSON_Object_Multi_Line;
- //info "Multi Line Straight From App: " + grabAnvil_ML;
- //Pull the unique CSS reference we inserted so we know where to insert the new CSS
- grabCSSREF = grabAnvil.CSS_Insert_Unique_Ref;
- //
- cssHardcode = "body { font-size: 14px; color: #171717; }.header-one { text-decoration: underline; }.header-two { font-style: underline; }";
- //Patch the CSS into the CSS Slot
- grabAnvil_ML = grabAnvil_ML.replaceFirst(grabCSSREF,cssHardcode);
- //
- //info "Multi Line With CSS Splice: " + grabAnvil_ML;
- //
- grabHTMLREF = grabAnvil.HTML_Insert_Unique_Ref;
- 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>";
- //
- grabAnvil_ML = grabAnvil_ML.replaceFirst(grabHTMLREF,htmlHardCode);
- //
- //-------------Send Code Off to Anvil PDF---------------------//
- //API URL
- inputURL = "https://app.useanvil.com/api/v1/generate-pdf";
- //Assemble the bodyMap
- bodyMap = Map();
- bodyMap.put("payload",grabAnvil_ML);
- //Assemble the headerMap
- headerMap = Map();
- //Encode the Key and add to header
- apiKey = "HIDDENKEY:";
- encodedToken = zoho.encryption.base64Encode(apiKey);
- headerMap.put("Authorization","Basic " + encodedToken);
- //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
- paramatersMap = Map();
- //I am fairly sure the next line is where I am getting it wrong!
- paramatersMap = {"paramName":"payload","content":"multipart/form-data","stringPart":"true"};
- //
- pdfResponse = invokeurl
- [
- url :inputURL
- type :POST
- parameters:bodyMap
- headers:headerMap
- files:paramatersMap
- ];
- //
- info pdfResponse;
- }
Any help would be VERY welcome! Thanks
Zoho Desk Resources
-
Desk Community Learning Series
-
-
-
-
-
-
-
-
-
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 Campaigns Resources
Zoho CRM Resources
Writer Get Started. Write Away!
Writer is a powerful online word processor, designed for collaborative work.