This library can help you with fetching flex queries from Interactive Brokers.
Simple call the library by passing your token and queryId:
...
FlexResult result = new Reader().GetByApi(token, queryId).Result;
...
Or pass an already downloaded file:
...
FlexQueryResponse result = new Reader().GetByString(content);
...