To include parameters in your fetch request when making a GET request to your Firebase Cloud Function, you can append them to the URL as query parameters. Hereโs how you can modify your fetch request to include parameters:
const apiUrl = 'https://webflow-api2.p.rapidapi.com/'; // Replace with your API endpoint
const queryParams = {
// Add your parameters here
access_token: '<access_token>',
collection_id: '<collection_id>',
item_id: '<item_id>',
};
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Key': 'ca67370cf0msh61e966d7498b378p1da3cajsn4c9f85ff6282',
'X-RapidAPI-Host': 'webflow-api2.p.rapidapi.com'
}
};
// Create a URL with query parameters
const url = new URL(apiUrl);
Object.keys(queryParams).forEach(key => url.searchParams.append(key, queryParams[key]));
fetch(url, options)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json(); // Parse the response body as JSON
})
.then(data => {
// Handle the JSON data here
console.log(data);
})
.catch(error => {
// Handle errors here
console.error('There was a problem with the fetch operation:', error);
});
In the code above, we define queryParams as an object containing the parameters you want to include. Then, we use the URL class to create a URL with query parameters based on your API endpoint and the queryParams object. Finally, we make the fetch request using the constructed URL, which includes the parameters.