# Use http.post() response to query data from django backend

**URL:** <https://community.influxdata.com/t/use-http-post-response-to-query-data-from-django-backend/26159>\
**Category:** Systems\
**Created:** [August 17, 2022, 8:47pm UTC](https://community.influxdata.com/t/use-http-post-response-to-query-data-from-django-backend/26159 "2022-08-17T20:47:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![KMansourr](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/kmansourr/32/10446_2.png) [@KMansourr](https://community.influxdata.com/u/KMansourr)\
**Post date:** [August 17, 2022, 8:47pm UTC](https://community.influxdata.com/t/use-http-post-response-to-query-data-from-django-backend/26159/1 "2022-08-17T20:47:35Z")

</div>

Hi,  
I’ve created a task that requires values that I would fetch from our django backend.  
However, I need to send a post request with http.post(),from the task, that returns an access token.  
This access token will then be used to fetch other values with the http.get()needed to calculate what I want to downsample into another bucket.  
The post request works perfectly, but the problem is that it only returns the status code (200), and I really need the response body from this post request that includes the access token.  
This is the response body of the post request on postman :

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/d/d1a9e64568cd61a423b77aa623fabd4a03770375.png)  
Is there a way I can get not only the status code but all of the POST response body?

Thank you!

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [August 17, 2022, 10:02pm UTC](https://community.influxdata.com/t/use-http-post-response-to-query-data-from-django-backend/26159/2 "2022-08-17T22:02:36Z")

</div>

Hello @KMansourr,  
Absolutely!  
Please see:

> **[TL;DR InfluxDB Tech Tips: Handling JSON Objects and Mapping Through Arrays |...](https://www.influxdata.com/blog/tldr-influxdb-tech-tips-handling-json-objects-mapping-arrays/)**
>
> There are many ways to use Flux to bring in data from different sources. Here's how to work with three examples with increasingly complex JSON types.

Essentially you would do something like:

```auto
resp = http.get(url: yourURL)
jsonData = json.parse(data: resp.body)
// uncomment the next line to display the JSON
// array.from(rows: [{data: display(v: jsonData)}])
refresh = jsonData.refresh

```

That’s really cool to see you using tasks like this! What app are you building? Hearing about customer use cases is exciting for me.

---

<div class="post-metadata">

**Author:** ![KMansourr](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/kmansourr/32/10446_2.png) [@KMansourr](https://community.influxdata.com/u/KMansourr)\
**Post date:** [August 17, 2022, 10:14pm UTC](https://community.influxdata.com/t/use-http-post-response-to-query-data-from-django-backend/26159/3 "2022-08-17T22:14:47Z")

</div>

Hi @Anaisdg, thank you for the quick Answer! However I am using the http.post() function and not the http.get(), which is why I have a problem, the http.post() function only returns the status code (200) and I need the whole body.  
The reason i need to do it with POST is that the auth tokens are fetched with a POST request and not GET  
Your example shows how to do this with http.get()  
Is there a way to do it with http.post()?  
Thank you!

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [August 17, 2022, 11:09pm UTC](https://community.influxdata.com/t/use-http-post-response-to-query-data-from-django-backend/26159/4 "2022-08-17T23:09:38Z")

</div>

@KMansourr Yeah, `http.post()` is limited in functionality and was the predecessor to the new [`requests` package](https://docs.influxdata.com/flux/v0.x/stdlib/http/requests/), a full-featured HTTP toolset. You should use [`requests.post()`](https://docs.influxdata.com/flux/v0.x/stdlib/http/requests/post/) instead. You’ll also need to use the [experimental `json.parse()` function](https://docs.influxdata.com/flux/v0.x/stdlib/experimental/json/parse/) to parse the returned JSON object into a [Flux record](https://docs.influxdata.com/flux/v0.x/data-types/composite/record/):

```javascript
import "http/requests"
import "experimental/json"

response = requests.post(url: "http://example-url.com")
tokens = json.parse(data: response.body)

tokens.refresh // would return the refresh token
tokens.access // would return the access token

```

---

<div class="post-metadata">

**Author:** ![KMansourr](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/kmansourr/32/10446_2.png) [@KMansourr](https://community.influxdata.com/u/KMansourr)\
**Post date:** [August 18, 2022, 1:16pm UTC](https://community.influxdata.com/t/use-http-post-response-to-query-data-from-django-backend/26159/5 "2022-08-18T13:16:32Z")

</div>

@scott Hi Scott,  
I tried using this library before, but I only get an error when importing it. Is it possible that they changed the library name? Here’s what it looks like on my task:

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/9/9f2d8ca0c77bb6b2b9d42a9fed27d31eff0460e6.png)

Thank you!

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [August 18, 2022, 2:32pm UTC](https://community.influxdata.com/t/use-http-post-response-to-query-data-from-django-backend/26159/6 "2022-08-18T14:32:40Z")

</div>

No, this likely means you’re using a version of InfluxDB/Flux that doesn’t support this package. What version of InfluxDB are you using?

---

<div class="post-metadata">

**Author:** ![KMansourr](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/kmansourr/32/10446_2.png) [@KMansourr](https://community.influxdata.com/u/KMansourr)\
**Post date:** [August 18, 2022, 2:32pm UTC](https://community.influxdata.com/t/use-http-post-response-to-query-data-from-django-backend/26159/7 "2022-08-18T14:32:50Z")

</div>

Hello again, I have found the problem with the import of http/requests, it was that I needed influxdb:nightly, the only version that was compatible with this library.  
I still get an error in the import but at least I can still use the requests package:

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/f/faaeb46c78f6998f59a72b69ff6444a0d599ea67.png)  
and the post request works fine :  
 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/a/accb2ab209b028b652487dfb29bf3e982cd7f67f.png).  
Is there a reason for the import error I’m getting though?  
Thank you so much for your help!

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [August 18, 2022, 2:43pm UTC](https://community.influxdata.com/t/use-http-post-response-to-query-data-from-django-backend/26159/8 "2022-08-18T14:43:59Z")

</div>

@KMansourr Yeah, the error shows up because the language server protocol (LSP) in the UI doesn’t get updated with every new Flux release. The LSP is what provides the error hinting and auto-complete suggestions.

---

<div class="post-metadata">

**Author:** ![KMansourr](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/kmansourr/32/10446_2.png) [@KMansourr](https://community.influxdata.com/u/KMansourr)\
**Post date:** [August 18, 2022, 2:47pm UTC](https://community.influxdata.com/t/use-http-post-response-to-query-data-from-django-backend/26159/9 "2022-08-18T14:47:54Z")

</div>

I see, everything works perfectly fine now thank you ! I will mark your first reply as the solution
