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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
ShaunBuchan
Frequent Visitor

Pagination Sophos API

Hi,

 

I have working code for retrieving data from Sophos Central. I have added pagination for other data sources before but can't get it working with Sophos. 

 

Here is my code:

 

SophosBearerToken = "Bearer " & (Json.Document(Web.Contents("https://id.sophos.com/api/v2/oauth2/token",
[
Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
Content = Text.ToBinary("grant_type=client_credentials&client_id=" & #"SophosClientID" & "&client_secret=" & #"SophosClientSecret" & "&scope=token")
]
)) [access_token]),

url="https://api-us03.central.sophos.com/endpoint/v1/endpoints",
Header=[
#"Authorization"=#"SophosBearerToken",
#"x-tenant-id"= tenantID
],

PartnerIDQuery = Json.Document(Web.Contents(url,
[Headers=Header])),
items = PartnerIDQuery[items]

 

Can anybody help with this?

6 REPLIES 6
ShaunBuchan
Frequent Visitor

Hi @v-yingjl ,

 

the first reference is the same issue that I have and appears to be unresolved.

There isn't an error message. However if I put page=1 into the url as per the sophos documentation, I receive the same items as when I put page=3 or page=5 etc

ShaunBuchan
Frequent Visitor

Still no success retrieving all the items for a sophos API. Has anybody succeeded in creating an api call to Sophos that retrieves all the items?

mahoneypat
Microsoft Employee
Microsoft Employee

In case it helps, here is a video that shows a different way to get your data potentially without pagination (just offset).

Power BI - Tales From The Front - REST APIs - YouTube

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


ShaunBuchan
Frequent Visitor

Thanks.

 

From the Sophos APi documentation:

PAGE  BY OFFSET

When paging by offset, the client asks for the specific page of data they want, starting from Page 1. The query parameters that affect paging are:

page, pageSize  [Integer]

pageTotal [Boolean]

 

The pages field in the response will have the following sub-fields:

current [Integer] The 1-based page number being returned

size [Integer] Same as the pageSize query parameter passed in.

total [Integer] The total number of pages that exist

 

All query parameters are optional. By default, if you don't specify a query parameter, the first page with up to 50 items on it is returned. The number of pages isn't returned.PAGE BY KEY

When paging by key, the client asks for a page worth of data after a particular matching key. You can omit this key to fetch the first page. The query parameters are the same.

 

The pages field in the response will have the following sub-fields:

fromKey [String] The key of the first item in the array of items returned

nextKey [String] The key to use as the value of the pageFromKey query parameter when fetching the next page of data. This field won't present if there are no more pages to fetch.

size [Integer] Same as the pageSize query parameter passed in or its default value.

total [Integer] (Optional) the total number of pages that exist, if pageTotal=true was passed into the request.

maxSize [Integer]

All query parameters are optional. By default, if you don't specify a query parameter, the first page with up to 50 items on it is returned. The number of pages isn't returned.

PhilipTreacy
Super User
Super User

Hi @ShaunBuchan 

How does the API specify that pagination works?  Are you accessing pages by number, by using a text string in the URL, by cursor?

Let's say that you are accessing different pages specified by a list called pages 

You can use a query like this that uses List.Transform to make a Web.Contents request for each item in the list 

 

pages = {"sales", "marketing","hr"},
url="https://api-us03.central.sophos.com/endpoint/v1/endpoints/",
Header=[
#"Authorization"=#"SophosBearerToken",
#"x-tenant-id"= tenantID
],

PartnerIDQuery = List.Transform(pages, each Json.Document(Web.Contents(url & _ , [Headers=Header])))

 

 

I'm using strings here as I don't actually know how the API works.  If you can supply details I can modify this for you.

Regards

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


v-yingjl
Community Support
Community Support

Hi @ShaunBuchan ,

Have you got any error message when you run the query and could you share the error message?

You can also refer this simliar issue: 

  1. Authenticating to the Sophos Central API with Power Query 
  2. Power Query M function in Paginate API 

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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