I keep getting a subscription error when trying to use a RapidAPI endpoint even though I have the API key set up correctly. The error message says I’m not subscribed to the API but I should have access.
Here’s my API configuration:
import fetch from 'node-fetch';
const API_ENDPOINT = 'https://video-search-v2.p.rapidapi.com';
const requestOptions = {
method: 'GET',
headers: {
'X-RapidAPI-Key': process.env.REACT_APP_API_SECRET,
'X-RapidAPI-Host': 'video-search-v2.p.rapidapi.com'
}
};
export const getData = async(endpoint) => {
const response = await fetch(`${API_ENDPOINT}/${endpoint}`, requestOptions);
const result = await response.json();
return result;
};
And here’s how I’m calling it:
import { getData } from '../helpers/getData';
const VideoList = () => {
const [currentFilter, setCurrentFilter] = useState('trending');
const [videoData, setVideoData] = useState([]);
useEffect(() => {
getData(`query?type=video&search=${currentFilter}&limit=25`)
.then((response) => setVideoData(response.results))
.catch(err => {
console.error('API Error:', err);
});
}, [currentFilter]);
};
I have my API key stored in the .env file in the project root. What could be causing this subscription error to appear?