zoukankan      html  css  js  c++  java
  • Call REST APIs And Parse JSON With Power BI

    Step 1 - Create a Web API
     
    First, we need to create an API. Create a Web API project in Visual Studio or use your existing Web API. Here is my example.
     
     
    1. using System;  
    2. using System.Collections.Generic;  
    3. using System.Linq;  
    4. using System.Net;  
    5. using System.Net.Http;  
    6. using System.Web.Http;  
    7.   
    8. namespace webapi.Controllers  
    9. {  
    10.     public class CountriesController : ApiController  
    11.     {  
    12.         [HttpGet]  
    13.         [Route("api/getcountries")]  
    14.   
    15.         public List<string>GetallCountries()  
    16.         {  
    17.             List<string> countryobject = new List<string>();  
    18.   
    19.             countryobject.Add("Austria");  
    20.             countryobject.Add("Afghanistan");  
    21.             countryobject.Add("Bangladesh");  
    22.             countryobject.Add("canada");  
    23.             countryobject.Add("China");  
    24.             countryobject.Add("Cuba");  
    25.             countryobject.Add("Denmark");  
    26.             countryobject.Add("India");  
    27.             countryobject.Add("Iran");  
    28.             countryobject.Add("Iraq");  
    29.             countryobject.Add("Japan");  
    30.             countryobject.Add("Kenya");  
    31.             countryobject.Add("Libya");  
    32.             countryobject.Add("Mali");  
    33.             countryobject.Add("Namibia");  
    34.             countryobject.Add("Nepal");  
    35.             countryobject.Add("Norway");  
    36.             countryobject.Add("Oman");  
    37.             countryobject.Add("Peru");  
    38.             countryobject.Add("Poland");  
    39.             countryobject.Add("Philippines");  
    40.   
    41.   
    42.             return countryobject;  
    43.         }  
    44.     }  
    45. }  
    Through postman, I've tested the API and it is working as expected. 
     
    Call REST APIs And Parse JSON With Power BI
    Figure(1)
     
    Step 2 - Run your Power BI desktop.
     
    Run your Power BI Desktop.
     
    Use the "Web" option for accessing data from an API. In the figure below, I have marked the GetData icon click on that and select Web option.
     
    Call REST APIs And Parse JSON With Power BI
    Figure(2)
     
    After selecting the Web option, "From Web" window will appear. Please check below figure.
     
    Basic
     
    Using this option, we can access data from an API by providing an API URL only.
    Call REST APIs And Parse JSON With Power BI
    figure(3) 
    Advanced
     
    Call REST APIs And Parse JSON With Power BI
    figure(4)
     
    Using this option, we can access data via an API by providing the API URL. The difference here is, we can use query parameters, pass values at headers (when our API's are implemented with authentication) and we can mention content type, etc.
     
    Let's access data from the API using Basic Option. Enter your API URL in textbox.
     
    Click on the OK button. See figure(3).
     
    Data is loaded from the API. See below.
     
    Call REST APIs And Parse JSON With Power BI 
    figure(5)
     
    Step 3 - Selection Visualization
     
    Select appropriate visualizations from the visualizations tab. I am selecting Table visualization. See below. 
     
    Call REST APIs And Parse JSON With Power BI 
    figure(6)
     
    Please click on the icon which I marked in the above figure(6). After clicking that icon, we will get table visualization.
     
    Call REST APIs And Parse JSON With Power BI
    figure(7)
     
    Now we need to load data for our visualization. For that click on the "get countries" checkbox, which is under the Fields tab when you expand it. 
     
    Call REST APIs And Parse JSON With Power BI 
    figure(8)
     
    By following the above steps, we've loaded data in a table. See below.
     
    Call REST APIs And Parse JSON With Power BI
    figure(9)
  • 相关阅读:
    今天整理一下以前各博客网站上的文章
    转一篇详解Excel逻辑函数的文章
    Google中国的首页变化
    [转]在QuantumGrid4.5中手动添加数据
    [转]VISTA服务介绍
    Idiomatic Phrases Game zoj 2750 Dijkstra
    Fleury 求欧拉回路
    QS Network ZOJ 1586 Prim
    Burn the Linked Camp ZOJ 2770 差分约束系统 SPFA
    ZOJ 1092 POJ 2240 Arbitrage Floyd
  • 原文地址:https://www.cnblogs.com/Javi/p/14276759.html
Copyright © 2011-2022 走看看