Issue with Fetching Data from Zoho Creator using Custom Outlook Add-in

Issue with Fetching Data from Zoho Creator using Custom Outlook Add-in

Hi Team,

I am encountering an issue while trying to fetch data from Zoho Creator in a custom Outlook add-in. The goal is to retrieve origin and destination information from a specific report, but I'm facing CORS-related errors and failed requests.

Error:

Code Overview: Here’s the code snippet I'm using to make the API call:

  1. const fetch = require('node-fetch');

  2. const apiHeaders = {
  3.     "Authorization": "Zoho-oauthtoken xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  4.     "Cookie": "ZCNEWUIPUBLICPORTAL=true; _zcsr_tmp=ac274c10-0020-4270-9587-795401481110; zalb_442b5845d7=16c37b275de039e0bf53479b8856aa88; zccpn=ac274c10-0020-4270-9587-795401481110"
  5. };

  6. async function fetchData() {
  7.     try {
  8.         const response = await fetch("https://www.zohoapis.com/creator/v2.1/data/OWNER_NAME/APP_NAME/report/REPORT_NAME", {
  9.             method: "GET",
  10.             headers: apiHeaders
  11.         });

  12.         if (!response.ok) {
  13.             throw new Error(`HTTP error! status: ${response.status}`);
  14.         }

  15.         const data = await response.json();
  16.         //console.log('API Response:', JSON.stringify(data, null, 2)); // Inspect structure

  17.         // Adjust the extraction logic based on the actual structure of the response
  18.         const origins = [];
  19.         const destinations = []

  20.         // Assuming the structure includes a 'data' key that contains the relevant items
  21.         if (data.data) {
  22.             data.data.forEach(item => {
  23.                 if (item.Origin) {
  24.                     origins.push(item.Origin);
  25.                 }
  26.                 if (item.Destination) {
  27.                     destinations.push(item.Destination);
  28.                 }
  29.             });

  30.             // Remove duplicates and sort the origins
  31.             const uniqueOrigins = [...new Set(origins)];
  32.             const sortedOrigins = uniqueOrigins.sort();

  33.             const uniqueDestinations = [...new Set(destinations)];
  34.             const sortedDestinations = uniqueDestinations.sort();

  35.             console.log(sortedOrigins);
  36.             console.log(sortedDestinations);
  37.         } else {
  38.             console.error('Data structure does not contain expected keys:', data);
  39.         }
  40.     } catch (exception) {
  41.         console.error(exception);
  42.     }
  43. }

  44. fetchData();

Context:

  • The API call works fine in tools like Postman, but when I try to run it in the custom add-in, I get the above errors.
  • I suspect it’s related to CORS issues, but I’m unsure how to proceed given the setup.

Could anyone suggest how to handle CORS in this context or point out if there's something wrong with the API call configuration? Is there a server-side configuration in Zoho Creator or any other workaround that could help?

Thanks in advance!

    Access your files securely from anywhere

        Zoho Developer Community







                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation


                                              Manage your brands on social media



                                                    Zoho TeamInbox Resources

                                                      Zoho DataPrep Resources



                                                        Zoho CRM Plus Resources

                                                          Zoho Books Resources


                                                            Zoho Subscriptions Resources

                                                              Zoho Projects Resources


                                                                Zoho Sprints Resources


                                                                  Qntrl Resources


                                                                    Zoho Creator Resources



                                                                        Zoho Campaigns 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





                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now