neihcs
neihcs

Reputation: 21

How do I correctly call an HTTP API GET request to weatherstack?

I'm trying to do a GET request to api.weatherstack.com (see documentation).

Here's my react effect hook:

useEffect(() => {
      if (country === undefined) return
      console.log(country.name)
      axios
        .get('http://api.weatherstack.com/current', {
            params: {
              access_key: api_key, 
              query: country.name
            }
        })
        .then(response => {
          console.log(response.data)
          setWeather(response.data)
        })
    }, [api_key, country])

However, every single time I run this, I get this error:

{ code: 105, type: "https_access_restricted", info: "Access Restricted - Your current Subscription Plan does not support HTTPS Encryption." }

Doing the API call through my browser or through Postman works perfectly, so I'm thinking that there's probably an issue with how I'm using React or Axios.

Also, this API call works about 10% of the time, so I'm confused about why that might happen too.

Upvotes: 2

Views: 2877

Answers (4)

MrReddy
MrReddy

Reputation: 1

Try using postman or ajax call, it works. All their http: urls are redirected to https:

Upvotes: 0

cpgade
cpgade

Reputation: 19

Try:

.get("http://api.weatherstack.com/current?access_key=YOUR_ACCESS_KEY&query=country.name)

on line 5.

Remove the params: {} on lines 6-9

Upvotes: 0

Odunsi
Odunsi

Reputation: 490

I think it's because you are using the free plan

weatherstack.com https encryption

Upvotes: 0

Related Questions