Iterate over API Call issue

Jood Kastero

New Member
Joined
Dec 3, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Dears,

I need your help please in my issue," I'm new to DAX and I have tried many ways in this issue and nothing work with me", simply what I'm trying to do is to loop over my API to get the customer details. the API limit is 50 per page I manage to retrieve one page but when I wrote the script I got an error that Converts a value of type Record to type Text.

the call for one page it retrieves 3 things (data, links and meta) I want to loop whenever I have pages or new pages to get the data and store it in one table then expand that table.
Power Query:
let
    
    BaseUrl = Json.Document(Web.Contents("https://api.XXXXXXXXXXXX\Customer.com",
        [
            Headers=
                [
                    Authorization="Bearer XXXXXXXXXXXX",
                    Accept="application/json",
                    #"Content-Type"="application/json"
                ]
        ]                               )
                            ),
    EntitiesPerPage = 50,
    Url = BaseUrl,

    GetJson = (Url) =>
        let
            RawData = Web.Contents(Url),
            Json = Json.Document(RawData)
        in
            Json,

    GetTotalCount = () =>
        let
            Json = GetJson(Url),
            Entities = Json[Count]
        in
            Entities,

    EntityCount = GetTotalCount(),
    PageCount = Number.RoundUp(EntityCount / EntitiesPerPage),
    PageIndex = { 1 .. PageCount},

    GetPage = (PageIndex) =>
        let
            PageUrl = BaseUrl & "page=" & Text.From(PageIndex),
            Json = GetJson(PageUrl),
            Value = Json[Customer]
        in
            Value,

    GetUrl = (PageIndex) =>
        let
            PageNum = "page=" & Text.From(PageIndex),
            PageUrl = BaseUrl & PageNum
        in
            PageUrl,

    Urls = List.Transform(PageIndex, each GetUrl(_)),
    Pages = List.Transform(PageIndex, each GetPage(_)),
    DataList = List.Union(Pages),

    TableFromList = Table.FromList(DataList, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
in
    #"TableFromList"


and when this code run the issue appears in this section:
Power Query:
 GetJson = (Url) =>

        let

            RawData = Web.Contents(Url),

            Json = Json.Document(RawData)

        in

            Json,

and this is the error:

Expression.Error: We cannot convert a value of type Record to type Text.
Details:
Value=[Record]
Type=[Type]


Any Idea please on this
 

Attachments

  • output.PNG
    output.PNG
    2.3 KB · Views: 17

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,223,888
Messages
6,175,213
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top