# Querying rest api

**URL:** https://forum.rasa.com/t/querying-rest-api/28769
**Category:** Rasa Open Source
**Created:** [May 13, 2020, 8:05am UTC](https://forum.rasa.com/t/querying-rest-api/28769 "2020-05-13T08:05:45Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Dnnsmoyo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/dnnsmoyo/32/4540_2.png) [@Dnnsmoyo](https://forum.rasa.com/u/Dnnsmoyo)
#### Post date: [May 13, 2020, 8:05am UTC](https://forum.rasa.com/t/querying-rest-api/28769/1 "2020-05-13T08:05:45Z")

</div>

I’m trying to use open weather map to make a weather bot. I’m using the code from the demo and everything is fine except actions. I have slot location but i don’t know how to replace the q in the url with the slot. It looks like this:

```
	    	loc = tracker.get_slot('location')
    		current = requests.get('http://api.openweathermap.org/data/2.5/weather?q&appid=cc24cc7c42f06680e1bec75abb70ca0c').json()

```

My question is how do i make the q value be the slot value without using Apixu?

---

<div class="post-metadata">

### Author: ![MuraliChandran14](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/muralichandran14/32/9120_2.png) [@MuraliChandran14](https://forum.rasa.com/u/MuraliChandran14)
#### Post date: [May 13, 2020, 8:33am UTC](https://forum.rasa.com/t/querying-rest-api/28769/2 "2020-05-13T08:33:03Z")

</div>

Hi @Dnnsmoyo,

q will be the location

 ![3](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/e/e3b5de36c83141599cb45c4c70deaa8349b1b71a.png)

In your code you have used

> loc

to get location. you can use that to replace q.

-Murali

---

<div class="post-metadata">

### Author: ![Dnnsmoyo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/dnnsmoyo/32/4540_2.png) [@Dnnsmoyo](https://forum.rasa.com/u/Dnnsmoyo)
#### Post date: [May 13, 2020, 8:38am UTC](https://forum.rasa.com/t/querying-rest-api/28769/3 "2020-05-13T08:38:26Z")

</div>

How do i replace it in the url? Ive tried q=loc but its not working Can you show me an example?

---

<div class="post-metadata">

### Author: ![MuraliChandran14](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/muralichandran14/32/9120_2.png) [@MuraliChandran14](https://forum.rasa.com/u/MuraliChandran14)
#### Post date: [May 13, 2020, 8:42am UTC](https://forum.rasa.com/t/querying-rest-api/28769/4 "2020-05-13T08:42:38Z")

</div>

> response = requests.get(“[http://api.openweathermap.org/data/2.5/weather?q=“+loc+”&appid=](http://api.openweathermap.org/data/2.5/weather?q=%22+loc+%22&appid=)”);

---

<div class="post-metadata">

### Author: ![Dnnsmoyo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/dnnsmoyo/32/4540_2.png) [@Dnnsmoyo](https://forum.rasa.com/u/Dnnsmoyo)
#### Post date: [May 13, 2020, 8:43am UTC](https://forum.rasa.com/t/querying-rest-api/28769/5 "2020-05-13T08:43:14Z")

</div>

Thanks let me try that

---

<div class="post-metadata">

### Author: ![Dnnsmoyo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/dnnsmoyo/32/4540_2.png) [@Dnnsmoyo](https://forum.rasa.com/u/Dnnsmoyo)
#### Post date: [May 13, 2020, 8:45am UTC](https://forum.rasa.com/t/querying-rest-api/28769/6 "2020-05-13T08:45:48Z")

</div>

Now getting this error `TypeError: can only concatenate str (not "NoneType") to str`

---

<div class="post-metadata">

### Author: ![MuraliChandran14](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/muralichandran14/32/9120_2.png) [@MuraliChandran14](https://forum.rasa.com/u/MuraliChandran14)
#### Post date: [May 13, 2020, 8:55am UTC](https://forum.rasa.com/t/querying-rest-api/28769/7 "2020-05-13T08:55:31Z")

</div>

Try `str()` in-built function

+str(loc)+

or go for this approach

> response = requests.get(“[http://api.openweathermap.org/data/2.5/weather?q={}&appid=](http://api.openweathermap.org/data/2.5/weather?q=%7B%7D&appid=)”.format(loc))

---

<div class="post-metadata">

### Author: ![Dnnsmoyo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/dnnsmoyo/32/4540_2.png) [@Dnnsmoyo](https://forum.rasa.com/u/Dnnsmoyo)
#### Post date: [May 13, 2020, 9:16am UTC](https://forum.rasa.com/t/querying-rest-api/28769/8 "2020-05-13T09:16:31Z")

</div>

Thanks

---

<div class="post-metadata">

### Author: ![MuraliChandran14](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/muralichandran14/32/9120_2.png) [@MuraliChandran14](https://forum.rasa.com/u/MuraliChandran14)
#### Post date: [May 13, 2020, 9:56am UTC](https://forum.rasa.com/t/querying-rest-api/28769/9 "2020-05-13T09:56:56Z")

</div>

Okay Sir, I fixed your problem This is the Json format you got from [api.openweather.org](http://api.openweather.org). It key and value pairs does not matched your previous solution. In my understanding the Apixu.weather.api is different than [api.openweather.org](http://api.openweather.org)

 ![3](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/4/4ba8cd146d4f040cf8da85f73983348b1b95807b.png)

This is the solution and working

 ![4](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/3/34a01843d6edc900b3a6733305c00d4722ccc15a.png)

Hope this helps!!

P.S Haha where is the post? 😃

---

<div class="post-metadata">

### Author: ![Dnnsmoyo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/dnnsmoyo/32/4540_2.png) [@Dnnsmoyo](https://forum.rasa.com/u/Dnnsmoyo)
#### Post date: [May 13, 2020, 10:26am UTC](https://forum.rasa.com/t/querying-rest-api/28769/10 "2020-05-13T10:26:31Z")

</div>

Here it is: Tried to solve it myself lol

```
from rasa_sdk import Action
from rasa_sdk.events import SlotSet
import requests

class ActionWeather(Action):
	def name(self):
		return 'action_weather'
		
	def run(self, dispatcher, tracker, domain):
		api_key = 'cc24cc7c42f06680e1bec75abb70ca0c' #your apixu key
		
		loc = tracker.get_slot('location')
		current = requests.get('http://api.openweathermap.org/data/2.5/weather?q={}&appid=cc24cc7c42f06680e1bec75abb70ca0c'.format(loc)).json()
		country = current['location']['country']
		city = current['location']['name']
		condition = current['current']['condition']['text']
		temperature_c = current['current']['temp_c']
		humidity = current['current']['humidity']
		wind_mph = current['current']['wind_mph']

		response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format(condition, city, temperature_c, humidity, wind_mph)
			
		dispatcher.utter_message(response)
		return [SlotSet('location',loc)]

```

Thanks let me implement your solution
