QLIK Sense REST请求

时间:2018-02-18 00:29:51

标签: rest qlikview qliksense

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

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

我尝试使用星号(*)代替237并且它没有用,我想知道查询参数或查询标题字段是否可能是解决方案。我已经看到填充REST连接表单的所有示例都很简单,在这种情况下没有帮助。

3 个答案:

答案 0 :(得分:0)

您无法将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;

顺便说一句试试,不要在互联网上放置Authorization密钥。

答案 1 :(得分:0)

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

我没有权限,因此无法查看数据,需要知道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团队的玩家ID?
如果是这样,则可以在根目录下找到9002团队的玩家编号。
(其余连接→选择要加载的数据→根>小队)

因此,您可以先获取小队表的id字段,然后循环访问id。   

步骤1)
将Rest Connector连接到 team API。
http://api.football-api.com/2.0/team/9002?Authorization=1234567890   

team的参数为 9002


第2步)
点击选择要加载的数据以选择根目录下的小队数据。
并且只有id字段进入小队表。 (共28行)
enter image description here


stpe 3)
在现有的 player_id RestConnector选项中,将分页类型设置为自定义
(创建了连接声明。)
enter image description here


步骤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.


听听结果:
enter image description here


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

答案 2 :(得分:0)

文档化: 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