Qlik Community

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
QlikWorld 2022, LIVE in Denver CO., May 16-19, 2022. REGISTER NOW TO RECEIVE EARLY BIRD PRICING
cancel
Showing results for 
Search instead for 
Did you mean: 
thomasgrimsby
Contributor II
Contributor II

API - How to get the loop working?

Hi!

I want to go on with a little hobby project in QV.

This is regarding English football and a game called fantasy premier league.

The API I want to work properly in QV is https://fantasy.premierleague.com/drf/element-summary/1.

I have the REST connector and have read in the above API.

BUT this is just information about Player 1 in the league (Goalkeeper at Arsenal), hence the 1 at the end of the API URI

So my real question is if somebody could help me out writing a proper loop to get all the player data in the league!

To be able to do this I need a working loop that goes from i = 1 to max(element_u0) somehow.....

element_u0 is the Player ID.

Someone who can help?

1 Solution

Accepted Solutions
mfchmielowski
Creator II
Creator II

Look here:

https://github.com/LazyTarget/FantasyPremierLeagueAPI/tree/master/src/Helpers/WebRetriever/Pages

You'll find here some endpoints of api you're using.

Try to fetch info from https://fantasy.premierleague.com/drf/elements You'll find there full players list with ids.

View solution in original post

6 Replies
mfchmielowski
Creator II
Creator II

Hi.

On https://fantasy.premierleague.com/drf/bootstrap you have key named total_players (at this moment value is 4436132). I've found information that there'is more info on this url while you're logged in.

let max = 2;

for i=1 to '$(max)'

  let connectionString = 'Provider=QvRestConnector.exe;url=https://fantasy.premierleague.com/drf/element-summary/'&i&';timeout=30;method=GET;autoDetectResponse...

  CUSTOM CONNECT TO '$(connectionString)';

  RestConnectorMasterTable:

  SQL SELECT

  "__KEY_root",

  (SELECT "id" AS "id_u3",/*...*/"fixture" AS "fixture_u0","opponent_team" AS "opponent_team_u0","__FK_history" FROM "history" FK "__FK_history")

  FROM JSON (wrap on) "root" PK "__KEY_root";

  [history]:

  LOAD

  $(i) as urlPlayedId, [id_u3],[fixture_u0],[opponent_team_u0],[__FK_history] AS [__KEY_root]

  RESIDENT RestConnectorMasterTable

  WHERE NOT IsNull([__FK_history]);

  DROP TABLE RestConnectorMasterTable;

next i;

This sample works. I didn't check what will happend when user was removed  and url will return 404 reply code

mfchmielowski
Creator II
Creator II

GitHub - bobbymond/FantasyPremierLeagueAPI: A C# API for accessing data for Fantasy Premier League

here you've info about api you're using. Maybe you'll find more interesting info there

thomasgrimsby
Contributor II
Contributor II
Author

Thanks a lot Michal.

That loop works when we are sure about how many players are in the league system

But is it possible to return the max(element_u0) somehow so that the script automatically finds all the id's.

When I now put in max = 100 i will get the 100 first players but if I put in max = 1000 the script fails when it can't find so many players (It ends around 650).

This below script is working but it would be amazing to get a loop that stops properly when all records are found!



let max=100;
for i=1 to '$(max)'


let connectionString='Provider=QvRestConnector.exe;url= https://fantasy.premierleague.com/drf/element-summary/'&i&';
timeout=30;method=GET;autoDetectResponseType=true;keyGenerationStrategy=0;useWindowsAuthentication=false;useCertificate=No;certificateStoreLocation=CurrentUser;certificateStoreName=My;PaginationType=Custom;XUserId=KNLDCcB;XPassword=HeeeWYC;';


CUSTOM CONNECT TO '$(connectionString)';


Bla bla bla



next i;

Peter_Cammaert
Partner
Partner

You'll have to figure out where on this web site you can get hold of the maximum number of players available for extraction. Any idea?

mfchmielowski
Creator II
Creator II

Look here:

https://github.com/LazyTarget/FantasyPremierLeagueAPI/tree/master/src/Helpers/WebRetriever/Pages

You'll find here some endpoints of api you're using.

Try to fetch info from https://fantasy.premierleague.com/drf/elements You'll find there full players list with ids.

View solution in original post

thomasgrimsby
Contributor II
Contributor II
Author

Hi again!

Thanks a lot for your answers Michal!

It was very useful to look in https://fantasy.premierleague.com/drf/elements to find how many ID's to use as max.

For now max=653

Unfortunately I'm just a QlikView user and have not tried Java so how to exactly use a max(ID) insted of typing in the x=653 or 700 when that changes is still a little mystery but not a real problem.

Things are working thanks to you