Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Wanted
Frequent Visitor

Take data from api with automatique loop

Hi ! 

I want to take data from API with an automatique id loop.

I'm not really good in Json but i created this code. I'm stuck on the last lines of development.
 
The code return me he can't convert the value "https://ecofac.nicoka..." in type list.
 
Here is the code  : 
 
 

 

 

let

    BaseUrl         = "https://ecofac.nicoka.com/api/jobs/",

    Token           = "token",

 

    GetJson = (Url) =>
        let Options = [Headers=[ #"Authorization" = "Bearer " & Token ]],
            RawData = Web.Contents(Url, Options),
            Json    = Json.Document(RawData)
        in  Json,

 

    GetTotalEntities = () =>

        let Json = GetJson(BaseUrl),

            Total = Json[total]

        in  Total,

 
    GetUrl = (Index) =>

        let Skip  = Text.From(Index) & "/counters/",

            Url   = BaseUrl & Skip

        in  Url,

 

    EntityCount = List.Max({GetTotalEntities()}),

    PageCount   = Number.RoundUp(EntityCount),

    PageIndices = { 32 .. PageCount + 1 },


    URLs  = List.Transform(PageIndices, each GetUrl(_)),

    Entities    = List.Union(URLs)
in
    Entities

 

 


And i need a list of ids pulled from the request on the api and it works fine.

But now I have to use this list to get all of my data but its not working.
 
If you need more information i can answer it.

Thanks for read this and for your helps if you can 😉

1 ACCEPTED SOLUTION

I don't need this list union 😮
I just missed to add this line on the GetUrl

 

Json = GetJson(Url),

 

Thank you for yours help 🙂

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

try replacing thjis

 

    URLs  = List.Transform(PageIndices, each GetUrl(_)),

    Entities    = List.Union(URLs)
in
    Entities

 

 

with this one

 

    URLs  = List.Transform(PageIndices, each GetUrl(_))

in
   URLs

 

 

 

PS

be careful not to leave the comma before in

When I do what you say I just have my address list that I want to request which it doesn't do.

Best regards

Anonymous
Not applicable

my suggestion was related to the error you reported. I have not read and understood the meaning and purpose of your code to give a complete answer (I don't have time to do such a thing).
I only saw that you improperly used the list.union function and suggested that you exclude it to get a correct but incomplete result.
<<can't convert the value "https://ecofac.nicoka..." in type list.>>

I'm sorry if the suggestion is not enough to completely solve your problem.

 

Yeah, I think I have to use a list.union to request my whole list to get all the data.
But this line doesn't actually work.

Anonymous
Not applicable

this is more or less what list.union can do:

https://docs.microsoft.com/it-it/powerquery-m/list-union

 

 

I don't need this list union 😮
I just missed to add this line on the GetUrl

 

Json = GetJson(Url),

 

Thank you for yours help 🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors