Estoy tratando de obtener datos de la API de Zillow a través de RapidApi. Soy nuevo en NextJS.
Aquí está el código de mi index.js:
export async function getStaticProps() { const propertyForSale = await fetchApi(`${baseUrl}/propertyExtendedSearch/list?location=Texas&purpose=for-sale&hitsPerPage=6`) const propertyForRent = await fetchApi(`${baseUrl}/propertyExtendedSearch/list?location=Texas&purpose=for-rent&hitsPerPage=6`) return { props: { propertiesForSale: propertyForSale?.hits, propertiesForRent: propertyForRent?.hits, } } }Aquí está el código de mi fetchApi.js:
export const baseUrl = 'https://zillow-com1.p.rapidapi.com' export const fetchApi = async (url) => { const { data } = await axios.get ((url), { headers: { 'x-rapidapi-host': 'zillow-com1.p.rapidapi.com', 'x-rapidapi-key': '8e2e11ca6dmsh77a061b9b854a4ep1762d7jsne6e273637c9f' } }) return data; }Revisé su solicitud a través del cartero y no devuelve ningún resultado.
curl --location --request GET 'https://zillow-com1.p.rapidapi.com/propertyExtendedSearch/list?location=Texas%26purpose=for-sale%26hitsPerPage=6' \ --header 'x-rapidapi-host: zillow-com1.p.rapidapi.com' \ --header 'x-rapidapi-key: 8e2e11ca6dmsh77a061b9b854a4ep1762d7jsne6e273637c9f'Vuelve
{ "status": "error", "statusMessage": "Endpoint no found! Check your query URL and parameters!" } Verifique su solicitud de obtención fuera del código y vuelva a publicar la pregunta. Para la estabilidad de la solución y si la API ofrece el nodo de status de manera consistente, debe verificar si tiene éxito antes de proceder a acceder a otros valores.
//cambiar el ?. pulsa a ?.data tal como lo hice a continuación
exportar función asíncrona getStaticProps() { const propertyForSale = esperar fetchApi ( ${baseUrl}/propertyExtendedSearch/list?location=Texas&purpose=for-sale&hitsPerPage=6 ) const propertyForRent = esperar fetchApi( ${baseUrl}/propertyExtendedSearch/list?location=Texas&purpose=for-rent&hitsPerPage=6 )
return { props: { propiedadesEnVenta: propiedadEnVenta?.datos, propiedadesEnAlquiler: propiedadEnAlquiler?.datos, } } }