Hello everyone,
I’m having an issue with an API request in my backend code. When I make a HTTPS request, I get a 200 status code, indicating that the fetch succeeded, but the JSON response is empty.
I’ve checked the API URL on Postman, and it seems to be working fine. However, when I request a large range of data, it takes a while to load, and it seems like the request is processing before the JSON is fully ready (at least, that’s my theory).
API SOURCE: Jewish calendar REST API – Hebcal
Here is my backend code:
import { fetch } from 'wix-fetch';
export function createDataFromUser(userLocation) {
let tzid = userLocation.tzid;
let latitude = userLocation.latitude;
let longitude = userLocation.longitude;
console.log('tzid', tzid)
console.log('longitude', longitude)
console.log('latitude', latitude)
getRandomGreeting(tzid, latitude, longitude)
return
}
export async function getRandomGreeting(tzid, latitude, longitude) {
console.log("get in getRandom function");
const response = await fetch(`https://www.hebcal.com/hebcal?v=1&cfg=json&maj=on&min=on&mod=on&nx=on&year=now&month=x&ss=on&mf=on&c=on&geo=pos&latitude=${latitude}&longitude=${longitude}&tzid=${tzid}&M=on&start=2023-04-18&end=2023-05-18&s=on`);
console.log("after fetch");
if (response.ok) {
console.log("status is ok ");
return response.json()
} else {
console.log("error");
return Promise.reject("Fetch did not succeed");
}
}
And here are my logs:
in my front page I’m trying to printing the JSON from the respond and i get undefined: