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:
- const fetch = require('node-fetch');
- const apiHeaders = {
- "Authorization": "Zoho-oauthtoken xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
- "Cookie": "ZCNEWUIPUBLICPORTAL=true; _zcsr_tmp=ac274c10-0020-4270-9587-795401481110; zalb_442b5845d7=16c37b275de039e0bf53479b8856aa88; zccpn=ac274c10-0020-4270-9587-795401481110"
- };
- async function fetchData() {
- try {
- const response = await fetch("https://www.zohoapis.com/creator/v2.1/data/OWNER_NAME/APP_NAME/report/REPORT_NAME", {
- method: "GET",
- headers: apiHeaders
- });
- if (!response.ok) {
- throw new Error(`HTTP error! status: ${response.status}`);
- }
- const data = await response.json();
- //console.log('API Response:', JSON.stringify(data, null, 2)); // Inspect structure
- // Adjust the extraction logic based on the actual structure of the response
- const origins = [];
- const destinations = []
- // Assuming the structure includes a 'data' key that contains the relevant items
- if (data.data) {
- data.data.forEach(item => {
- if (item.Origin) {
- origins.push(item.Origin);
- }
- if (item.Destination) {
- destinations.push(item.Destination);
- }
- });
- // Remove duplicates and sort the origins
- const uniqueOrigins = [...new Set(origins)];
- const sortedOrigins = uniqueOrigins.sort();
- const uniqueDestinations = [...new Set(destinations)];
- const sortedDestinations = uniqueDestinations.sort();
- console.log(sortedOrigins);
- console.log(sortedDestinations);
- } else {
- console.error('Data structure does not contain expected keys:', data);
- }
- } catch (exception) {
- console.error(exception);
- }
- }
- 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
Deliver unforgettable customer experiences
Deliver unforgettable customer experiences
New to Zoho Marketing Plus?
Everything you need to run your marketing
New to Zoho Marketing Plus?
Everything you need to run your marketing
Zoho Desk Resources
-
Desk Community Learning Series
-
-
-
-
-
-
-
-
-
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
Zoho Show Resources
Writer Get Started. Write Away!
Writer is a powerful online word processor, designed for collaborative work.