Forum Discussion

Kathir's avatar
Kathir
Frequent Visitor
4 years ago

API JSON Codes

 

hi, I need an help with the above code. I encountered an error: Expression.Error: We cannot convert a value of type Record to type Number. 

Need help on this please. 

6 Replies

    • Kathir's avatar
      Kathir
      Frequent Visitor

      Sure thanks

       

      ************************************************************************************************************

      let
      baseuri = "https://xxxx/devices/641524/stream-data-full",
      initReq = Json.Document(Web.Contents(baseuri),[Headers=[Authorization="JWT "&GetToken()]]),
      initData = initReq[results],
      gather = (data as list, uri) =>

      let
      newOffset = Json.Document(Web.Contents("https://xxxx/devices/641524/stream-data-full"))[paging][next][after],
      newUri = baseuri & "&after=" & newOffset,
      newReq = Json.Document(Web.Contents(newUri)) ,
      newdata = newReq[results] ,
      data = List.Combine({data, newdata}),
      check = if Table.Contains ( Record.ToTable(newReq) , [Name = "paging"] ) = true then @gather (data , newUri) else data
      in check,

      outputList = if Table.Contains ( Record.ToTable (initReq) , [Name = "paging"] ) = true then gather( initData , baseuri ) else initData ,
      expand = Table.FromRecords(outputList)
      in
      expand

      • lbendlin's avatar
        lbendlin
        Super User

        Your call result is a list, not a record. Replace Table.FromRecords with the appropriate list extractor.