Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use next link #27

Open
JohnSColeman opened this issue Nov 15, 2024 · 2 comments
Open

how to use next link #27

JohnSColeman opened this issue Nov 15, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@JohnSColeman
Copy link

When consuming customer reviews the response may contain a link to the next set of reviews. There does not seem to be a mechanism available on the API to handle this scenario.

@isaced
Copy link
Owner

isaced commented Nov 29, 2024

It seems that for paginated APIs, it is necessary to parse links.next in the Response to continue initiating the next page request.

{
 ...
  links: {
    self: "https://api.appstoreconnect.apple.com/v1/apps/xxxxx/customerReviews",
    first: undefined,
    next: "https://api.appstoreconnect.apple.com/v1/apps/xxxx/customerReviews?cursor=Ma.AMl1C-1",
  },
  meta: {
    paging: {
      total: 345,
      limit: 50,
    },
  }
}

It seems that for paginated APIs, it is necessary to parse links.next in Response to continue to initiate the next page request.

I plan to add a method similar to request(url: string) in Client for this purpose. If you have a better idea, please let me know.

@isaced isaced added the enhancement New feature or request label Nov 29, 2024
isaced added a commit that referenced this issue Nov 29, 2024
feat: Add `request` method for making API requests #27
@isaced
Copy link
Owner

isaced commented Nov 29, 2024

v1.3.0 has been released, adding a new client.request() method to send other requests. here is an example of requesting reviews pagination, hope it can help you.

import { AppStoreConnectAPI } from "appstore-connect-sdk";
import { AppsApi, CustomerReviewsResponse } from "appstore-connect-sdk/openapi";

const client = new AppStoreConnectAPI({
    issuerId: process.env.ISSUER_ID,
    privateKeyId: process.env.PRIVATE_KEY_ID,
    privateKey: process.env.PRIVATE_KEY,
});
const api = await client.create(AppsApi);

// fetch apps
const res = await api.appsGetCollection();
console.log('Fetch apps count:', res.data.length);

const appId = res.data[1].id;

// fetch reviews
const reviews = await api.appsCustomerReviewsGetToManyRelated({ id: appId });
console.log('Fetch reviews links:', reviews.links);

// fetch next page reviews
if (reviews.links.next) {
    const nextPageRes = await client.request({
        url: reviews.links.next
    })
    const nextPageReviews = (await nextPageRes.json()) as CustomerReviewsResponse
    console.log('Fetch next page reviews:', nextPageReviews.meta?.paging.total);
}

https://github.com/isaced/appstore-connect-sdk/blob/main/test/reviews.test.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants