Search this api by city React/javaScript

288 Views Asked by At

Good afternoon everyone. I am trying to implement the rescuegroups.org api into a React project I'm working on. I am trying to search organizations by city. This is the link to the api docs: https://test1-api.rescuegroups.org/v5/public/docs

no matter what query i try I can not get the results im looking for im trying to be able to search by city name and get organizations in that city. Here is what I have so far....


const Results = () => {
  const [animals, setAnimals] = useState({animals:[]})
 

  const fetchData = () => {
   let url = "https://test1-api.rescuegroups.org/v5/public/orgs/search?city=miami";
    const API_KEY = 'mSvOMmM8'

    fetch(url, {
        method: 'POST',
        headers: {
            Authorization: API_KEY,
            'Content-Type': 'application/json'}
    })
    .then(response => response.json())
    .then(response => setAnimals({animals: response }))
  }
  
  useEffect(fetchData, [])

    console.log(animals)

Every time I get the same results no matter how much I change the url. Any help would be greatly appreciated, ive been stuck on this for the past few hours and havnt made much progress. Even looking at the examples on the docs didnt help much.

2

There are 2 best solutions below

0
Eric On

Your useEffect looks a bit different. If the city is varied, you may need to useState for the city, and put city as second para of useEffect. Try

 useEffect(() => {
    fetchData();
  }, []);
0
Apostolos On

The documentation states the following endpoint for GET and POST

 /public/orgs/search/{viewName}/

Have you tried https://test1-api.rescuegroups.org/v5/public/orgs/search/miami/?