QLIK Sense REST request



我使用下面的URL在qlik Sense中建立了休息连接,但是我使用的URL只会返回237的播放器ID的数据。我想返回播放器下的所有数据库而不是一个特定的ID。

http://api.football-api.com/2.0/player/237?authorization=0123456789

我尝试使用星号(*(而不是237,但它不起作用,我想知道查询参数或查询标头字段是否可能是解决方案。我见过的所有填写休息连接表的示例都很简单,在这种情况下没有帮助。

您不能用*替换player,并期望获取所有数据。这不是REST API的工作方式。理想情况下,您应该拥有players(例如(终点,该终点应与所有玩家(包括它们id(一起返回列表,然后循环遍历其中的所有(或子集(,以获取更多详细信息。据我所知,football-api.com API文档中没有这样的端点。如果他们能为您提供此类信息

,最好与他们支持团队联系。

在qlik中,此解决方案可能看起来像这样:

// Lets imagine that this table is the API response that
// returns list with all players
Players:
Load * Inline [
  playerId
  1
  2
  3
  4
  5
]; 
// Loop through all values in playerId field
for i = 0 to FieldValueCount('playerId')
  // vPlayerId variable will hold the current iteration player id
  let vPlayerId = FieldValue('playerId', $(i))
  // Load player data. The player id variable is in the url
  Details:
  Load
    *
  From
    http://api.football-api.com/2.0/$(vPlayerId)/237?Authorization=0123456789
  ;
next
// We can drop the Players table if not needed anymore
Drop Table Players;

顺便说一句,请不要在Internet上放置Authorization键之类的内容。

文档:https://football-api.com/documentation2/#!/player/get_player_player_id

说需要player_id,您无法使用 *。

下载全部

我认为绕过它的方法是通过使用循环在类似块的块中询问玩家:

FOR i=1 to 1000
    // your code here just get player using $(i) as id
    // you can save also player data as qvd so you will not ask another time for that
    // (most api have plimitation with number of calls)
NEXT i

您可以使用变量代替数字。

我无法查看数据,因为我没有授权,需要知道URL中的PlayerId总数。

// Variable setting, Total Row of PlayerID's Number.
let Id = FieldValue('playerId', 1);
//or
let Id = total number; 

// Loop Start
for start = 1 to $(ID)

// exampleQuery
RestConnectorMasterTable:
SQL SELECT
    "__KEY_...."
    (SELECT ....
     FROM ...)
    FROM XML ...
WITH CONNECTION(Url "http://api.football-api.com/2.0/player/$(start)?Authorization=0123456789");
/* put a variable instead of ID's number in the WITH CONNECTION statement. */

// Loop End
Next start;

Play:
Load *
Resident RestConnectorMasterTable
Where Not IsNull([__FK_...]);

Drop table RestConnectorMasterTable;

希望您发现它有帮助:(


---- - 附加----

我检查了API。

简单地运行一个从1到数字的循环将导致 404错误。(非远程参数(

您是否需要9002团队中的player_id?
如果是这样,则可以在根本下找到9002团队的Player_id。
(休息连接→选择加载数据→root> squad(

因此,您可以先获取小队表的ID字段,然后在ID上循环。

步骤1(
将REST连接器连接到 Team API。
http://api.football-api.com/2.0/team/9002?authorization=1234567890

团队的参数为 9002


步骤2(
单击选择数据以加载以在根下选择小队数据。
只有ID字段到小队表中。(总计28行(
在此处输入图像描述


STPE 3(
将分页类型设置为 custom 在现有 player_id RestConnector选项中。
(创建了连接语句。(
在此处输入图像描述


步骤4(
请参阅下面的脚本并执行加载。

// Team API Connect
LIB CONNECT TO 'Football_Team';
RestConnectorMasterTable:
SQL SELECT 
    "__KEY_root",
    (SELECT 
        "id",
        "name",
        "__FK_squad"
    FROM "squad" FK "__FK_squad")
FROM JSON (wrap on) "root" PK "__KEY_root";
[squad]:
LOAD    [id] AS [id],
        [name] AS [name]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__FK_squad]);

DROP TABLE RestConnectorMasterTable;

// Player_Id API Connect
LIB CONNECT TO 'Football_playerId';
LET total = NoOfRows('squad');        // Number of total.
For i = 0 to $(total) - 1
LET vID = Peek('id', $(i), 'squad');  // Loop start id by 9002 team.

// The following default script was commented out unnecessarily.
// Action required: Implement the logic to retrieve the total records from the REST source and assign to the 'total' local variable.
// Let total = 0;
// Let totalfetched = 0;
// Let startAt = 0;
// Let pageSize = 100;
// for startAt = 0 to total step pageSize
RestConnectorMasterTable:
SQL SELECT 
    "id" AS "id_u3",
    "common_name",
    "name" AS "name_u3",
    "firstname",
    "lastname",
    "team",
    "teamid",
    "nationality",
    "birthdate",
    "age",
    "birthcountry",
    "birthplace",
    "position",
    "height",
    "weight",
    "__KEY_root"
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION(Url "http://api.football-api.com/2.0/player/$(vID)?Authorization=0123456789");
// player/id? → Change the ID to a variable. *****
// Action required: change URL included in 'WITH CONNECTION' as needed to support pagination for the REST source. 
// Please see the documentation for "Loading paged data."
// NEXT startAt;

[Player]:
LOAD    [id_u3] AS [id_u3],
        [common_name] AS [common_name],
        [name_u3] AS [name_u3],
        [firstname] AS [firstname],
        [lastname] AS [lastname],
        [team] AS [team],
        [teamid] AS [teamid],
        [nationality] AS [nationality],
        [birthdate] AS [birthdate],
        [age] AS [age],
        [birthcountry] AS [birthcountry],
        [birthplace] AS [birthplace],
        [position] AS [position],
        [height] AS [height],
        [weight] AS [weight]
    //  , [__KEY_root] AS [__KEY_root]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__KEY_root]);
DROP TABLE RestConnectorMasterTable;
Next i;  // Loop End.

DROP TABLE squad;  // id info table delete.


听到结果是:
在此处输入图像描述


希望您得到想要的结果:D

相关内容

最新更新