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: 13

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,077
Latest member
Jocksteriom

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