Rest API "Unauthorized" 401

I am trying to get data from an API by selecting start date and end date and the info displays on a graph.

So far I have made a query that generates the Bearer token, and another one that uses it to get the required information based on the dates input.
Sometimes it works, but when trying again it gets me this 401 "Unauthorized" error, although it has nothing to do with anything at all, because the same query worked 5s ago.
I also tried to have a look at the cache and disabled it just to make sure I get the right token information, I also made a delay for the data to be transfered from the get token query to the get data query. It seems to help a bit, but it crashes again after a few tries. I am sure it's not a problem with the API provider, because the requests are working, and there isn't any time frames I need to wait to make a new query.
I still think the problem is either my unprofessional and unoptimized way of making the queries or cache.

This is a ss of the token_get query witch always works (the authorization info is stored in the "edit" part of the query):

And this is the actual problematic query reservation_income:


This is the image when the code works:


And here it is when it doesn't (nothing is different):

I am about to give up on life with these types of errors, thanks in advance for any recommendations guys.