Forum Discussion

ShaunBuchan's avatar
ShaunBuchan
Frequent Visitor
5 years ago

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

  • 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.

  • ShaunBuchan's avatar
    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.

  • ShaunBuchan's avatar
    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?

  • ShaunBuchan's avatar
    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