Comments (5)
FYI - I have since tested extracting the $skiptoken parameter using the Spatie URL package and that worked.
However I'd still like to know if it's possible to change the full URL in the $request?
protected function getNextCursor(Response $response): int|string
{
$url = Url::fromString($response->json('@odata.nextLink'));
return $url->getQueryParameter('$skiptoken'); // <-- might need to check both $skip and $skiptoken
}
//...
protected function applyPagination(Request $request): Request
{
if ($this->currentResponse instanceof Response) {
$request->query()->add('$skiptoken', $this->getNextCursor($this->currentResponse)); // <-- might need to use $skip instead $skiptoken in some cases
}
if (isset($this->perPageLimit)) {
$request->query()->add('$top', $this->perPageLimit);
}
return $request;
}
from saloon.
Hey @avenjamin firstly I want to apologise for being slow to reply to your message.
I'm going to see if there's a way I can introduce the ability to overwrite the URL on a per-request basis for situations like these. However I think you are on the right track with modifying the query parameters.
Do you have an example of how the @odata.nextLink
value?
from saloon.
Hey @Sammyjo20 - no worries :)
That would be great if you could - I'm sure this won't be the only time someone will want this feature.
The original URL is:
https://graph.microsoft.com/v1.0/users?$select=id,mail,accountEnabled,displayName,department
And the @odata.nextLink
URL is:
https://graph.microsoft.com/v1.0/users?$select=id%2cmail%2caccountEnabled%2cdisplayName%2cdepartment&$skiptoken=RFNwdAIAAQA....snip....GG5AAAAA
As you can see the URL is practically the same just with some URL escaping and the addition of the $skiptoken
.
I'm only hesitant due to what Microsoft say in the docs which I'm reading as don't modify the URL basically and that in some instances they use $skip
instead.
I suppose Microsoft could potentially set the $skiptoken
to a different server hostname for load balancing. e.g. graph-na-01.microsoft.com
but I haven't seen them do this yet:
Important
You should include the entire URL in the @odata.nextLink property in your request for the next page of results. Depending on the API that the query is being performed against, the @odata.nextLink URL value will contain either a $skiptoken or a $skip query parameter. The URL also contains all the other query parameters present in the original request. Do not try to extract the $skiptoken or $skip value and use it in a different request.
from saloon.
Hey @avenjamin
Thanks for the information - I've had a look into building a new url()
API for Saloon's requests/connectors but I think it's going to be too difficult to retrofit it into v3 for everyone. I would recommend that you add your own setEndpoint()
method on your request, which internally sets a property. When the endpoint is a full URL it'll be preferred over the base URL defined on the connector.
class YourRequest extends Request
{
protected string $endpoint = '/default';
protected function resolveEndpoint()
{
return $this->endpoint;
}
public function setEndpoint(string $endpoint): void
{
$this->endpoint = $endpoint;
}
}
// ...
protected function applyPagination(Request $request): Request
{
if ($this->currentResponse instanceof Response) {
$request->setEndpoint($this->currentResponse->json('@odata.nextLink'));
}
// ...
}
from saloon.
Thanks @Sammyjo20 - maybe in v4 :)
I did as you suggested and it's working well so far.
I also just used the same technique for another API which has the page number as part of the URL (not a query parameter).
We can close this for now.
Cheers
Ben
from saloon.
Related Issues (20)
- Cannot Have Request with `headers` HOT 4
- Skipping authentication when request is cached HOT 7
- Skipping AuthenticatePendingRequest when fetching a new accessToken using OAuth2 plugins HOT 4
- OAuth2 - Method not allowed (405) when getting the access Token HOT 8
- Missing methods updates for MockResponse HOT 1
- ERROR There are no commands defined in the "saloon" namespace. HOT 1
- Rate Limit Plugin: Issue with 'allow(1)->everySeconds(1)->sleep()' Exceeding One Request per Second
- Inteliphense cannot recognize the merge() method on request HOT 3
- Connector default headers overwrite request body headers
- Remove authentication on a specific request HOT 2
- Some properties are removed from the response body
- Using non-standard HTTP methods HOT 2
- Generating Documentation Files for GPT on ChatGPT HOT 1
- Tests using Fixtures with custom Authenticators record incorrect response HOT 1
- async request with multi connector HOT 1
- Allow partial overriding of fixtures HOT 1
- Asserting a request is sent by closure parameter
- Connector object() throws an exception but json returns null|object? HOT 1
- Feature Request: Requests have the ability to return a Colleciton HOT 1
- Connector does not support `defaultBody()`? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from saloon.