-
Notifications
You must be signed in to change notification settings - Fork 13
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
Support for nextCursor #6
Comments
Hey @friendscottn, thanks for the thorough bug report and solution analysis. It looks like the reason for this problem is that Walmart just doesn't include the Taking a look through the OpenAPI models, it looks like there should be a
There are cursors used in a bunch of other places, too, but they're just query parameter strings that should be used on the next request, rather than tokens. A PR is definitely welcome – let me know if you need more guidance on how to get started with this. |
Okay sounds good. I'll take a swing at it. |
When can we handle this issue ? |
Hey @cnx7 , {
"minimum-stability": "dev",
"prefer-stable": true,
"repositories": {
"highsidelabs/walmart-api": {
"type": "vcs",
"url": "https://github.com/friendscottn/walmart-api-php.git"
},
}
}
|
Any explanation of how to actually get all orders from this endpoint using multiple requests with cursor? Maybe add a method that retrieves an iterator for orders to abstract away the details of passing the cursor parameters manually? |
Figured it out, you have to do ugly stuff like this: $ordersResponse = $ordersApi->getAllOrders();
do {
foreach ($ordersResponse->getList()->getElements()->getOrder() as $order) {
yield $order;
}
if ($ordersResponse->getList()->getMeta()->getNextCursor() === null) {
break;
} else {
$cursor = [];
parse_str(
ltrim(
$ordersResponse->getList()->getMeta()->getNextCursor(),
'?'
),
$cursor
);
}
$ordersResponse = $ordersApi->getAllOrders(
limit: $cursor['limit'],
hasMoreElements: $cursor['hasMoreElements'],
soIndex: $cursor['soIndex'],
poIndex: $cursor['poIndex'],
partnerId: $cursor['partnerId'],
sellerId: $cursor['sellerId'],
createdStartDate: $cursor['createdStartDate'],
createdEndDate: $cursor['createdEndDate']
);
} while(true); |
The Issue
When you request orders on Walmart's Orders API using the /v3/orders endpoint they return a
nextCursor
property in themeta
response. Here's a sample of thenextCursor
:They want you to use that for the querystring parameters of your next call to get the next page.
The
Walmart\Apis\MP\US\OrdersApi::getAllOrders()
method needs some way to support requesting that next page of orders.It looks like this is not the only endpoint that uses the
nextCursor
meta property to support pagination.I'd be happy to create a PR for this, but first I'd like to:
Possible solution
Take a
nextCursor
argument on thegetAllOrders
method and ignore all other arguments. Just use the nextCursor as the query string for the API Call if the nextCursor is not null.The text was updated successfully, but these errors were encountered: