# How to call callback url from python?

**URL:** <https://forum.rasa.com/t/how-to-call-callback-url-from-python/19451>\
**Category:** Rasa Open Source\
**Created:** [October 8, 2019, 1:02pm UTC](https://forum.rasa.com/t/how-to-call-callback-url-from-python/19451 "2019-10-08T13:02:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kabeer](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/kabeer/32/5310_2.png) [@kabeer](https://forum.rasa.com/u/kabeer)\
**Post date:** [October 8, 2019, 1:02pm UTC](https://forum.rasa.com/t/how-to-call-callback-url-from-python/19451/1 "2019-10-08T13:02:58Z")

</div>

Hi all,

I am trying to call a callback URL from a python function.

Here is the code:

```
 	rasa_url = "http://localhost:5005/webhooks/callback/webhook"
    wa_data = {
		"sender":"Rasa",
    	"message":"hi"
	}
    r = requests.post(url=rasa_url, data=wa_data)

```

In the terminal of `rasa run`, I am getting below error,

```
 sanic.exceptions.InvalidUsage: Failed when parsing body as json.

```

I also tried r = requests.post(url=rasa\_url, data=json.loads(json.dumps(wa\_data)))

How can I solve this?

---

<div class="post-metadata">

**Author:** ![vp109](https://avatars.discourse-cdn.com/v4/letter/v/c89c15/32.png) [@vp109](https://forum.rasa.com/u/vp109)\
**Post date:** [October 9, 2019, 4:18am UTC](https://forum.rasa.com/t/how-to-call-callback-url-from-python/19451/3 "2019-10-09T04:18:48Z")

</div>

Hi @kabeer.

Try calling the API with `Content-Type` header set to `application/json`. You will also have to pass the data in form of a string and not dict object. Like:

```auto
rasa_url = "http://localhost:5005/webhooks/callback/webhook"
wa_data = {
    "sender":"Rasa",
    "message":"hi"
}

headers = {
    "Content-Type": "application/json"
}

r = requests.post(url=rasa_url, headers=headers, data=json.dumps(wa_data))

```

---

<div class="post-metadata">

**Author:** ![kabeer](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/kabeer/32/5310_2.png) [@kabeer](https://forum.rasa.com/u/kabeer)\
**Post date:** [October 9, 2019, 6:15am UTC](https://forum.rasa.com/t/how-to-call-callback-url-from-python/19451/5 "2019-10-09T06:15:08Z")

</div>

Thanks @vp109, your solution worked.
