white-cartoon-58880
04/11/2024, 2:22 PMpage_token
out from the response.headers
?lively-scientist-17848
04/11/2024, 4:16 PMimport (
"fmt"
"net/http"
"net/url"
"<http://github.com/peterhellberg/link|github.com/peterhellberg/link>"
)
// GetNextPageToken parses the link header in the response to get the next page of the API
// See: <https://www.ory.sh/docs/ecosystem/api-design#pagination>
func GetNextPageToken(response *http.Response) (*string, error) {
links := link.ParseResponse(response)
if nextPage, ok := links["next"]; ok {
uri, err := url.Parse(nextPage.URI)
if err != nil {
return nil, fmt.Errorf("failed to parse nextPage uri: %w", err)
}
pageToken := uri.Query().Get("page_token")
if pageToken == "" {
return nil, fmt.Errorf("next link present, but has no page_token")
}
return &pageToken, nil
} else {
// There is no next page link, so we are at the last page of the response.
return nil, nil
}
}
white-cartoon-58880
04/11/2024, 4:29 PMplain-lunch-50969
04/16/2024, 8:18 PMpage_token
without parsing headers? I'm just using the Ory Kratos API. It wants a token but there is no clear way to get it. And there is no documentation about how to get it.plain-lunch-50969
04/16/2024, 9:10 PMListIndentities
response. This worked though, ty.