<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic GraphQL to Power Query/BI - M-code Pagination in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/GraphQL-to-Power-Query-BI-M-code-Pagination/m-p/4069113#M54436</link>
    <description>&lt;P&gt;Hi ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im quite new to Power BI and GraphQL espesially. Im using chatgpt to fidn the answers. I want to fetch data from a ERP to Power BI via their Graph QL API. The info follows below and the questions is at the end &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Helpful for your support!&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Graph QL code::&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;query MyQuery {&lt;BR /&gt;accounts(first: 10) {&lt;BR /&gt;edges {&lt;BR /&gt;node {&lt;BR /&gt;code&lt;BR /&gt;description&lt;BR /&gt;}&lt;BR /&gt;cursor&lt;BR /&gt;}&lt;BR /&gt;pageInfo {&lt;BR /&gt;hasNextPage&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Response in JSON:&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;{&lt;BR /&gt;"data": {&lt;BR /&gt;"accounts": {&lt;BR /&gt;"edges": [&lt;BR /&gt;{&lt;BR /&gt;"node": {&lt;BR /&gt;"code": "1045",&lt;BR /&gt;"description": "XYZ"&lt;BR /&gt;},&lt;BR /&gt;"cursor": "92627"&lt;BR /&gt;}&lt;BR /&gt;],&lt;BR /&gt;"pageInfo": {&lt;BR /&gt;"hasNextPage": true&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Chat GPT suggests M-code::&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;let&lt;BR /&gt;// Define the base URL for the API&lt;BR /&gt;baseUrl = "&lt;A href="https://system.net" target="_blank" rel="noopener"&gt;https://system.net&lt;/A&gt;",&lt;BR /&gt;&lt;BR /&gt;// Define the authorization token&lt;BR /&gt;authToken = "ASYYJjCLOeBxaS4768obS",&lt;BR /&gt;&lt;BR /&gt;// Function to fetch a page of data&lt;BR /&gt;fetchPage = (optional afterCursor as nullable text) as record =&amp;gt;&lt;BR /&gt;let&lt;BR /&gt;query = if afterCursor = null then&lt;BR /&gt;"query MyQuery { accounts(first: 10) { edges { node { code description } cursor } pageInfo { hasNextPage } } }"&lt;BR /&gt;else&lt;BR /&gt;"query MyQuery { accounts(first: 10, after: """ &amp;amp; afterCursor &amp;amp; """) { edges { node { code description } cursor } pageInfo { hasNextPage } } }",&lt;BR /&gt;body = "{ ""query"": """ &amp;amp; query &amp;amp; """ }",&lt;BR /&gt;options = [&lt;BR /&gt;Headers = [&lt;BR /&gt;#"Content-Type" = "application/json",&lt;BR /&gt;#"Authorization" = "Bearer " &amp;amp; authToken&lt;BR /&gt;],&lt;BR /&gt;Content = Text.ToBinary(body)&lt;BR /&gt;],&lt;BR /&gt;response = Json.Document(Web.Contents(baseUrl, options)),&lt;BR /&gt;accounts = response[data][accounts]&lt;BR /&gt;in&lt;BR /&gt;accounts,&lt;BR /&gt;&lt;BR /&gt;// Function to fetch all pages&lt;BR /&gt;fetchAllPages = (initialPage as record) as list =&amp;gt;&lt;BR /&gt;let&lt;BR /&gt;fetchPageRecursive = (page as record, acc as list) as list =&amp;gt;&lt;BR /&gt;let&lt;BR /&gt;newAcc = List.Combine({ acc, page[edges] }),&lt;BR /&gt;nextPage = if page[pageInfo][hasNextPage] then @fetchPageRecursive(fetchPage(List.Last(page[edges])[cursor]), newAcc) else newAcc&lt;BR /&gt;in&lt;BR /&gt;nextPage&lt;BR /&gt;in&lt;BR /&gt;fetchPageRecursive(initialPage, {}),&lt;/P&gt;&lt;P&gt;// Fetch the first page&lt;BR /&gt;firstPage = fetchPage(null),&lt;/P&gt;&lt;P&gt;// Fetch all pages&lt;BR /&gt;allPages = fetchAllPages(firstPage),&lt;/P&gt;&lt;P&gt;// Convert the data to a table&lt;BR /&gt;dataTable = Table.FromList(allPages, Splitter.SplitByNothing(), {"Data"}),&lt;BR /&gt;expandedTable = Table.ExpandRecordColumn(dataTable, "Data", {"node"}, {"node"}),&lt;BR /&gt;finalTable = Table.ExpandRecordColumn(expandedTable, "node", {"code", "description"}, {"code", "description"})&lt;BR /&gt;in&lt;BR /&gt;finalTable&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;The result i get in Power Query is&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;"DataFormat.Error: We found extra characters at the end of the JSON input.&lt;BR /&gt;Details:&lt;BR /&gt;Value=&amp;lt;&lt;BR /&gt;Position=4"&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The question is&amp;nbsp;&lt;BR /&gt;1. Is it possible to automatically paginate all the data fromt he graphql API with M-code?&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Would it be better to fetch the data differently to make it easier as im a beginner?&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. Do you see what is wrong with the Chat GPT suggestion and how to handle it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jul 2024 12:16:37 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-07-30T12:16:37Z</dc:date>
    <item>
      <title>GraphQL to Power Query/BI - M-code Pagination</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/GraphQL-to-Power-Query-BI-M-code-Pagination/m-p/4069113#M54436</link>
      <description>&lt;P&gt;Hi ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im quite new to Power BI and GraphQL espesially. Im using chatgpt to fidn the answers. I want to fetch data from a ERP to Power BI via their Graph QL API. The info follows below and the questions is at the end &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Helpful for your support!&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Graph QL code::&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;query MyQuery {&lt;BR /&gt;accounts(first: 10) {&lt;BR /&gt;edges {&lt;BR /&gt;node {&lt;BR /&gt;code&lt;BR /&gt;description&lt;BR /&gt;}&lt;BR /&gt;cursor&lt;BR /&gt;}&lt;BR /&gt;pageInfo {&lt;BR /&gt;hasNextPage&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Response in JSON:&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;{&lt;BR /&gt;"data": {&lt;BR /&gt;"accounts": {&lt;BR /&gt;"edges": [&lt;BR /&gt;{&lt;BR /&gt;"node": {&lt;BR /&gt;"code": "1045",&lt;BR /&gt;"description": "XYZ"&lt;BR /&gt;},&lt;BR /&gt;"cursor": "92627"&lt;BR /&gt;}&lt;BR /&gt;],&lt;BR /&gt;"pageInfo": {&lt;BR /&gt;"hasNextPage": true&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Chat GPT suggests M-code::&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;let&lt;BR /&gt;// Define the base URL for the API&lt;BR /&gt;baseUrl = "&lt;A href="https://system.net" target="_blank" rel="noopener"&gt;https://system.net&lt;/A&gt;",&lt;BR /&gt;&lt;BR /&gt;// Define the authorization token&lt;BR /&gt;authToken = "ASYYJjCLOeBxaS4768obS",&lt;BR /&gt;&lt;BR /&gt;// Function to fetch a page of data&lt;BR /&gt;fetchPage = (optional afterCursor as nullable text) as record =&amp;gt;&lt;BR /&gt;let&lt;BR /&gt;query = if afterCursor = null then&lt;BR /&gt;"query MyQuery { accounts(first: 10) { edges { node { code description } cursor } pageInfo { hasNextPage } } }"&lt;BR /&gt;else&lt;BR /&gt;"query MyQuery { accounts(first: 10, after: """ &amp;amp; afterCursor &amp;amp; """) { edges { node { code description } cursor } pageInfo { hasNextPage } } }",&lt;BR /&gt;body = "{ ""query"": """ &amp;amp; query &amp;amp; """ }",&lt;BR /&gt;options = [&lt;BR /&gt;Headers = [&lt;BR /&gt;#"Content-Type" = "application/json",&lt;BR /&gt;#"Authorization" = "Bearer " &amp;amp; authToken&lt;BR /&gt;],&lt;BR /&gt;Content = Text.ToBinary(body)&lt;BR /&gt;],&lt;BR /&gt;response = Json.Document(Web.Contents(baseUrl, options)),&lt;BR /&gt;accounts = response[data][accounts]&lt;BR /&gt;in&lt;BR /&gt;accounts,&lt;BR /&gt;&lt;BR /&gt;// Function to fetch all pages&lt;BR /&gt;fetchAllPages = (initialPage as record) as list =&amp;gt;&lt;BR /&gt;let&lt;BR /&gt;fetchPageRecursive = (page as record, acc as list) as list =&amp;gt;&lt;BR /&gt;let&lt;BR /&gt;newAcc = List.Combine({ acc, page[edges] }),&lt;BR /&gt;nextPage = if page[pageInfo][hasNextPage] then @fetchPageRecursive(fetchPage(List.Last(page[edges])[cursor]), newAcc) else newAcc&lt;BR /&gt;in&lt;BR /&gt;nextPage&lt;BR /&gt;in&lt;BR /&gt;fetchPageRecursive(initialPage, {}),&lt;/P&gt;&lt;P&gt;// Fetch the first page&lt;BR /&gt;firstPage = fetchPage(null),&lt;/P&gt;&lt;P&gt;// Fetch all pages&lt;BR /&gt;allPages = fetchAllPages(firstPage),&lt;/P&gt;&lt;P&gt;// Convert the data to a table&lt;BR /&gt;dataTable = Table.FromList(allPages, Splitter.SplitByNothing(), {"Data"}),&lt;BR /&gt;expandedTable = Table.ExpandRecordColumn(dataTable, "Data", {"node"}, {"node"}),&lt;BR /&gt;finalTable = Table.ExpandRecordColumn(expandedTable, "node", {"code", "description"}, {"code", "description"})&lt;BR /&gt;in&lt;BR /&gt;finalTable&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;The result i get in Power Query is&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;"DataFormat.Error: We found extra characters at the end of the JSON input.&lt;BR /&gt;Details:&lt;BR /&gt;Value=&amp;lt;&lt;BR /&gt;Position=4"&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;The question is&amp;nbsp;&lt;BR /&gt;1. Is it possible to automatically paginate all the data fromt he graphql API with M-code?&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Would it be better to fetch the data differently to make it easier as im a beginner?&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. Do you see what is wrong with the Chat GPT suggestion and how to handle it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2024 12:16:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/GraphQL-to-Power-Query-BI-M-code-Pagination/m-p/4069113#M54436</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-07-30T12:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: GraphQL to Power Query/BI - M-code Pagination</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/GraphQL-to-Power-Query-BI-M-code-Pagination/m-p/4071018#M54460</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This error typically occurs when the JSON data being imported has extra characters or formatting issues. The following thread is the one which has the similar problem as yours, hope it can help you.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://community.fabric.microsoft.com/t5/Power-Query/Data-Format-Error-We-found-extra-characters-at-the-end-of-JSON/td-p/2615560" target="_blank"&gt;Solved: Data Format .Error: We found extra characters at t... - Microsoft Fabric Community&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT size="3"&gt;&lt;SPAN&gt;It is responding I have checked through web.browsercontains . Prolem has solved by using header and bearer token in it. thanks for the reply.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please review the applied codes to see from which step the error is reported?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vyiruanmsft_0-1722418557364.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1142206i0C867D7D01D4EEEA/image-size/large?v=v2&amp;amp;px=999" role="button" title="vyiruanmsft_0-1722418557364.png" alt="vyiruanmsft_0-1722418557364.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Update the codes for content part as below and check if it can work:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="100%"&gt;Content = Text.ToBinary(&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Json.FromValue(&lt;/FONT&gt;&lt;/STRONG&gt;body&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/FONT&gt;)&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2024 09:37:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/GraphQL-to-Power-Query-BI-M-code-Pagination/m-p/4071018#M54460</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-07-31T09:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: GraphQL to Power Query/BI - M-code Pagination</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/GraphQL-to-Power-Query-BI-M-code-Pagination/m-p/4083577#M54597</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Has your problem been resolved? If so, could you kindly mark your post as Answered? Additionally,could you please kindly share your solution if it’s convenient. This will greatly assist others in the community who may be facing similar challenges. Thank you for your dedication.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2024 08:24:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/GraphQL-to-Power-Query-BI-M-code-Pagination/m-p/4083577#M54597</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-08-06T08:24:43Z</dc:date>
    </item>
  </channel>
</rss>

