Use response to query data from django backend

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,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 :

Is there a way I can get not only the status code but all of the POST response body?

Thank you!

Hello @KMansourr,
Please see:

Essentially you would do something like:

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.

Hi @Anaisdg, thank you for the quick Answer! However I am using the function and not the http.get(), which is why I have a problem, the 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
Thank you!

@KMansourr Yeah, is limited in functionality and was the predecessor to the new requests package, a full-featured HTTP toolset. You should use instead. You’ll also need to use the experimental json.parse() function to parse the returned JSON object into a Flux record:

import "http/requests"
import "experimental/json"

response = "")
tokens = json.parse(data: response.body)

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

@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:

Thank you!

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?

1 Like

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:

and the post request works fine :
Is there a reason for the import error I’m getting though?
Thank you so much for your help!

@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.

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