# Downlink scheduling using http post requests and python with flask or django

**URL:** <https://www.thethingsnetwork.org/forum/t/downlink-scheduling-using-http-post-requests-and-python-with-flask-or-django/50756>\
**Category:** Uncategorized\
**Created:** [August 18, 2021, 12:39pm UTC](https://www.thethingsnetwork.org/forum/t/downlink-scheduling-using-http-post-requests-and-python-with-flask-or-django/50756 "2021-08-18T12:39:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ecosoph](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/ecosoph/32/35697_2.png) [@ecosoph](https://www.thethingsnetwork.org/forum/u/ecosoph)\
**Post date:** [August 18, 2021, 12:39pm UTC](https://www.thethingsnetwork.org/forum/t/downlink-scheduling-using-http-post-requests-and-python-with-flask-or-django/50756/1 "2021-08-18T12:39:26Z")

</div>

Hi Guys,

I would like to schedule downlinks using python and either django, flask or the requests (preferred way) module. I was able to setup an http webhook with an endpoint and read out sensor data from an endnode using python.

Now, I would like to advance one step and schedule downlinks. I followed the appropriate documentation here:  
[How to schedule downlinks](https://www.thethingsindustries.com/docs/integrations/webhooks/scheduling-downlinks/)

To perform the post request, I need to know the exact URL. An example is provided as follows:  
`/api/v3/as/applications/{application_id}/webhooks/{webhook_id}/devices/{device_id}/down/push`

But what is the base URL? Is it eu1.cloud.thethings.network and what is meant by webhook\_id? From What I could see you can only provide an external endpoint.

Can I provide the API key as follows?

```
import requests
access_token = #yourAccessTokenHere#

result = requests.post(url,
      headers={'Content-Type':'application/json',
               'Authorization': 'Bearer {}'.format(access_token)})

```

Thank you!

---

<div class="post-metadata">

**Author:** ![Jeff-UK](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/jeff-uk/32/35697_2.png) [@Jeff-UK](https://www.thethingsnetwork.org/forum/u/Jeff-UK)\
**Post date:** [August 18, 2021, 1:27pm UTC](https://www.thethingsnetwork.org/forum/t/downlink-scheduling-using-http-post-requests-and-python-with-flask-or-django/50756/2 "2021-08-18T13:27:05Z")

</div>

When thinking of downlinks and especially automating the process have in mind the TTN FUP … limit is 10 per day… and as Nick of these parts says whenever a downlink happens a puppy goes hungry. Downlinks render the gw deaf to uplinks…your convenience is a nightmare for all other community users in range of said gw!

---

<div class="post-metadata">

**Author:** ![ecosoph](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/ecosoph/32/35697_2.png) [@ecosoph](https://www.thethingsnetwork.org/forum/u/ecosoph)\
**Post date:** [August 18, 2021, 1:40pm UTC](https://www.thethingsnetwork.org/forum/t/downlink-scheduling-using-http-post-requests-and-python-with-flask-or-django/50756/3 "2021-08-18T13:40:46Z")

</div>

@Jeff-UK don’t worry, using downlinks will be an exception and we also extend the coverage by bringing out gateways in the field.

I can now send downlinks but I don’t understand the payload format provided in the documentation: frm\_payload":“vu8=”

I receive this downlink as follows:  
 ![image](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/1/b/1b14ac2fbe1e1e343a133a91b6e6abc0af1a6944.png)

Please note that I have also pumped this [thread](https://www.thethingsnetwork.org/forum/t/python-to-automatically-send-a-downlink-to-a-v3-device-using-the-http-webhook/49776). to avoid double posting

---

<div class="post-metadata">

**Author:** ![Jeff-UK](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/jeff-uk/32/35697_2.png) [@Jeff-UK](https://www.thethingsnetwork.org/forum/u/Jeff-UK)\
**Post date:** [August 18, 2021, 1:58pm UTC](https://www.thethingsnetwork.org/forum/t/downlink-scheduling-using-http-post-requests-and-python-with-flask-or-django/50756/4 "2021-08-18T13:58:01Z")

</div>

> [@ecosoph](#):
>
> don’t worry, using downlinks will be an exception and we also extend the coverage by bringing out gateways in the field.

From this and your other post I DO worry - cleary you do not understand the technology or the service you are using!

The cry of ‘but its my device’ or ‘but its my gw’ or ‘but I am only…’ or ‘I/we are adding…’ doesnt wash if you research the Forum posts for the last N years!

Both the GW’s and the airwaves along with the back end infrastructure as and when used for and connected to TTN are a shared resource and are there for all and offered under terms of service and a manifesto with associated FUP that makes this approach unacceptable. As a major contributor of community GW’s myself this is done without reservation or special privaleges! Deploying GW’s does not afford you extra rights or some ring fenced use of the network/infrastructure…and location - in the field or in you own office/lab/home per your other post does not influence that…

> [@Python to automatically send a downlink to a v3 device using the HTTP webhook](https://www.thethingsnetwork.org/forum/t/python-to-automatically-send-a-downlink-to-a-v3-device-using-the-http-webhook/49776/6):
>
> Don’t worry, I’m prototyping this in my office plus I’m also just sending uplinks/downlinks to gateways that we brought out in the field.

---

<div class="post-metadata">

**Author:** ![ecosoph](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/ecosoph/32/35697_2.png) [@ecosoph](https://www.thethingsnetwork.org/forum/u/ecosoph)\
**Post date:** [August 18, 2021, 2:04pm UTC](https://www.thethingsnetwork.org/forum/t/downlink-scheduling-using-http-post-requests-and-python-with-flask-or-django/50756/5 "2021-08-18T14:04:42Z")

</div>

Alright alright, I see and will have a different perspective about using downlinks in future. I thought more like changing the sensor transmission time out in the field eventually 1, 2 or 3 times during its lifetime, which should be up to 10 years.

---

<div class="post-metadata">

**Author:** ![Jeff-UK](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/jeff-uk/32/35697_2.png) [@Jeff-UK](https://www.thethingsnetwork.org/forum/u/Jeff-UK)\
**Post date:** [August 18, 2021, 2:27pm UTC](https://www.thethingsnetwork.org/forum/t/downlink-scheduling-using-http-post-requests-and-python-with-flask-or-django/50756/6 "2021-08-18T14:27:12Z")

</div>

That is fine - it follows the FUP and good netizenship - its the assumption behind what you do and how you do it I’m calling out 😉 A short breach for accidental (\*) or short test (say mapping a community as was mentioned in the Summer Academy this week) is tolerated but many are not mindful of impact so we call out agressively when there may look to be a problem. If 150k TTN users all spend 1 day abusing ‘because I’m just testing’ we woudl have a huge issue 🙂

(\*) classic one is not realising you have the ‘sense’/logic wrong when programming a new device for unconfirmed vs confirmed packets (was that AT command 1 for confirmed and 0 for unforirmed…or was it…) and suddenly bang! - Think we have all done it 🤷‍♂️
