【问题标题】:QLIK Sense REST requestQLIK Sense REST 请求
【发布时间】:2018-02-18 00:29:50
【问题描述】:

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

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

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

【问题讨论】:

    标签: rest qlikview qliksense


    【解决方案1】:

    您不能将 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 键之类的东西放在互联网上。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        你可以用变量代替数字。

        我没有权限无法查看数据,需要知道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 到 number 的循环将导致 404 错误。 (不存在的参数)

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

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

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

        团队的参数是9002


        第 2 步)
        点击Select data to load选择root下的小队数据。
        并且只有 id 字段进入了小队表。 (共 28 行)
        enter image description here


        stpe 3)
        在现有的 player_id RestConnector 选项中将分页类型设置为 Custom
        (创建了WITH CONNECTION STATEMENT。)
        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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-07-07
          • 2021-09-05
          • 2016-08-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多