Forum Discussion
Pagination in Shopify API
- Anonymous1 year ago
Hi Ambhika_07 ,
The only way to get all headers (as opposed to a subset) is to use a custom connector.
Upvote suggestion to get all headers back here: https://ideas.fabric.microsoft.com/ideas/idea/?ideaid=e47d7520-1509-ed11-b5cf-281878de6c19
There is a similar thread here,hope it helps.
Solved: Retrieve API response headers - Microsoft Fabric Community
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Ambhika_07 ,
To achieve this in Power BI, you could use the Power Query M language to programmatically follow the pagination links.
Please try below steps:
1. Initial API Call: Start by making an initial API call to fetch the first set of data along with the pagination link from the response headers.
2. Parse Response Headers: Extract the "next URL" from the response headers. This will require parsing the headers to locate the URL for the next page of data.
3. Recursive Function: Create a recursive function in Power Query M that takes the "next URL" as an input, fetches the data, and then calls itself with the new "next URL" found in the response headers of the subsequent call. This function should continue to execute until there is no "next URL" found, indicating the end of the data.
Here's a simplified example of how you might start to structure this function in Power Query M:
et
FetchData = (url as text) as table =>
let
Source = Json.Document(Web.Contents(url)),
Data = Source[data],
NextUrl = Source[headers][next_url], // Adjust this based on actual header structure
Output = if NextUrl <> null then Table.Combine({Data, @FetchData(NextUrl)}) else Data
in
Output
in
FetchData("YourInitialShopifyApiUrl")
Note: This is a simplified example. You'll need to adjust the logic to match the specific structure of the Shopify API response and ensure you handle authentication headers if required.
If you struggle with connecting to Shopify API, there are ready-made solutions for extracting data automatically from Shopify. Here is one of them: https://vidi-corp.com/shopify-power-bi-connector/
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.